Cache primary font queries and font metrics across layouts in FontContext - #19
Open
nicoburns wants to merge 3 commits into
Open
Cache primary font queries and font metrics across layouts in FontContext#19nicoburns wants to merge 3 commits into
nicoburns wants to merge 3 commits into
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
2 times, most recently
from
September 3, 2026 14:05
f1dfc77 to
7a2665b
Compare
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
from
September 3, 2026 14:15
7a2665b to
5f61d3a
Compare
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
from
September 3, 2026 14:32
5f61d3a to
c01db93
Compare
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
2 times, most recently
from
September 3, 2026 15:47
2bf324d to
441c7bd
Compare
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
from
September 3, 2026 17:05
441c7bd to
f84aff0
Compare
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
from
September 3, 2026 17:26
f84aff0 to
f191978
Compare
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
from
September 3, 2026 17:38
f191978 to
312295a
Compare
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
from
September 3, 2026 17:54
312295a to
296e16a
Compare
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
3 times, most recently
from
September 8, 2026 14:42
be970e2 to
758580b
Compare
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
from
September 8, 2026 15:59
758580b to
ac1079d
Compare
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
from
September 9, 2026 09:16
ac1079d to
d2b9cce
Compare
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
4 times, most recently
from
September 9, 2026 13:39
fc8a766 to
f3463d2
Compare
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
2 times, most recently
from
September 9, 2026 14:39
e5e21be to
533d713
Compare
Cache fontique primary-font queries (keyed on the FamilyId stack and attributes) and FontMetrics (keyed on blob id, index, size bits and variations) in FontContext so they survive across layouts. The cache is invalidated via a new Collection::generation() counter that is bumped on every mutation of the fontique collection. The shaper uses the cached primary font only for clusters it fully covers; anything else goes through the existing per-cluster fallback query so font fallback behaviour is unchanged.
When the cached primary font does not fully cover a cluster, seed the fallback query with its coverage and skip it when the query yields it again, so that no cluster computes coverage for the same font twice.
staging-devin-ai-integration
Bot
force-pushed
the
devin/1788393297-font-cache
branch
from
September 9, 2026 16:22
533d713 to
2be9fb5
Compare
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.
LLM Contributions: This PR was written with Devin, which also ran the benchmarks below.
Stacks on #18 (
devin/1788383056-vertical-align). #18 re-runs afontique::Queryper style per layout (resolve_style_metrics) and re-parses fonts forFontMetrics; the shaper'sFontSelectorrepeats the same query per item. This adds a cross-layout cache owned byFontContext:(FamilyId stack, FontWidth, FontWeight, FontStyle) -> Option<FontInstance + CharmapIndex>. Keyed on the actualFamilyIdlist becauseResolveContextfamily-stack handles are per-LayoutContextinterned indices, not stable across layouts. A miss runs the query but only accepts a font from the requested families (never from the query's fallback families), so the result is independent of fallback settings and the cachedNonemeans "no family font".(blob id, font index, size bits, synthesis variation settings + style variations) -> FontMetrics.MAX_ENTRIES = 1024, cleared when full).fontique::Collection::generation()counter, bumped on every mutatingCollectionmethod (register/unregister fonts, load system fonts, load from paths, generic families, fallbacks, clear) and when a shared collection syncs a newer version from another clone.FontContextcompares it before each layout and drops the cache on change.FontContext::clear_cache()exists for mutations the collection can't see (e.g. swapping blob data);FontContext::cache_len()exposes entry counts. Struct-literal construction ofFontContextis replaced withFontContext::from_parts.FontKeydedup instyle_metrics.rsis kept as the first-level (hash-free) cache.FontSelectortakes the cached primary font for the current style. A cluster fully covered by it is resolved without touching the query (this is exactly what the query would yield first). Otherwise the normal per-cluster fallback query runs, seeded with the primary font's coverage so it isn't computed twice. Fallback behaviour is unchanged; emoji clusters bypass the cache entirely as before.core_maths::CoreFloatimportstyle_metrics.rsneeded for--no-default-features --features libm(x86_64-unknown-none), which was failing on Implement CSSvertical-alignfor inline formatting contexts #18.Tests:
parley/src/tests/test_font_cache.rscovers reuse across layouts, invalidation onregister_fonts/set_fallbacks, negative caching for unknown families, andCollection::generation()bumps.cargo fmt --all --check,cargo test --workspace,cargo clippy --workspace --all-targets -- -D warningspass.Tango (
parley_bench), base = #18 headff83800, this branch =5c31f79Latin (where the primary font covers everything) gains 5–13%, which more than recovers the +3–10% #18 cost on short styled layouts. Arabic/Japanese rows (primary Roboto covers nothing, so every cluster goes through fallback) are within noise except a ~+3.5% on two "Styled - japanese" rows that was not reproducible across three runs (−1.7%..+3.9%).
Changelog
Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/3a0b8cc210c041d8955c841fb2a76a8e
Open in Devin Desktop: https://dioxus.staging.devinenterprise.com/desktop/session/3a0b8cc210c041d8955c841fb2a76a8e?variant=devin-insiders
Requested by: @nicoburns