Re: speeding up auto-hinter start-up

Behdad Esfahbod <[email protected]> Sun, 15 Jun 2025 16:06:55 -0600
Newsgroups gmane.comp.fonts.freetype.devel
Message-ID <CAF63+7WQOz-6daMXLf65QaJcY97CzSuAmzRPx5R=SN5Om-ZH3Q@mail.gmail.com>
--000000000000f0c1e40637a380fd
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

I put together a pull request:

  https://github.com/harfbuzz/harfbuzz/pull/5367

Untested, but should work. Please let me know.

Thanks,

behdad
http://behdad.org/


On Sun, Jun 15, 2025 at 12:05=E2=80=AFPM Behdad Esfahbod <[email protected]=
> wrote:

> So, this will be the prototype:
>
> HB_EXTERN hb_map_t *
> hb_ot_layout_lookup_get_glyphs_alternates (hb_face_t *face,
>                                            unsigned   lookup_index);
>
> behdad
> http://behdad.org/
>
>
> On Sun, Jun 15, 2025 at 11:40=E2=80=AFAM Behdad Esfahbod <[email protected]=
rg>
> wrote:
>
>> Hi Werner,
>>
>> I have an idea. Similar in essence to `af_map_lookup`, just using anothe=
r
>> style to avoid extra allocations.
>>
>> Basically, to get gid's variants, you will check `gid + (i << 24)` for i
>> being 0, 1, 2, ... until you hit a miss.
>>
>> This allows for just one hash table to be returned. Allows for 24bit
>> gid's. Its only limitation is 8bit of alternates, but if you see gid has
>> alternate at index 255, you can use to the slower API to get all the
>> remaining alternates.
>>
>> Does that sound good to you? I can go ahead and prototype it.
>> behdad
>> http://behdad.org/
>>
>>
>> On Sun, Jun 15, 2025 at 1:00=E2=80=AFAM Werner LEMBERG <[email protected]> wrot=
e:
>>
>>>
>>> I've just submitted a Merge Request to speed up the auto-hinter
>>> start-up.  The previous code using HarfBuzz functions was far too slow
>>> to be acceptable =E2=80=93 HarfBuzz (currently) doesn't exactly provide=
 what
>>> we need, causing way to much overhead.
>>>
>>> To speed things up it was necessary to (partially) parse, validate and
>>> access the GSUB table.  I really tried to avoid that, but...
>>>
>>> Please have a look!  The speed-up is really impressive, I think; the
>>> old code slowed down the start-up time by more than 300% (in
>>> comparison to a commit before introducing vertical accent
>>> positioning), while the new code only adds about 25%.
>>>
>>>   https://gitlab.freedesktop.org/freetype/freetype/-/merge_requests/381
>>>
>>> Ideally, I would like to get rid of the GSUB code since it doesn't fit
>>> conceptually into FreeType (and HarfBuzz does it anyway).  Behdad, do
>>> you have ideas whether something similar to `af_map_lookup` could be
>>> added to HarfBuzz?  This would be a long-term solution, since even if
>>> HarfBuzz gets fitting functionality I don't want to make FreeType
>>> depend on the newest HarfBuzz version...
>>>
>>>
>>>     Werner
>>>
>>

--000000000000f0c1e40637a380fd
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I put together a pull request:</div><div><br></div><d=
iv>=C2=A0=C2=A0<a href=3D"https://github.com/harfbuzz/harfbuzz/pull/5367">h=
ttps://github.com/harfbuzz/harfbuzz/pull/5367</a></div><div><br></div><div>=
Untested, but should work. Please let me know.</div><div><br></div><div>Tha=
nks,</div><div><br></div><div><div dir=3D"ltr" class=3D"gmail_signature" da=
ta-smartmail=3D"gmail_signature">behdad<br><a href=3D"http://behdad.org/" t=
arget=3D"_blank">http://behdad.org/</a></div></div><br></div><br><div class=
=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr=
">On Sun, Jun 15, 2025 at 12:05=E2=80=AFPM Behdad Esfahbod &lt;<a href=3D"m=
ailto:[email protected]">[email protected]</a>&gt; wrote:<br></div><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px=
 solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div>So, this wi=
