Avoid cloning owned font data when constructing font faces#8320
Open
undermoonn wants to merge 1 commit into
Open
Avoid cloning owned font data when constructing font faces#8320undermoonn wants to merge 1 commit into
undermoonn wants to merge 1 commit into
Conversation
|
Preview is being built... Preview will be available at https://egui-pr-preview.github.io/pr/8320-epaint-share-font-data View snapshot changes at kitdiff |
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
Reuse the
Arc<FontData>already stored inFontDefinitionsas the owningBlobfor each font face.Previously,
blob_from_font_dataclonedFontData. When the font usesCow::Owned, this also cloned the entire underlying font byte buffer.FontDataalready implementsAsRef<[u8]>, so its existingArccan be used directly as the stable owner required byFontCelland Skrifa.Reproduction
A black-box eframe reproduction is available here:
https://github.com/undermoonn/egui-font-data-clone-repro
The repository contains two branches:
main: crates.ioeframe/epaint 0.35.0patched: the same application with onlyepaintandemathpatched to this changeThe application code and font are identical between the branches. It loads a
7.95 MiB Noto Sans SC font from disk using
FontData::from_ownedand rendersthrough glow/OpenGL.
Three Windows runs were measured for each branch:
mainpatchedThe process-level reduction closely matches the 7.95 MiB font file.
Safety
FontCellretains its own strongArcreference, so the font bytes remain aliveat a stable address for as long as Skrifa references them.
The shared data cannot be mutated in place. Any use of
Arc::make_mutcreates aseparate copy instead of modifying bytes referenced by an existing font face.
Testing
cargo test --locked -p epaint --lib— 45 passedcargo clippy --locked -p epaint --all-targets --all-features -- -D warningscargo check --locked -p epaint --no-default-featurescargo fmt -p epaint -- --check