W
William Ryan
I thought I understood this subject, but something happened today that
proved me wrong...
My boss has a class that takes a DataTable passed by Reference and Add some
columns to it (in this example 18). So an app he was working on was taking
like 3 seconds to fill the DataTable each time it was called.
I suggested using a DataReader b/c of the way the query was being used.
However, in order not to break the class, he wanted it to return a DataTable
(which is still passed in by Ref). Anyway, adding the 18 columns that were
needed took 3 seconds.
I was really surprised that adding 18 columns was taking longer than
iterating through 100+ rows or 18 columns and adding them to the datatable.
The latter happened instantly, but the adding of the columns took 3-5
seconds.
I suspected the reference type (datatable) might be causing some performance
hit, but not that much of one. Anyway, I declared a table locally and tried
adding 18 columns to it. Same function, locally declared datatable, filled
instantly. So to not break the code, he set the data table that was passed
in equal to the one we declared locally, and still, no performance problem.
So my question is this....are reference types that bad performance wise when
you pass them., and if so, I guess some are much worse than others (namely
the Datatable)?
TIA,
Bill
proved me wrong...
My boss has a class that takes a DataTable passed by Reference and Add some
columns to it (in this example 18). So an app he was working on was taking
like 3 seconds to fill the DataTable each time it was called.
I suggested using a DataReader b/c of the way the query was being used.
However, in order not to break the class, he wanted it to return a DataTable
(which is still passed in by Ref). Anyway, adding the 18 columns that were
needed took 3 seconds.
I was really surprised that adding 18 columns was taking longer than
iterating through 100+ rows or 18 columns and adding them to the datatable.
The latter happened instantly, but the adding of the columns took 3-5
seconds.
I suspected the reference type (datatable) might be causing some performance
hit, but not that much of one. Anyway, I declared a table locally and tried
adding 18 columns to it. Same function, locally declared datatable, filled
instantly. So to not break the code, he set the data table that was passed
in equal to the one we declared locally, and still, no performance problem.
So my question is this....are reference types that bad performance wise when
you pass them., and if so, I guess some are much worse than others (namely
the Datatable)?
TIA,
Bill