freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Devel] Optimizatins to ttinterp.c


From: David Williss
Subject: [Devel] Optimizatins to ttinterp.c
Date: Wed, 6 Dec 2000 15:58:47 -0600

I happened to be running a program through Rational Quantify (a really
good profiler for Windows NT/2000) and found a few things in Freetype 1.3
that I was able to speed up.  They're compiler specific (Visual C 6.0), but
significant.

My test was to open "Arial Unicode MS" and TT_Load_Glyph all the
glyphs so that I could call TT_Get_Glyph_Extents.  In doing so, I found
that RunIns() got called 52,794 times for 13,494 ms. (This font has
a lot of Kanji and Korean glyphs, many of which are composites).
I tried loading without hinting, but that made my extents inaccurate.

Of the functions that RunIns() calls, the major ones were...

   function               percent      calls              propagated time
    Calc_Length        17.57%    9,474,392    2,370 ms
    Ins_SHP              14.08       1,014,967    1,899 ms
    Ins_IUP                11.07         103,158     1,493 ms
    Ins_IP                  10.04        521,928       1,355 ms


The first thing I did was to make Calc_Length() in ttinterp.c an inline
function.
This is done via the __inline keyword, which I would create a #define for if
I cared about portability.
While I was at it, I added __inline to a few other really short functions
but
they didn't have much impact.

The big gain came from TT_MulDiv().  It turns out that all the other time
soaking functions end up calling it.   Since TT_MulDiv is exported from
the library, this would need some cleaning up, but it boils down to...

(in freetype.h, where TT_MulDiv() is prototyped)

#ifdef WIN32        // perhaps a better #define to check would be helpful
    // since __inline and __int64 are Microsoft-specific extensions.

    __inline TT_Long TT_MulDiv( TT_Long  a, TT_Long  b, TT_Long  c )
    {
    return ((long)(((__int64)a * (__int64)b) / (__int64)c));
    }

#else
    // the old prototype goes here
#endif

Then the version in ttcalc.c would be #ifdef'd out for the case where it
was inlined.  Since TT_MulDiv is exported from the library, it might
be necessary to change the name of the inline version and have the
one exported call it, then change places where the interpreter calls
it to use the inline version.   It would need some cleaning up.

Anyway, the result was that with all the changes I made, loading
this font, the time to do the hinting went from 13.5 sec to 3.5 sec.
Now the child of RunIns() that takes the most time is Ins_IUP
which is down to 908ms and is now 25.43% of the time.
followed by Ins_SHP at 431ms for 12.07% of the time.

------------------------------------------------------------
David Williss
Meddle not in the affairs of dragons,
for you are crunchy and taste good with catsup





reply via email to

[Prev in Thread] Current Thread [Next in Thread]