fontique: parallelize file system font scanning with sparse reads - #3
Open
nicoburns wants to merge 2 commits into
Open
fontique: parallelize file system font scanning with sparse reads#3nicoburns wants to merge 2 commits into
nicoburns wants to merge 2 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:
|
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
Speeds up
ScannedCollection::from_paths(used for system font enumeration on macOS/Android andload_fonts_from_paths) by restructuring the scan into three phases:collect_font_files: walk the given paths up front into a deduplicated file list.parse_files: parse files in parallel acrossavailable_parallelism()threads (std::thread::scope+ an atomic cursor for work stealing), each producing plainFontRecord { names, postscript_name, font }values.FamilyNameMap/FamilyInfo/postscript-name maps on the calling thread (these maps allocate runtime IDs and aren't thread-safe).Per-file parsing also switches from
mmapto positionedreadcalls (mmap page faults serialize in the kernel, defeating parallelism). Rather than reading whole files,read_font_metadatareads only what scanning needs — header, TTC directory, table directories, and thename/OS/2/head/post/fvar/cmaptables — merging overlapping ranges and placing them at their original offsets in a sparse buffer soFontRef::from_indexsees a normal font. This matters for large fonts (CJK, emoji,.ttccollections) where metadata is a tiny fraction of the file.Behavior is preserved: same family/alias/postscript-name results,
hvglfonts still rejected, invalid fonts skipped. Verified on Linux that the sparse-read parse produces byte-identical results (indices, names, postscript names, charmap offsets) to the previous mmap scan across all 236 system font files including a.ttc.Note: I can only cross-compile for macOS from this environment (clippy/check pass for
aarch64-apple-darwin, Windows, wasm, Linux, and a no-stdtarget); real-world timing on macOS still needs to be measured. Stacked PR adding a persistent scan cache follows.Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/60a3d833a0894a73945c806adff1cbf3
Requested by: @nicoburns