bugThe FreeType Project - Bugs: bug #43248, New CFF engine is too slow


bug #43248: New CFF engine is too slow

Submitted by:  Behdad Esfahbod <behdad>
Submitted on:  Thu 18 Sep 2014 10:48:00 AM UTC  
Severity:  3 - Normal Item Group:  None
Status:  None Privacy:  Public
Assigned to:  None Open/Closed:  Open
Planned Release:  None

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Tue 14 Oct 2014 11:38:08 PM UTC, comment #2: 

Thanks Dave.

I'm guessing that you might be seeing a lot of I/O which masks the actual work being done.  On Linux, with NotoSansCJK-Regular.otf, for flags 0=DEFAULT 1=NO_SCALE 2=NO_HINTING I get the following times:

New engine:

Load                     : 13.914 us/op
Load                     : 11.615 us/op
Load                     : 13.013 us/op

Old engine:

Load                     : 23.984 us/op
Load                     : 2.625 us/op
Load                     : 2.856 us/op

So, looks like the loading used to be superfast but is not anymore.

On the plus side, hinting is twice faster with the new engine.

Behdad Esfahbod <behdad>
Fri 19 Sep 2014 06:44:11 PM UTC, comment #1: 

Hi Behdad, Here is the response I sent to freetype-devel on 9/5.

It is true that disabling hints for the Adobe CFF engine does not give a significant performance advantage as it did with the old engine. The new engine is optimized for rendering with hints. It makes a single pass over the outline. The old engine made two passes, with the second (optional) pass applying hints. However, the new engine is somewhat faster than the old one when rendering with hints.

I do not have easy access to the fontconfig test that you mention. I tried to simulate it with ftbench as follows.

I enabled CFF_CONFIG_OPTION_OLD_ENGINE and built a 64-bit Release target for Windows with Visual Studio. I used ftbench to call FT_Load_Glyph with various flags:

I used the font SourceHanSans-Regular.otf (one of the fonts you mention; the other weights have similar results). So, for example, the first value, below, is from this command:
ftbench -H -f 0 -b a SourceHanSans-Regular.otf

Flag New CFF Old CFF

  1.      49us      54us

1      39us      19us
 2      48us      19us

Note that the new CFF engine has two ways to modify outlines in a size-dependent way. The first is by hinting (grid-fitting) and the second is by stem darkening. FT_LOAD_NO_HINTING does not turn off stem darkening. There are situations where you want to darken stems at small sizes for unhinted glyphs. FT_LOAD_NO_SCALE DOES turn off both hinting and darkening. Or, you can set the driver property "no-stem-darkening". Stem darkening does incur a performance cost and in the ftbench test above, stem darkening has an effect. Patching ftbench to turn it off yields times of 40us for flags 0 and 2. But, hinting has almost no effect on the performance of the new engine.

So, depending on what calls fontconfig is making, I can understand a factor of 2 or 2.5 in comparing unhinted outlines. I don't understand why there would be a factor of 5, as you observed. And I don't see an easy fix.



Dave Arnold <darnold>
Project Member
Thu 18 Sep 2014 10:48:00 AM UTC, original submission:  

I noticed that fontconfig caching (eg, running fc-query on font files) is five
times slower with Adobe CFF engine that it is with old engine.  Fontconfig
loads all glyphs with FT_Load_Glyph().

With old engine:

behdad:source-han-sans 0$ time fc-query *.otf --format

real 0m0.952s
user 0m0.927s
sys 0m0.024s

With Adobe engine:

behdad:source-han-sans 0$ time fc-query *.otf --format

real 0m4.832s
user 0m4.782s
sys 0m0.045s

Any chance someone familiar with the code can look into it?  I suppose this is
something that can easily be fixed.  Maybe the new code doesn't respect

Behdad Esfahbod <behdad>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by darnold (Posted a comment)
  • -email is unavailable- added by behdad (Submitted the item)
  • -email is unavailable- added by behdad

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-09-18 behdad Carbon-Copy- => Added darnold@adobe.com

    Back to the top

    Powered by Savane 3.5