I'm basing my performance opinion on a series of different tests I've run
over time. Each time I have tried to use DataTables, there has been a
negative performance impact. I've experimented with lots of different
things. Comments inline below.
William Ryan said:
Have you tried creating a DataTable from code, columns and all?
Yes, that's how I always do it.
Under the
scenes, all a datatable is is an 'in memory' data type.
I understand. This is how I have used them. I was shocked to find that I
could create an ASCII file on disk much faster than I could add data to an
in-memory DataTable. Also, deleting a column from an in-memory DataTable is
extremely slow.
I've played with
this quite a bit, and while not professing to be an expert, at least have a
good case to make. A DataTable isn't a huge heavy object by any means. If
you are only using it to hold data, it's not notably different from using a
strongly typed collection.
In my experience it is much slower. I don't know why.
I created a myDataTable object that was simply a
class implementing CollectionBase. I had my own .AddRow() method which
simply added a blank object to the collection.
So how did you allow for different typed columns? Sounds like all your
columns were either not typed or of the same type.
If I may ask, why is it that a DataTable has overhead that makes it a deal
breaker? I can tell you from personal experience that a lot of 'overhead'
is often perceived (not saying that's the case hear, just speaking from
personal experience).
We're doing computationally intensive stuff. The original design (using the
standard .NET approach) took about 48 hrs of continuous running to finish a
results set. The current design, still in C#, does the same thing in 2 hrs
45 min. We've had to pay attention to performance stuff others don't need to
be concerned about.
Remember that it's a reference type, so this can have
a HUGE performance impact depending on how you are using it. I can't
understate this point. Pass by ref or val all you want, it's a reference
type and unless you are careful, it can really cause you some problems
performance wise.
Care to give an example?