SAF(NET) = STEPHEN A. FUQUA operating on the Web since 1995

Stephen is a web developer, Bahá'í, and interfaith activist in St. Paul, Minnesota. He likes to write about religion, social justice, sustainability, science, programming, &c.

July 14, 2007

Performance #4: Consolidate Object Creation from Database

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:

calc1.jpg

Calls to Class::FindByID are accumulating up to 13.36% of the memory allocation. And they are occurring in two different methods (Class2::Prep and 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:

reInitialize(obj1.ID);

if (!this.obj2.NoCalc)
{
     class2.Prep(ref obj1);

Obvious strategy change: pass the Class3 instance into Prep() instead of having that function re-query for the correct Class3 values. I just had to add one line above this Prep call: class2.Object2 = obj2;.

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%.

deprecated

On safnet.com

Other sites managed or developed by S.A.F.

S.A.F. elsewhere on the web

  • LinkedIn
    LinkedIn can actually be useful when looking for prospective hires and business or organizational partners
  • GoodReads
    A fun and relatively-unknown social networking site geared towards one's book list
  • Live Journal
    Mirror of the blog at safnet.com, so that a few LJ friends can more easily read and comment there