Skip to content

Conversation

@dfrg
Copy link
Collaborator

@dfrg dfrg commented Jan 5, 2026

This extracts the primary coverage table (along with any suitable caches) into a field on SubtableInfo so that we can check coverage before attempting to parse the subtable. The glyph id, coverage index, coverage metadata and external cache are then passed to the subtable apply function in a new ApplyState parameter. This avoids some buffer indexing and reparsing the primary coverage table.

This attempts to clean up and unify some of the caching code paths along with laying some groundwork for future optimizations (like #260).

HR benchmarks seem to show a reasonable gain on non-Latin shaping as a bonus.

This extracts the primary coverage table (along with any suitable caches) into a field on `SubtableInfo` so that we can check coverage before attempting to parse the subtable. The glyph id, coverage index, coverage metadata and external cache are then passed to the subtable apply function in a new `ApplyState` parameter. This avoids some buffer indexing and reparsing the primary coverage table.

This attempts to clean up and unify some of the caching code paths along with laying some groundwork for future optimizations (like #260).

HR benchmarks seem to show a reasonable gain on non-Latin shaping as a bonus.
@dfrg dfrg requested a review from behdad January 5, 2026 20:31
@behdad
Copy link
Member

behdad commented Jan 5, 2026

I see a 6% slowdown on Roboto, although speedup on heavier Arabic fonts:

Comparing before to after
Benchmark                                                                               Time             CPU      Time Old      Time New       CPU Old       CPU New
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
BM_Shape/Roboto-Regular.ttf/en-thelittleprince.txt/harfrust                          +0.0655         +0.0655             7             7             7             7
BM_Shape/Roboto-Regular.ttf/en-words.txt/harfrust                                    +0.0200         +0.0205            12            12            12            12
BM_Shape/SourceSerifVariable-Roman.ttf/react-dom.txt/harfrust                        +0.0028         +0.0032            77            77            77            77
BM_Shape/NotoSansDevanagari-Regular.ttf/hi-words.txt/harfrust                        +0.0001         +0.0001            27            27            27            27
BM_Shape/Amiri-Regular.ttf/fa-thelittleprince.txt/harfrust                           -0.1877         -0.1878            39            32            39            32
BM_Shape/NotoNastaliqUrdu-Regular.ttf/fa-thelittleprince.txt/harfrust                -0.0602         -0.0597            87            82            87            82
BM_Shape/NotoNastaliqUrdu-Regular.ttf/fa-words.txt/harfrust                          -0.0594         -0.0591           103            97           103            97
BM_Shape/Gulzar-Regular.ttf/fa-thelittleprince.txt/harfrust                          -0.1554         -0.1555          2200          1858          2190          1850
BM_Shape/Gulzar-Regular.ttf/fa-words.txt/harfrust                                    -0.1409         -0.1408          1426          1225          1418          1219
BM_Shape/NotoSansDuployan-Regular.otf/duployan.txt/harfrust                          -0.1638         -0.1639          3079          2574          3065          2562
OVERALL_GEOMEAN                                                                      -0.0718         -0.0716             0             0             0             0

}

pub struct ApplyState<'a> {
pub first_glyph: GlyphId,
Copy link
Member

Choose a reason for hiding this comment

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

Should this be u32 at least?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a u32 underneath. I don't have a preference on the actual type

Copy link
Member

Choose a reason for hiding this comment

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

Oh that's good to know. I was under the impression that it's 16bit, and hence a headache to update for beyond-64k.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A while back we added GlyphId16 specifically for 16-bit glyphs and changed our common GlyphId to be 32-bit.

@dfrg
Copy link
Collaborator Author

dfrg commented Jan 5, 2026

I see a 6% slowdown on Roboto

oof, the Roboto benches are so temperamental :( I'll see if I can figure out why.

@behdad
Copy link
Member

behdad commented Jan 5, 2026

Patch generally looks fine to me. My only concern is that we're getting more and more distanced from HB in some of the trickiest part of the code. I'm afraid I'll have to defer to you porting any changes in subtable instantiation or caching in the future.

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.

3 participants