freetype-devel
[Top][All Lists]
Advanced

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

FT_Get_Advance() too slow?


From: Behdad Esfahbod
Subject: FT_Get_Advance() too slow?
Date: Fri, 20 May 2022 11:05:43 -0600

Hi,

I'm debugging an issue where FT_Get_Advance(), even in its fast path (NO_HINTING), seems to be much slower than the equivalent HarfBuzz code. Much of it seems to be overhead because we have to call FT_Get_Advance() one glyph at a time and it does multiple indirections before getting the advance and returning.

But I also found that it tries to apply variations unconditionally. The following patch fixes that to only try applying variations if the font has blends set. For me this seems to help a bit (~20% of my numbers):

diff --git a/src/sfnt/ttmtx.c b/src/sfnt/ttmtx.c
index 7aece36fb..5bca8560d 100644
--- a/src/sfnt/ttmtx.c
+++ b/src/sfnt/ttmtx.c
@@ -306,7 +306,7 @@
     }
 
 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
-    if ( var )
+    if ( var && face->blend )
     {
       FT_Face  f = FT_FACE( face );
       FT_Int   a = (FT_Int)*aadvance;

For the curious, I'm using perf/benchmark-font in the harfbuzz repo. Here's the numbers of interest:

$ ninja -Cbuild && LD_PRELOAD=~/freetype/objs/.libs/libfreetype.so build/perf/benchmark-font --benchmark_filter=advance --benchmark_out=after
ninja: Entering directory `build'
ninja: no work to do.
2022-05-20T11:01:01-06:00
Running build/perf/benchmark-font
Run on (24 X 3665.32 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x12)
  L1 Instruction 32 KiB (x12)
  L2 Unified 512 KiB (x12)
  L3 Unified 32768 KiB (x2)
Load Average: 0.28, 0.80, 1.02
--------------------------------------------------------------------------------------------------------
Benchmark                                                              Time             CPU   Iterations
--------------------------------------------------------------------------------------------------------
BM_Font/glyph_h_advances/Roboto-Regular.ttf/hb                      3.08 us         3.08 us       227980
BM_Font/glyph_h_advances/Roboto-Regular.ttf/ft                      18.5 us         18.5 us        37889
BM_Font/glyph_h_advances/Roboto-Regular.ttf/var/hb                  3.09 us         3.08 us       226996
BM_Font/glyph_h_advances/Roboto-Regular.ttf/var/ft                  18.3 us         18.2 us        38431
BM_Font/glyph_h_advances/SourceSansPro-Regular.otf/hb               4.62 us         4.61 us       150940
BM_Font/glyph_h_advances/SourceSansPro-Regular.otf/ft               27.4 us         27.3 us        25622
BM_Font/glyph_h_advances/AdobeVFPrototype.otf/hb                   0.752 us        0.751 us       932022
BM_Font/glyph_h_advances/AdobeVFPrototype.otf/ft                    1.83 us         1.83 us       380586
BM_Font/glyph_h_advances/AdobeVFPrototype.otf/var/hb                6.22 us         6.21 us       112788
BM_Font/glyph_h_advances/AdobeVFPrototype.otf/var/ft                3.53 us         3.52 us       199363
BM_Font/glyph_h_advances/SourceSerifVariable-Roman.ttf/hb           3.41 us         3.40 us       205771
BM_Font/glyph_h_advances/SourceSerifVariable-Roman.ttf/ft           20.2 us         20.2 us        34728
BM_Font/glyph_h_advances/SourceSerifVariable-Roman.ttf/var/hb       28.3 us         28.2 us        24723
BM_Font/glyph_h_advances/SourceSerifVariable-Roman.ttf/var/ft       37.0 us         36.9 us        18952
BM_Font/glyph_h_advances/Comfortaa-Regular-new.ttf/hb               2.08 us         2.08 us       336868
BM_Font/glyph_h_advances/Comfortaa-Regular-new.ttf/ft               12.2 us         12.2 us        56816
BM_Font/glyph_h_advances/NotoNastaliqUrdu-Regular.ttf/hb            3.24 us         3.24 us       216425
BM_Font/glyph_h_advances/NotoNastaliqUrdu-Regular.ttf/ft            19.2 us         19.2 us        36445
BM_Font/glyph_h_advances/NotoSerifMyanmar-Regular.otf/hb            1.67 us         1.67 us       418787
BM_Font/glyph_h_advances/NotoSerifMyanmar-Regular.otf/ft            9.92 us         9.90 us        70415

I truly cannot explain the order-of-magnitude difference so far.

Regards,

reply via email to

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