Skip to content

Conversation

@valadaptive
Copy link
Contributor

Stacked on #542; the last commit is the new one.

Previously, drawing a glyph performed the following lookups, in order:

  1. A skrifa::BitmapStrikes lookup
  2. If that fails (which it probably will, because most fonts are not bitmaps), a skrifa::ColorGlyphCollection lookup
  3. If that fails (which it probably will, because most fonts are not COLR), a skrifa::OutlineGlyphCollection lookup
  4. An outline cache lookup

The Skrifa lookups are somewhat slow. I believe they perform a binary search on the raw font data internally.

We can optimize this by:

  • Checking for an outline glyph first, since most glyphs are outline glyphs
  • Checking the outline cache without ever going through Skrifa

To do this, I refactored the prepare_[kind]_glyph functions to return an Option; this allows them to perform the requisite Skrifa "does the glyph exist" lookups themselves. The prepare_outline_glyph function can then check the outline cache itself, before doing a potentially-expensive Skrifa lookup. I also changed the outline cache to store Option<OutlinePath>, so we can store absent glyphs in the cache too.

Combined with the changes from #542, this is a ~10% speedup above current main, at least on my machine.

@valadaptive valadaptive requested review from conor-93 and taj-p February 8, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant