... Here comes the promised stacktrace and example app.
Exception in thread "main" java.lang.NullPointerException at sun.font.TrueTypeGlyphMapper.<init>(TrueTypeGlyphMapper.java:62) at sun.font.TrueTypeFont.getMapper(TrueTypeFont.java:1232) at sun.font.FileFontStrike.<init>(FileFontStrike.java:170) at sun.font.FileFont.createStrike(FileFont.java:104) at sun.font.Font2D.getStrike(Font2D.java:359) at sun.font.Font2D.getStrike(Font2D.java:266) at sun.java2d.SunGraphics2D.checkFontInfo(SunGraphics2D.java:700) at sun.java2d.SunGraphics2D.getFontInfo(SunGraphics2D.java:755) at sun.java2d.pipe.GlyphListPipe.drawString(GlyphListPipe.java:50) at sun.java2d.pipe.ValidatePipe.drawString(ValidatePipe.java:165) at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2805) at TestFontsPerformance.main(TestFontsPerformance.java:21) Am Dienstag, den 12.08.2008, 23:22 +0200 schrieb Roman Kennke: > Hi Igor, > > > Anyway, i promise i'll look into this in more detail as i get some > > spare > > time (that is really rare these days :() > > Thanks alot. > > > >> From the top of the head i'd sugegst to check impact of such change > > on > > >> performance and perceived > > >> footprint scanning large set of large fonts. > > >> > > > > > > I can do that. Any suggestions on how to do that easily? I'm not > > sure > > > how that (FreeType) implementation works, but I know at least one > > font > > > implementation that doesn't actually load anything until the > > > corresponding glyphs are needed (also mmap-based, very handy... this > > is > > > the code in Classpath, all Java, all nice :-D ). > > > > > Both freetype and t2k do not read everything explicitly too. > > However, to build list of all available fonts we have to scan some > > tables in all files. > > And it will be unfortunate if process size will grew by total size of > > all fonts. > > > > Quick tests are: run Font2DTest on system that has some really large > > ttf/ttc files. > > > > Write simple test that iterates through all available fonts and draw > > one > > or all glyphs to bufferedimage. > > I wrote a simple test program that gets an array of all fonts and gets > the baseline for all 0-0xffff characters. (Drawing stuff to BI didn't > work due to NPE, see stacktrace below. BTW, this makes everything, e.g. > SwingSet2, kindof unstable, is this a known bug?) > > 10 runs of this program with my patch take: 4338ms > 10 runs of this program w/o my patch take: 4492ms > > And I can say from the output that the jitter is not very big here. (The > values of the runs with and w/o my patch do not overlap). Seems like a > small but noticable performance improvement. This is on Linux though. > > One interesting note here: Everytime this program is run, it shows a > different number of fonts (around 285-302 fonts). On an OpenJDK6 system > it constantly shows 360 fonts. > > > >> I likely be mistaken here > > >> but on some platforms > > >> (Windows) this might have noticeable negative consequences. > > >> > > > > > > Unfortunately, I don't have a Windows box around, and can't setup > > one > > > easily. Windows licenses and VS licenses are too costly for my > > taste. > > > Also, at work, some people tried to setup a build of OpenJDK on > > Windows > > > and failed (or at least, did not succeed after 16 hours of work or > > so). > > > > > It will be nice to hear why it does not build on Windows. > > I am quite sure OpenJDK is buildable with commercial VS and > > i know that some people were building it with VS Express too (with > > minor > > tweaks). > > I can ask. > > Cheers, Roman > -- http://kennke.org/blog/
import java.awt.*; public class TestFontsPerformance { public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Toolkit tk = Toolkit.getDefaultToolkit(); long start = System.currentTimeMillis(); Font[] fonts = ge.getAllFonts(); System.err.println("scanning: " + fonts.length + " fonts..."); byte value = 0; for (Font font : fonts) { for (char i = 0; i < 0xFFFF; i++) { value |= font.getBaselineFor(i); } } System.err.println("took: " + (System.currentTimeMillis() - start) + " ms."); // Prevent HotSpot from optimizing away stuff that we want to know. System.err.println("value: " + value); } }
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil