Performance #4: Consolidate Object Creation from Database
July 14, 2007
This article is part of the series An Exercise in Performance Tuning in C#.Net.
At this point I did not re-run the profiler but continued investigating memory allocation. Here’s an interesting looking result:
Class::FindByID are accumulating up to 13.36% of the memory
allocation. And they are occurring in two different methods (
Class3::reInitialize) that are themselves called by the same method
Class3::runCalculations). Surely I could eliminate one of these?
Turns out that these two calls are basically right next to each other in the code:
Obvious strategy change: pass the
Class3 instance into
instead of having that function re-query for the correct
I just had to add one line above this
Well, this change one wasn’t as dramatic as the last ones: only 2% improvement. However, for some reason there was a great deal of variability in the 10 runs I performed. If I throw out the largest number, which was larger than any times from the version with un-tuned PinCalculation object, then that improvement is 2.6%.