[fonttools/fonttools] 431ca5: [glyf] Use reverse glyph map for O(1) __setitem__ ...

0 views
Skip to first unread message

Cosimo Lupo

unread,
Jun 17, 2026, 7:13:34 AM (8 days ago) Jun 17
to fontto...@googlegroups.com
Branch: refs/heads/glyf-setitem-perf
Home: https://github.com/fonttools/fonttools
Commit: 431ca5771611e98cfe06876802fa8ee11485ca28
https://github.com/fonttools/fonttools/commit/431ca5771611e98cfe06876802fa8ee11485ca28
Author: Cosimo Lupo <cos...@anthrotype.com>
Date: 2026-06-17 (Wed, 17 Jun 2026)

Changed paths:
M Lib/fontTools/ttLib/tables/_g_l_y_f.py
M Tests/ttLib/tables/_g_l_y_f_test.py

Log Message:
-----------
[glyf] Use reverse glyph map for O(1) __setitem__ membership

table__g_l_y_f.__setitem__ tested `glyphName not in self.glyphOrder`, a linear
scan of the glyphOrder list on every assignment, so repeatedly assigning glyphs
over a pre-populated glyphOrder was O(n^2) in the glyph count -- several seconds
of pure scanning for a 60k-glyph font.

Use the reverse glyph map (_reverseGlyphOrder) for O(1) membership instead,
rebuilding it when it is missing or its length no longer matches glyphOrder, and
invalidating it on __delitem__. Reordering goes through setGlyphOrder, which
already clears the map; editing glyphOrder directly behind the table's back is
unsupported.

Related to #2605, a separate correctness issue (the TTFont-level
_reverseGlyphOrderDict going stale, see #3582), not changed here.



To unsubscribe from these emails, change your notification settings at https://github.com/fonttools/fonttools/settings/notifications

Cosimo Lupo

unread,
Jun 17, 2026, 1:05:28 PM (8 days ago) Jun 17
to fontto...@googlegroups.com
Branch: refs/heads/main
Home: https://github.com/fonttools/fonttools
Commit: 431ca5771611e98cfe06876802fa8ee11485ca28
https://github.com/fonttools/fonttools/commit/431ca5771611e98cfe06876802fa8ee11485ca28
Author: Cosimo Lupo <cos...@anthrotype.com>
Date: 2026-06-17 (Wed, 17 Jun 2026)

Changed paths:
M Lib/fontTools/ttLib/tables/_g_l_y_f.py
M Tests/ttLib/tables/_g_l_y_f_test.py

Log Message:
-----------
[glyf] Use reverse glyph map for O(1) __setitem__ membership

table__g_l_y_f.__setitem__ tested `glyphName not in self.glyphOrder`, a linear
scan of the glyphOrder list on every assignment, so repeatedly assigning glyphs
over a pre-populated glyphOrder was O(n^2) in the glyph count -- several seconds
of pure scanning for a 60k-glyph font.

Use the reverse glyph map (_reverseGlyphOrder) for O(1) membership instead,
rebuilding it when it is missing or its length no longer matches glyphOrder, and
invalidating it on __delitem__. Reordering goes through setGlyphOrder, which
already clears the map; editing glyphOrder directly behind the table's back is
unsupported.

Related to #2605, a separate correctness issue (the TTFont-level
_reverseGlyphOrderDict going stale, see #3582), not changed here.


Commit: 541c1d52019e5a974cbf64f52833729fcd3b4c4f
https://github.com/fonttools/fonttools/commit/541c1d52019e5a974cbf64f52833729fcd3b4c4f
Author: Cosimo Lupo <cos...@anthrotype.com>
Date: 2026-06-17 (Wed, 17 Jun 2026)

Changed paths:
M Lib/fontTools/ttLib/tables/_g_l_y_f.py
M Tests/ttLib/tables/_g_l_y_f_test.py

Log Message:
-----------
Merge pull request #4103 from fonttools/glyf-setitem-perf

[glyf] Use reverse glyph map for O(1) __setitem__ membership


Compare: https://github.com/fonttools/fonttools/compare/3b44a54ae741...541c1d52019e
Reply all
Reply to author
Forward
0 new messages