render: stop re-indexing host fonts per fallback measurement - #1504
Merged
developer0hye merged 1 commit intoSep 2, 2026
Merged
Conversation
glyph_advances_em_with_typst_fallback, best_face, and the two cached advance lookups obtained the default font search paths by resolving a full FontSearchContext, which indexes every face on the host. Outside an active context that ran once per measured run: a 35-page report with many overlong tokens spent 111 s of a 112 s conversion inside index_families_from_paths (sampled on macOS, Apple M4 Pro), where v0.6.7 converts the same file in 1.7 s. Memoize the default paths, at most six directory probes, in default_font_search_paths and use it at every site, including resolve_font_search_context itself and the test probe's private OnceLock. A test pins the memoized paths to the resolved context's search paths, and a test-only counter asserts that the fallback lookup resolves no context. Assisted-by: LLM (Claude) Signed-off-by: Aktan Azat <aktanaazat@gmail.com>
aktanazat
force-pushed
the
fix/default-font-search-paths
branch
from
September 1, 2026 23:28
e1a12fb to
d88af64
Compare
Owner
|
Thank you for tracking this down, and for the What I verified before merging:
The pinned-equality test and the resolution counter are exactly the right two assertions for this change. Much appreciated. |
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
glyph_advances_em_with_typst_fallback,best_face, and the two cached advance lookups obtained the default font search paths by callingresolve_font_search_context(&[]), which indexes every face on the host. Outside an active font context that ran once per measured run. On a 35-page DOCX with many overlong tokens,sampleattributed 111 s of a 112 s conversion toindex_families_from_pathsunderglyph_advances_em_with_typst_fallback; v0.6.7 converts the same file in 1.7 s.default_font_search_pathsnow memoizes the paths (at most six directory probes, once per process) in aLazyLock, every site uses it, andresolve_font_search_contextreads the same slice. The--metricscodegen stage on that file drops from 111 s to 0.3 s; the full lib test suite drops from 234 s to 28 s on this machine because the tests hit the same path.Related issue
None filed. The per-run resolution arrived with #1456 (Related: #1454), which added the overlong-token measurement; v0.6.7 predates it. Numbers measured on an Apple M4 Pro, macOS 26.6, with Microsoft Office fonts present.
Testing
cargo test -p office2pdf --lib(2777 passed)cargo fmt --all --check,cargo clippy -p office2pdf --all-targets(only the pre-existingeffective_last_resort_familydead-code warning)test_default_font_search_paths_match_the_resolved_contextpins the memoized paths toresolve_font_search_context(&[]).search_paths();test_fallback_glyph_advances_do_not_resolve_a_font_contextuses a test-only counter (same pattern asAUTO_ROW_FRAME_ESTIMATE_CALLS) and fails onmainwith 1 resolution per call.Visual impact
Checklist
Signed-off-byline