This blog has moved. Please update your bookmarks.

I Love Optimizing Components

Yesterday I managed to take one of our older components and optimize it so much it actually scared me. It's a component that reads about 1000 language texts into memory and enabling the software to be multi-lingual.

Before optimization began, it took about 700 ms to load and parse the file. Clearly too much for a measly 1000 rows.

In mid-optimization, I had cut the time down to 130 ms, but I still thought that was a little bit too much. I decided to optimize the parsing further; there was a portion where we had a very repetitive string addition,

    Result := Result + p^;

and I decided to skip that step and just count characters and copy the entire string through StrMove instead when I was done. The result: I cut the total time down to 30 ms; including loading, parsing and sorting the file. That's about 95% of execution time slashed away.

An added bonus was that I could optimize the language lookup function too, using a binary search routine, reducing text lookups from O(n/2) to O(log2(n)). The effect was that our main program ran about twice as fast, as perceived by me and my colleagues.

It just goes to prove that sometimes, by focusing on the worst 1% of the code, you can reap enormous benefits. Yay!


Post a Comment

<< Home


Blog contents copyright © 2005 Mats Gefvert. All rights reserved.