Qball's Weblog
Sneaky slowness
I noticed, since I added similar song, that gmpc got slowish in the metadata browser.
So today I decided to profile it, so I installed sysprof. After fixing a bug in ubuntu package (see here) I ran it.
For me totally unexpected, it was saving the metadata db that took so much time. Everytime a change was made, it took around 6 seconds to save it.
So time to optimise, First thing was to only save it on close. Not on every change. But even on close, 6 seconds is way to long.
First thing I did was remove all calls to fprintf and replace them by fput and putc. This reduced the time to 3.5 second. Still to long.
After fiddling around, I saw the bug, this was part of the code:
1 |
for (i=; i < strlen(string);i++) {.. |
I always thought (wrongly offcourse) that gcc was smart enough not to run strlen on each itteration.
After changing it to </pre> <div class="wp_codebox_msgheader wp_codebox_hide"> ?View Code C<div class="codebox_clear"> </div> </div>
1 2 3 |
int length = strlen(string); for(i=;i < length;i++){.. |
The total time saving the 1.7mb database is 0.17 seconds. Now this is acceptable on close.
One tiny change, speed difference of a life time.
Q</pre>