So, I went back and looked at things today, so see how hard it would be to add a simple caching system to my orignal generator. Turns out it was pretty easy [smile]
The caching is a very simple std::map which uses the glyph index as a key and stores a structure which the glyph bitmap and the metrics of the glyph (used for height adjustments and the like in the inital setup routine).
Then, when the font is rendered the inital setup routine checks the map to see if the glyph has been rendered, if so it extracts the infomation from it, if not renderes like normal and inserts the glyph into the map for later usage.
Having completed these changes I wanted to see what, if any, change it had made in my program with regards to speed.
Now, is FPS a horrible method of seeing how long things take when your rendering at >100fps and currently I'm above 1000fps as I'm not really doing much, so I settle on timing the rendering time over a fixed amount of updates and outputting the average time to render each frame (in ms), the results were.. intresting :
Over 500 updates:
Render time : 10093
Number of frames : 19037
0.530178ms per frame
Render time : 10306
Number of frames : 19680
0.523679ms per frame
Over 5000 updates:
Render time : 104062
Number of frames : 184318
0.564579ms per frame
Render time : 101947
Number of frames : 183289
0.556209ms per frame
The only change between each version was the useage or not of the caching code.
As you can see, I'm rendering pretty quickly anyways so its not like this was a bottle neck, however even at such high speeds the fact that over 500 updates the uncached version was faster is... intresting. Even over 5000, while its slightly quicker to use the cached version it infact rendered ~1000 less, I'm putting this down to the update loop running closer to 50 updates a second the 2nd time.
My current theory for the difference in speed comes down to locality in memory and excess copying. When things are inserted into the std::map the extra memory is request via 'new' but this memory might not be local to each other, as such the system has to work harder to find each character.
The extra copying is down to the simpleness of the caching system, instead of keeping one copy in the cache the pointing the character data at it I'm copying the data across.
This infact is probably increasing memory fragmentation, its not a problem now as the test case is so simple, but it could prove a problem down the line.
I think I'll look into a slightly better caching system, infact iirc freetype2 has its own in build cache system, it might be worth looking at that to see if it can assist in anyway.