ll be the prototype:</div><div><br></div><div><font face=3D"monospace">HB_E=
XTERN hb_map_t * <br>hb_ot_layout_lookup_get_glyphs_alternates (hb_face_t *=
face, <br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0unsigned =C2=A0 lookup_index);</font></div><div>=C2=A0</di=
v><div><div dir=3D"ltr" class=3D"gmail_signature">behdad<br><a href=3D"http=
://behdad.org/" target=3D"_blank">http://behdad.org/</a></div></div><br></d=
iv><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On =
Sun, Jun 15, 2025 at 11:40=E2=80=AFAM Behdad Esfahbod &lt;<a href=3D"mailto=
:[email protected]" target=3D"_blank">[email protected]</a>&gt; wrote:<br><=
/div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bo=
rder-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><di=
v>Hi Werner,</div><div><br></div><div>I have an idea. Similar in essence to=
 `af_map_lookup`, just using another style to avoid extra allocations.</div=
><div><br></div><div>Basically, to get gid&#39;s variants, you will check `=
gid=C2=A0+ (i &lt;&lt; 24)` for i being 0, 1, 2, ... until you hit a miss.<=
/div><div><br></div><div>This allows for just one hash table to be returned=
. Allows for 24bit gid&#39;s. Its only limitation is 8bit of alternates, bu=
t if you see gid=C2=A0has alternate at index 255, you can use to the slower=
 API to get all the remaining alternates.</div><div><br></div><div>Does tha=
t sound good to you? I can go ahead and prototype it.</div><div><div dir=3D=
"ltr" class=3D"gmail_signature">behdad<br><a href=3D"http://behdad.org/" ta=
rget=3D"_blank">http://behdad.org/</a></div></div><br></div><br><div class=
=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Jun 15, 2025=
 at 1:00=E2=80=AFAM Werner LEMBERG &lt;<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_q=
uote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,2=
04);padding-left:1ex"><br>
I&#39;ve just submitted a Merge Request to speed up the auto-hinter<br>
start-up.=C2=A0 The previous code using HarfBuzz functions was far too slow=
<br>
to be acceptable =E2=80=93 HarfBuzz (currently) doesn&#39;t exactly provide=
 what<br>
we need, causing way to much overhead.<br>
<br>
To speed things up it was necessary to (partially) parse, validate and<br>
access the GSUB table.=C2=A0 I really tried to avoid that, but...<br>
<br>
Please have a look!=C2=A0 The speed-up is really impressive, I think; the<b=
r>
old code slowed down the start-up time by more than 300% (in<br>
comparison to a commit before introducing vertical accent<br>
positioning), while the new code only adds about 25%.<br>
<br>
=C2=A0 <a href=3D"https://gitlab.freedesktop.org/freetype/freetype/-/merge_=
requests/381" rel=3D"noreferrer" target=3D"_blank">https://gitlab.freedeskt=
op.org/freetype/freetype/-/merge_requests/381</a><br>
<br>
Ideally, I would like to get rid of the GSUB code since it doesn&#39;t fit<=
br>
conceptually into FreeType (and HarfBuzz does it anyway).=C2=A0 Behdad, do<=
br>
you have ideas whether something similar to `af_map_lookup` could be<br>
added to HarfBuzz?=C2=A0 This would be a long-term solution, since even if<=
br>
HarfBuzz gets fitting functionality I don&#39;t want to make FreeType<br>
depend on the newest HarfBuzz version...<br>
<br>
<br>
=C2=A0 =C2=A0 Werner<br>
</blockquote></div>
</blockquote></div>
</blockquote></div>

--000000000000f0c1e40637a380fd--