Repository navigation
Load each glyph-fallback face once per font system - #558
Merged
Merged
Conversation
A character missing from a run's font loaded every fallback candidate anew, and the only cache lived for a single text run. Each load built a fresh face with a new id, so the canvas glyph cache missed as well. With the Foxit CFF substitutes, whose loading parses every private dictionary and builds a charmap from the whole charset, text-heavy pages that fall back took over ten times longer to interpret, on every redraw. FontSystem now keeps the faces it loads for in-memory fallback programs, keyed by buffer address, length, format and face index, and holds each source so its buffer cannot be freed and its address reused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A character missing from a run's font loaded every fallback candidate anew, and the only cache (
FallbackCache) lived for a single text run. Each load built a fresh face with a newFontFaceId, so the canvas glyph outline cache missed too. With the Foxit CFF substitutes, whose loading parses every private dictionary and builds a charmap from the whole charset, pages whose text falls back took over 10× longer to interpret, on every redraw in the Skia viewer.FontSystemnow keeps the faces it loads for in-memory fallback programs, keyed by buffer address, length, format and face index. It holds each source so its buffer cannot be freed and its address reused.Measurements
Page interpretation (
record_ms, conformance worker,regressionprofile) for a text-heavy document whose embedded TrueType subsets fall back:Bisecting merges showed 7–9 ms up to #555, rising to ~125 ms at #556. Rendered output is byte-identical before and after.
Test plan
cargo fmt --check,cargo clippy --all --workspacecargo test -p pdf-text-engine -p pdf-font -p pdf-canvas -p pdf-renderer🤖 Generated with Claude Code