Clarity, Technology, and Solving Problems | PracticeThis.com
WP7 App with Key Windows Azure resources – Slides, Videos, How-To’s, and T-shooting – for quick consumption on the go.
We used System.Diagnostics.Trace to report execution times.
1: System.Diagnostics.Trace.WriteLine("1. STARTING");
3: DataGrid datagrid = SampleServices.GenerateDynamicDataGridControl();
6: System.Diagnostics.Trace.WriteLine("2. GRID CREATED AND ADDED TO PAGE");
8: MyCollection myCollection = (MyCollection)SampleServices.GenerateCollection(200);
10: System.Diagnostics.Trace.WriteLine("3. CUSTOM COLLECTION CREATED");
12: datagrid.DataSource = myCollection;
15: System.Diagnostics.Trace.WriteLine("5. DONE");
12: DataTable datatable = SampleServices.ConvertCollectionTableIntoDataTalbe(myCollection);
14: System.Diagnostics.Trace.WriteLine("4. CUSTOM COLLECTION CONVERTED INTO DATATABLE");
16: datagrid.DataSource = datatable;
19: System.Diagnostics.Trace.WriteLine("5. DONE");
Note, that UseCustomCollection.aspx.cs misses step “4. CUSTOM COLLECTION CONVERTED INTO DATATABLE”.
We used DebugView to collect reported execution times.
Applying simple mathematics we can see that converting Collection to Datatable takes 0.00081015 seconds. This is the gain we get when skipping this step in UseCustomCollection.aspx.cs.
Now lets examine DataBind() in both cases:
I know it is not a huge improvement for binding datatable vs. collection, but the tests we conducted always showed this gap. That is why eliminating the type transformation from collection to datatable that included enumeration and looping did not really help and we ended up with similar results of ~65% CPU utilization:
Binding custom collection is expensive performance wise since internally it uses reflection and reflection is expensive thing to do. Looping is expensive performance wise too but it is cheaper than reflection.
If you casting DataItem in DataBound event and fill each line control (cells/labels), wouldn't you have a better performance?
Something is wrong on your own numbers:
- the 1st one (customecollection) shows 0.0043
- the 2nd one (datatable) shows 0.0047
So the 2nd one is slower.
Look at what PAG says about that:
look at "Minimize Calls to DataBinder.Eval" in it
I guess I need to do more testing - thansk for calling this out!
Good catch! Please notice that in the post i measure how long does it take to DataBind() to complete and not the whole cycle as you call out. I must admit I was not that clear and this might have misled you. Sorry about that.
The other stuff. My main goal - which is also not very clear in my post - to identify CPU killers and I am less interested in response times.
Bottom line - you bring in interesting angle which adds to the whole picture, thank you for that