Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[skrifa] autohint: use visited set when processing GSUB lookups #1365

Merged
merged 1 commit into from
Feb 21, 2025

Conversation

dfrg
Copy link
Member

@dfrg dfrg commented Feb 21, 2025

Adds a visited set to GSUB traversal for autohinting to prevent redundant processing of lookups. This can cause a perceived hang on fonts with large complex lookup graphs (like Noto Nastaliq Urdu) even when there are no cycles.

Also removes the existing cycle detection code since it is no longer needed.

Fixes #1363

Adds a visited set to GSUB traversal for autohinting to prevent redundant processing of lookups. This can cause a perceived hang on fonts with large complex lookup graphs (like Noto Nastaliq Urdu) even when there are no cycles.

Also removes the existing cycle detection code since it is no longer needed.

Fixes #1363
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question inline, looks like a sane approach.

/// Invokes the callback with a memory buffer of the requested size.
pub(super) fn with_temporary_memory<R>(size: usize, mut f: impl FnMut(&mut [u8]) -> R) -> R {
// Wrap in a function and prevent inlining to avoid stack allocation
// and zeroing if we don't take this code path.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as in dead code analysis would not prune the branch if it was inlined? Is this a common trick?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this just guarantees that we'll never end up with a stack frame that is the sum of all potential buffer sizes. LLVM would probably do a dynamic stack adjustment (alloca style) for each branch but you never know...

@dfrg dfrg merged commit e250138 into main Feb 21, 2025
10 checks passed
@dfrg dfrg deleted the autohint-gsub-visited-set branch February 21, 2025 19:45
drott added a commit to drott/fontations that referenced this pull request Feb 24, 2025
Release tip of tree with fix for googlefonts#1363 hang in gsub
processing during autohinting of Noto Nastaliq.

Changes for read-fonts from read-fonts-v0.27.1 to 0.27.1
        5657ab8 [chore] Clippy day
        53407d0 [read-fonts] CFF charsets (googlefonts#1361)
Changes for write-fonts from write-fonts-v0.36.0 to 0.36.0
        5657ab8 [chore] Clippy day
        029f62f [font_builder] provide more expository comment
        7f95b52 [font_builder] test recommended table order
        a49be74 [font_builder] test checksum_adjustment
        ffc69ee [font_builder] compute head.checksum_adjustment and sort table in recommended order
        53407d0 [read-fonts] CFF charsets (googlefonts#1361)
Changes for skrifa from skrifa-v0.28.0 to 0.28.0
        e250138 [skrifa] autohint: use visited set when processing GSUB lookups (googlefonts#1365)
        441a388 [skrifa] Remove unused write-fonts dev-dep
        652b3ca Apply limits to cmap12 iterator (googlefonts#1352)
        24fb1c8 [skrifa] tthint: adjust DELTAP/DELTAC limits (googlefonts#1353)
drott added a commit that referenced this pull request Feb 24, 2025
Release tip of tree with fix for #1363 hang in gsub
processing during autohinting of Noto Nastaliq.

Changes for read-fonts from read-fonts-v0.27.1 to 0.27.1
        5657ab8 [chore] Clippy day
        53407d0 [read-fonts] CFF charsets (#1361)
Changes for write-fonts from write-fonts-v0.36.0 to 0.36.0
        5657ab8 [chore] Clippy day
        029f62f [font_builder] provide more expository comment
        7f95b52 [font_builder] test recommended table order
        a49be74 [font_builder] test checksum_adjustment
        ffc69ee [font_builder] compute head.checksum_adjustment and sort table in recommended order
        53407d0 [read-fonts] CFF charsets (#1361)
Changes for skrifa from skrifa-v0.28.0 to 0.28.0
        e250138 [skrifa] autohint: use visited set when processing GSUB lookups (#1365)
        441a388 [skrifa] Remove unused write-fonts dev-dep
        652b3ca Apply limits to cmap12 iterator (#1352)
        24fb1c8 [skrifa] tthint: adjust DELTAP/DELTAC limits (#1353)
aarongable pushed a commit to chromium/chromium that referenced this pull request Mar 7, 2025
This is a cherry-pick to M134, branch 6998, of the fix in
https://chromium-review.googlesource.com/c/chromium/src/+/6298807
reduced to only the visited-set fix of GSUB processing in Skrifa
from
googlefonts/fontations#1365

Updated crates:

* skrifa: 0.26.5 => 0.26.6

Skrifa vetted for does-not-implement-crypto, ub-risk-0, safe-to deploy.

Bug: chromium:396173460
Change-Id: I38f8be5acb52da1f4fe9312030fecfc56046d946
Disable-Rts: True
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6305501
Reviewed-by: Łukasz Anforowicz <[email protected]>
Commit-Queue: Dominik Röttsches <[email protected]>
Cr-Commit-Position: refs/branch-heads/6998@{#1867}
Cr-Branched-From: de9c6fa-refs/heads/main@{#1415337}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autohinting of Noto Nastaliq 3.007 hangs in GSUB processing
2 participants