From: Wenyuan G. <guo...@gm...> - 2010-07-21 23:26:17
|
Hi all, With more careful profiling of the program, I found my earlier theory to be wrong: I thought the delay when switching resolution mainly came from HDD delay. This component turns out to be minor, thanks to OS caching. The following two components are much more significant: 1. Surprisingly, the librsvg function that determines the dimension of an input SVG image file takes substantial time. I had thought that it ought to be as simple as to locate the relevant strings from the SVG file involving only minimum parsing efforts. In any case, I have build an in-memory caching table to store dimensions of SVG files seen before to minimize this performance penalty to once per file for each session. 2. The PNG function to parse input file into SDL surface is the second contributor to the delay, although smaller than 1. I have built another in-memory caching mechanism for these SDL surfaces, with reference copying instead of actual data copying. This assumes that all loaded SDL surfaces are never modified, which seem to be the case for tuxmath. This is faster and more memory efficient. With the additional caching, pressing F10 to switch resolution takes only 0.5s, compared with about 2s before. Given this small delay, I have scratched the multithreading mechanism implemented before, which is no longer necessary. Moreover, the multithreading functions still have mysterious bugs. There are too many rendering functions that have global variable and I/O conflicts. It is extremely difficult to identify all race conditions between them at this point. Cheers Wenyuan |