[HarfBuzz] an optimization for complex fonts

Behdad Esfahbod behdad at behdad.org
Mon Oct 28 07:40:27 PDT 2013


On 13-10-28 02:47 PM, Jonathan Kew wrote:
> Hey Behdad,
> 
> Turns out that for fonts such as Noto Devanagari and Gujarati, we're spending
> an inordinate amount of time under lookup.is_inplace (&inplace_c) in
> apply_string().
> 
> We can get a big win for these fonts if we cache the is_inplace result in the
> lookup-accelerator, instead of recursing down through the sub-lookups every time.
> 
> With the attached patch, I see the total run time for a test such as
> 
>   hb-shape NotoSansDevanagari-Regular.ttf --text-file hi.txt > /dev/null
> 
> drop from 22 seconds to 8 sec. And that includes the time to read the file,
> populate and serialize the buffer, etc., so once those constant factors are
> discounted, the actual shaping itself is over 3x faster. :)
> 
> NotoSansGujarati shows a similar gain; and Amiri with ar.txt runs in 45 sec
> instead of 1 min+, for a speedup of over 25%.

Wow!  Yet another reason to use profiling to guide optimizations.  Thanks for
looking into this!


> (For fonts that don't have lots of complex contextual lookups, of course,
> there's no significant difference.)
> 
> See what you think. An alternative implementation might be to initialize the
> is_inplace flag during hb_ot_layout_lookup_accelerator_t::init() (then no need
> for the _initialized flag, hence taking an if() out of the hot path, and the
> hb_ot_layout_lookup_accelerator_t references could remain const), but it
> looked like this would involve rather more rearrangement of code, so I took
> the simplest approach for now.

I like to keep the shape_plan const.  I'll look into rearranging the code to
do that.

Thanks again!

-- 
behdad
http://behdad.org/



More information about the HarfBuzz mailing list