Wed, 02 Jul 2003

Painless Optimization

Today, I was looking over a Delphi project which my company is close to marketing, trying to find a way to make it quicker when initially loading up the various settings (hundreds of them) from the INI files. The product functions as expected, and is fairly complete, so now is a good time to start looking at optimizations which will increase the number of calculations per second (one of Knuth's laws: premature optimization is the root of all evil).

I figured that the TINIFile object implemented by Delphi was merely a thin wrapper around the INI file related Windows API functions. I thought that I could perhaps write my own INI file object which would perhaps cache the file in memory, thus reducing disk I/O and hence, increasing performance. Checking out the source code for the TINIFile object confirmed my guesstimation, and provided a pleasant surprise as well. In the same INIFiles unit which defines the TINIFile object, another object called TMemINIFile is defined. The implementation of this class cached the INI file in memory, just as I had planned on doing.

To make a long story somewhat longer, I merely replaced references of TINIFile to TMemINIFile in all of the units where INI files are used, and the performace of the project increased by more than a factor of 8. Woo-hoo! Now that is the kind of optimization that I like...

posted at: 19:25 | path: /computers/programming | permanent link to this entry