PATCH: XGraphicsConfiguration implement font metrics cache
Scott Gilbertson
scottg@mantatest.com
Wed Jan 29 21:21:00 GMT 2003
I have revised the font cache patch in the following ways, and I claim it's
ready to check in.
- one cache per Display, referenced through a Hashtable
- when putting the 11th font in any cache, the least-recently-used one is
removed
- code-wise, the cache is now implemented in an inner class
- also modified the font name format, which wasn't letting me load certain
fonts
To test it, I reduced the LRU threshold to 4 and added a bunch of println
statements. I confirmed that fonts were getting cached, found, created and
removed as intended. I then removed the printlns and bumped the LRU
threshold to 10.
Caveats:
1. Nothing gets disposed, so server resources could be tied up for some time
after discarding a font from the cache.
2. The LRU assessment is based on an integer counter, which will eventually
overflow if you run for a very long time with 10 or fewer fonts, one or more
of which were only used at startup, then suddenly use some new fonts. If
that happens, I predict that the cache will sometimes discard a few of the
wrong fonts. Although I haven't tested this scenario, I'm pretty sure it
will be OK, other than a very slight momentary performance hit.
3. There's a lot of hash-tabling, which could be reduced by moving the cache
into Display. I opted instead, however, to keep the change nicely contained
in XGraphicsConfiguration.
4. If you have more than ten fonts on-screen at once, there might be some
unfortunate overhead. I think, however, that even in these cases,
performance will be better than it would without a cache.
Index: libjava/ChangeLog
from Scott Gilbertson <scottg@mantatest.com>
* XGraphicsConfiguration.getXFontMetrics: implemented cache to improve
performance
revised patch is attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20030129_FontCache.patch
Type: application/octet-stream
Size: 6884 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20030129/145ea5e3/attachment.obj>
More information about the Java-patches
mailing list