Commit Graph
21814 Commits
Author SHA1 Message Date
Behdad Esfahbod 5bfff718f1 [harfrust] Reuse cached per-shape metadata (#6200) 2026-08-23 21:58:04 -06:00
Behdad EsfahbodandClaude Fable 5 b04cd416f3 [aat] Force-inline the state-machine transition functions (#6198)
The subtables' transition functions are called once per transition
from the drive loop, but are big enough that the compiler declines to
inline them, leaving a call plus prologue in the hottest loop of AAT
shaping. Force them inline via HB_AAT_TRANSITION_INLINE, defined away
under HB_OPTIMIZE_SIZE.

Measured on the AAT corpus (clang -O3, instructions/cycles vs main):
Lucida Grande -10.3%/-5.2%, Menlo -6.6%, GeezaPro -5.6%/-4.4%,
Devanagari Sangam -5.6%/-2.2%. The ligature machine's transition alone
carries most of the Menlo/Lucida win. Code size: +16KB text (+0.65%).
Outputs byte-identical on the AAT corpus plus PingFang over a CJK
sample.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-22 22:24:44 -06:00
Behdad EsfahbodandClaude Fable 5 29c1b91df1 [ft] Fix -Wdouble-promotion warnings in get_glyph_extents (#6196)
Make the float-to-double widening of the roundf() results explicit,
matching the treatment in glyf.hh from the previous round.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-22 13:09:35 -06:00
ff217d3039 [graphite2] Fix cluster values when the buffer was reversed (#6156)
When the requested direction differs from the script's horizontal
direction, the Graphite2 shaper reverses the buffer before segmenting.
Input cluster values then decrease along the buffer, so assigning each
Graphite group the cluster of its base character can leave earlier
characters outside the resulting cluster map.

Preserve the source span of every Graphite glyph while constructing the
output. At monotone cluster levels, seed each glyph from the minimum
endpoint of that span and use merge_clusters() over each Graphite output
range. Keep the historical base-character behavior at non-monotone
levels.

HarfBuzz cluster values are opaque client labels and can be repeated or
gapped. Merging them can therefore coalesce multiple Graphite layout
groups. Preserve the Graphite group index separately for positioning so
every group's advance is emitted even when its HarfBuzz cluster was
merged. Validate Graphite slot source bounds before indexing the input.

Add shape regressions using a subset of Awami Nastaliq and an API test
with repeated input clusters. The latter used to merge the output
clusters correctly but drop an entire layout-group advance, reducing
the total from 3200 to 1269.

Tested with:
meson test -C build test-graphite2
meson test -C build --suite shape
meson test -C build



Assisted-by: Codex <codex@openai.com>

Co-authored-by: Michael Brown <michael.brown@rubicotech.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-22 12:48:13 -06:00
Behdad EsfahbodandClaude Fable 5 bc9e8db59b [algs] Add a float overload of hb_clamp_to (#6195)
Call sites feeding roundf/floorf/ceilf results into hb_clamp_to
promoted float to double implicitly, tripping -Wdouble-promotion under
clang. The overload widens explicitly — float cannot represent all
integer bounds exactly, so the clamp itself stays in double — and the
two glyf extents assignments that promote outside hb_clamp_to get
explicit casts. No behavior change.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-21 15:07:28 -06:00
Behdad EsfahbodandClaude Fable 5 40949cc70b [ot-layout] Skip the per-subtable digest retest for single-subtable lookups (#6194)
The lookup accelerator's digest is the union of its subtables'
digests, and apply_forward/apply_backward test it before applying the
lookup. For lookups with one subtable - the overwhelming majority -
the subtable's own digest is identical to the accelerator's, so the
per-subtable may_have retest in hb_applicable_t::apply is always true.
Dispatch single-subtable lookups straight to the apply function.

Invalid subtables do not collect and used to rely on their zeroed
entry's empty digest to gatekeep the null apply funcs; trim the zeroed
tail entries at accelerator create time instead, so the apply paths
never see them.

Benchmark-shape instruction counts: Roboto/en-thelittleprince -2.3%,
NotoNastaliqUrdu/fa-thelittleprince -3.7%; outputs unchanged.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-21 14:46:46 -06:00
Behdad EsfahbodandClaude Fable 5 8273c6d2ad [rust] Batch nominal-glyph lookups in the harfrust bridge (#6193)
Implement harfrust's new FontFuncs::populate_nominal_glyphs callback
(harfrust 0.13.1) with a single hb_font_get_nominal_glyphs call per
run, replacing one FFI round-trip per character during the
normalizer's short-circuit prefill. Speeds up the harfrust side of the
benchmark-shape parity suite by 6.2% on Menlo and 4.6% on
LucidaGrande; shaping outputs are unchanged.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-21 13:19:37 -06:00
Behdad EsfahbodandClaude Fable 5 d155a10dff [ot-shape] Skip the post-morx digest update if not applying GPOS (#6192)
The buffer digest is only consumed by the OT lookup-apply loop. After
morx substitution it exists solely for a following GPOS pass; when
positioning goes through kerx/kern instead, rebuilding it is wasted
work. Speeds up the Menlo/en-thelittleprince benchmark by 2%; shaping
outputs are unchanged on the AAT benchmark fonts.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-21 01:10:56 -06:00
Behdad EsfahbodandClaude Fable 5 cf30f712e7 [buffer] Charge move_to moves against max_ops (#6191)
move_to()'s two memmoves - the forward copy into out_info and the
rewind copy-back - were not charged against max_ops, while
shift_forward() already charges its moved tail. A morx insertion
subtable that keeps its mark far behind the insertion point can force
an O(distance) rewind plus re-copy per insertion action, for O(N^2)
total work that the max_ops budget never sees.

Charge count in both branches, mirroring shift_forward()'s failure
pattern. Charging only the rewind branch would also bound the
quadratic, but both memmoves are attacker-drivable work, and
symmetric accounting is simpler to reason about.

Fixes https://github.com/harfbuzz/harfbuzz/issues/6190

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-20 18:10:34 -06:00
Behdad EsfahbodandClaude Fable 5 24b368ec17 [GDEF] Answer mark-filtering-set queries from a cached bit-page (#6188)
Mark-filtering-set checks during lookup application went through a
set-digest pre-filter and then a Coverage binary search in the GDEF
table, for every candidate glyph on every skippy-iterator step.  For
fonts that make heavy use of UseMarkFilteringSet lookups this
dominates shaping time.

Cache each mark set in the GDEF accelerator instead: a set whose
glyphs span fewer than 512 gids (the common case; 102 of 123 sets in
Noto Sans Duployan, 16 of 30 in Gulzar) is flattened into a single
hb_bit_page_t biased at its first glyph, answering exactly in O(1)
with no table access.  Wider sets (eg. possible with 24-bit gids)
keep a set-digest in the same union as a pre-filter ahead of the
out-of-line table fallback, so memory per set is one fixed 68-byte
entry either way.

Shaping the Duployan corpus with Noto Sans Duployan drops 18% in both
instructions retired and wall time (5.25s to 4.27s for three passes of
perf/texts/duployan.txt).  Amiri, Gulzar, Nastaliq, Devanagari, and
Latin fonts are unchanged within noise, with instruction counts
verified flat.

Also adds an HB_NEVER_INLINE macro, used to keep the table fallback
out of the inlined hot path.

Tested with meson test (all 269 tests pass).

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-20 12:37:43 -06:00
Behdad Esfahbod ee9f8d9489 Merge pull request #6187 from harfbuzz/agent/subset-perf
[subset] Misc speedups
2026-08-20 12:37:12 -06:00
Garret Rieger f279195ce7 Remove accidentally committed __pycache__ file. 2026-08-20 11:44:38 -06:00
Behdad EsfahbodandClaude Fable 5 f5ce090554 [subset] Remap ClassDef glyphs through the flat array
Extend the flat old-to-new gid array introduced for Coverage::subset
to ClassDef subsetting: add a map_gsub_glyph() helper on the plan and
use it in ClassDefFormat1/2::subset in place of per-glyph
glyph_map_gsub hash lookups.  The use_class_zero glyph counts switch
from the map to the equivalent glyphset_gsub set.

Tested with meson test (all tests pass).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-20 05:25:15 -06:00
Behdad EsfahbodandClaude Fable 5 f6bcedab83 [subset/cff] Record byte segments instead of tokens when not analyzing hints
The CFF subroutine subsetter recorded one parsed_cs_op_t entry per
charstring token (every operand and operator), then merged adjacent
entries back together in a separate compact() pass.  When hints are
not being analyzed (not dropping hints and not populating the subset
accelerator), per-op granularity is never needed: the only structure
that matters is the subroutine-call sites, whose numbers are
re-encoded with new biases.

In that mode, only note token boundaries (two integer stores) and
flush verbatim byte segments at call sites and at the end of each
string.  CFF1's return/endchar bytes flush through add_op; CFF2 has
no such ops in the stream, so flush explicitly where the interpreter
synthesizes them at end-of-string.  This eliminates the compact()
pass, shrinks the parsed representation by an order of magnitude,
and add_op inlines into the interpreter loop again.

Speeds up CFF subsetting: hb-subset on SourceHanSans (10K glyphs,
all unicodes) improves by ~9.5% total CPU (interleaved A/B against
main with perf stat).  Layout-heavy and glyf fonts unaffected.

Tested with meson test (all 267 tests pass, including CFF1/CFF2
golden-file subset comparisons).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-20 05:21:02 -06:00
Behdad EsfahbodandClaude Fable 5 7990062241 [subset] Remap Coverage glyphs through a flat array
Coverage::subset remapped every covered glyph through the
glyph_map_gsub hash map, paying a hash lookup per glyph.  Build a flat
old-gid-indexed array of new gids (HB_MAP_VALUE_INVALID holes for
unretained glyphs) once per plan, sized to the highest retained GSUB
gid, and index it instead.  The array doubles as the retained-glyph
filter, and the lambda mapper also inlines into the iterator pipeline
where the hb_map_t mapper did not.

Speeds up subsetting layout-heavy fonts: benchmark-subset
subset_unicodes on NotoNastaliqUrdu at 512 codepoints improves by 12%
(26.2ms to 22.9ms), Amiri at 512 by 9%.  No measurable change on
small subsets or glyf-heavy CJK fonts.

Tested with meson test (all 267 tests pass).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-20 05:21:02 -06:00
Behdad Esfahbod cb9460bcbb Merge pull request #6185 from harfbuzz/agent/depend-context-memoization
[depend] Speed up contextual dependency collection
2026-08-20 05:20:24 -06:00
Behdad EsfahbodandClaude Fable 7c349a3f89 [depend] Ignore edge flags in recursion memoization
Edge flags affect neither traversal nor edge identity. A state revisited
with different flags can therefore only attempt edges already present in
the deduplication table, whose first-discovered flags already win. Leave
context-set identity in the key because it does distinguish edges.

This reduces Noto Nastaliq dependency construction from about 110ms and
1.25B instructions to about 106ms and 1.21B instructions.

Dependency graphs match on Noto Nastaliq, Noto Sans Duployan, Gulzar,
Iran Nastaliq, Noto COLRv1, Amiri, and Source Serif Variable.

Tested with: meson test -C build

Co-Authored-By: Claude Fable <noreply@anthropic.com>
Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:53:24 -06:00
Behdad EsfahbodandClaude Fable 8d0b8738ab [depend] Skip cached chained-context preparation
A chained contextual rule with cached record labels no longer needs to
rebuild its backtrack, lookahead, or input-position sets. Reuse the
resolved labels and recurse directly.

Do not take the fast path for rules with no valid lookup records. Those
rules have no label-cache entries, but their original preparation can
still allocate dependency sets in an observable order.

On Noto Nastaliq, compile-only dependency construction falls from about
133ms and 1.58B instructions to about 110ms and 1.25B instructions.
That is about 4,237x faster than the original 7:44.77 run.

Dependency graphs match on Noto Nastaliq, Noto Sans Duployan, Gulzar,
Iran Nastaliq, Noto COLRv1, Amiri, and Source Serif Variable.

Tested with: meson test -C build

Co-Authored-By: Claude Fable <noreply@anthropic.com>
Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:47:15 -06:00
Behdad Esfahbod 980cceb98e [depend] Reuse cached context label lookups
The all-cached precheck already resolves every context-set index, but
the recurse loop looked up each key a second time. Retain those indices
in per-depth scratch storage and consume them directly on the cached
path.

On Noto Nastaliq this reduces compile-only construction from about
136ms to about 133ms while preserving byte-identical graph output.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:39:44 -06:00
Behdad Esfahbod 75455f7338 [depend] Skip cached contextual input expansion
Once every lookup record's context label is cached, the expanded input
position glyph sets are no longer consumed. Check the exact label keys
first and bypass that side-effect-free preparation on a full cache hit.

Keep chained backtrack and lookahead set interning in place because its
allocation order determines observable dependency-set indices.

On Noto Nastaliq, compile-only dependency construction falls from about
151ms and 1.87B instructions to about 136ms and 1.59B instructions. The
original 7:44.77 run is now about 3,420x slower.

Dependency graphs match the pre-change output for Noto Nastaliq,
Noto Sans Duployan, Gulzar, Iran Nastaliq, Noto COLRv1, Amiri, and
Source Serif Variable.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:36:35 -06:00
Behdad EsfahbodandClaude Fable 63b41dab9f [depend] Cache contextual edge labels
Contextual rules rebuild the same position-specific context label for
each visit even though it depends only on the rule, lookup record, and
parent active glyph contents. Intern active glyph sets across top-level
lookups and cache the resulting context-set index by that stable
identity.

This avoids repeated set scans, intersections, and content hashing
without changing traversal or label semantics. On Noto Nastaliq,
compile-only dependency construction falls from about 209ms and 2.77B
instructions to about 151ms and 1.87B instructions. That is about
3,080x faster than the original 7:44.77 run.

Dependency graphs match the pre-change output for Noto Nastaliq,
Noto Sans Duployan, Gulzar, Iran Nastaliq, Noto COLRv1, Amiri, and
Source Serif Variable.

Tested with: meson test -C build

Co-Authored-By: Claude Fable <noreply@anthropic.com>
Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:27:07 -06:00
Behdad Esfahbod 3a1ab8f173 [depend] Compact edge deduplication storage
Dependency edges are already retained in per-glyph output vectors, but the
generic deduplication hashmap stored another complete edge record in every
36-byte bucket. Replace it with an exact open-addressed table whose buckets
hold only an eight-byte source and per-glyph edge index. Hash collisions are
resolved by comparing the retained records, preserving first-seen ordering
and flags.

On Noto Nastaliq this reduces construction from about 229ms to 209ms and
from 2.83 to 2.77 billion instructions. Peak RSS falls from about 46MB to
28MB, while cumulative allocated bytes fall from about 78.4MB to 49.1MB.

Dependency graphs match for Noto Nastaliq, Noto Sans Duployan, Gulzar,
Iran Nastaliq, Noto COLRv1, Amiri, and Source Serif Variable Roman.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:16:51 -06:00
Behdad Esfahbod 5bf0cfbc45 [set] Insert coverage intersections by bitmap word
Coverage format 2 now reads intersection results a word at a time, but
still inserted every selected glyph separately. Add an internal
word-at-a-time set insertion path and use it when the output sink is an
hb_set_t, preserving the generic per-glyph fallback for other sinks.

This removes another about 121M instructions from Noto Nastaliq
dependency construction. The compile-only run now takes about 226ms
task-clock / 229ms elapsed and 2.83B instructions, over 2,000x faster
than the original 7:44.77 run.

Dependency graphs match the original output for Noto Nastaliq, Noto
Sans Duployan, Gulzar, Iran Nastaliq, Noto COLRv1, Amiri, and Source
Serif Variable Roman.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:04:54 -06:00
Behdad Esfahbod f3a00d0086 [set] Intersect coverage ranges by bitmap word
Coverage format 2 previously advanced the input set one glyph at a time
inside each coverage range. Fetch nonempty 64-bit words instead, mask the
boundary words, and consume their bits locally.

This removes about 96M instructions, or 3.2%, from Noto Nastaliq
dependency construction. Dependency graphs match the previous output
across Noto Nastaliq, Duployan, Gulzar, Iran Nastaliq, Noto COLRv1,
Amiri, and Source Serif Variable.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 04:00:24 -06:00
Behdad Esfahbod 7951998565 [set] Compute iterator length lazily
Set iteration does not always need the remaining item count. Defer the
population scan until len() is first requested, using unsigned accounting
to track advances without adding a branch to the iterator hot path.

This preserves fast length for iterator consumers that use it while
avoiding unnecessary population scans for the others. Noto Nastaliq
dependency construction is instruction-neutral because its existing set
iterators already encounter cached populations.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 03:55:41 -06:00
Behdad Esfahbod 375b3f4b33 [depend] Combine edge deduplication lookup and insert
Use a non-overwriting hashmap insertion to detect duplicate dependency
edges. This avoids hashing and probing every newly inserted edge twice,
while still distinguishing duplicates from allocation failures through
the hashmap error state.

The NotoNastaliqUrdu compile-only dependency workload saves about 2.2M
instructions. Its wall-time change is below measurement noise.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 03:48:08 -06:00
Behdad Esfahbod 4daafa0767 [depend] Encode common active glyph states
Root and singleton active-glyph sets dominate dependency recursion memo
keys. Avoid copying and interning the root set, and encode singleton glyph
IDs directly in the key.

Add an internal singleton query that can recognize uncached sparse sets in
one pass while preserving the population cache.

On NotoNastaliqUrdu-Regular.ttf this reduces the compile-only dependency
run from about 3.18B to 3.05B instructions and from about 245ms to 238ms.
Dependency graphs match the previous output across the focused font
corpus.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 03:45:19 -06:00
Behdad Esfahbod 772005ba59 [depend] Intern recursion paths directly
Memoization previously interned the full set of in-progress lookups for
every recursive dispatch.  Hashing, comparing, and copying those sets
became visible after the larger dependency-analysis speedups.

Assign stable IDs to ordered recursion paths instead.  The path identity
is conservatively more specific than lookup-set identity, while the
separate bit set continues to provide exact cycle detection.

This reduces Noto Nastaliq dependency construction by about 4% in
instructions while preserving byte-identical graphs across the tested
font corpus.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 03:16:03 -06:00
Behdad Esfahbod c011af18b9 [subset] Use set iterators when formatting input
Walk tag sets and sorted glyph-map keys through their native iterators
instead of repeatedly calling the public scalar set API.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 02:48:34 -06:00
Behdad Esfahbod 3c55d48206 [set] Iterate over bitmap words
Fetch one nonempty 64-bit bitmap word at a time and consume its bits
locally in hb_set_t iterators. This avoids searching the sparse page
map once per codepoint while preserving inverted-set iteration and
bidirectional iterator behavior.

Mutating a set now explicitly invalidates its iterators.

Noto Nastaliq dependency construction is about 1-2% faster in an A/B
comparison, with 3.33B instructions reduced to 3.31B.

Tests: meson test -C build (272/272)
Tests: Noto dependency graph byte-identical to the pre-change oracle
Tests: full-Unicode subset output byte-identical for Noto Nastaliq,
       Amiri, Source Serif Variable, and Noto COLRv1

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 02:45:18 -06:00
Behdad Esfahbod 31d8ff343e [depend] Flatten lookup feature storage
The per-lookup nested feature vectors introduced a leak in the sanitizer
job: their inner allocations were lost when the temporary dependency
builder was destroyed on GitHub's Clang 18 build.

Pack lookup index and feature tag into a single flat uint64_t vector, then
sort and deduplicate it and build per-lookup offsets. This preserves the
compact sequential traversal and its performance while giving the builder
only flat owning containers.

Tests: meson test -C build (272/272)
Tests: Clang 18 ASan/UBSan depend-fuzzer chunks (9/9)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 02:33:15 -06:00
Behdad Esfahbod b3eb3329d2 [depend] Store lookup feature tags in vectors
Lookup feature tags are collected once, then only iterated while dependency
edges are emitted. Sparse sets make each of those tiny iterations pay bit-page
lookup costs in a major graph-construction hot path.

Append tags to per-lookup vectors, then sort and deduplicate each vector once
after collection. This preserves the set's sorted iteration order while
avoiding quadratic insertion behavior for pathological feature lists.

On Noto Nastaliq this reduces dependency compilation from about 275ms to
259ms, with instructions falling from 3.50 billion to 3.32 billion. Output
is byte-identical.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 02:09:19 -06:00
Behdad Esfahbod 87f696af11 [set] Make intersection workspace optional
Pass reusable intersection workspace as an optional pointer through the set
layers. Existing callers keep the ordinary local-workspace behavior, while
hot paths can opt into retaining the temporary allocation.

This also lets dependency position collection supply workspace only for the
class/parent intersection that can actually require compaction.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 02:09:19 -06:00
Behdad Esfahbod b3f9708a1e [set] Allow reusing intersection workspace
Removing pages during a bit-set operation needs a temporary index vector.
The normal set API allocates this vector locally so arbitrary callers do not
carry extra storage, but dependency traversal performs the same class-set
intersection hundreds of thousands of times.

Add an internal intersection overload that accepts caller-owned workspace,
and retain that workspace in the contextual recursion scratch pool. The
ordinary intersection path and its exact-sized temporary remain unchanged.

On Noto Nastaliq this removes 271 thousand allocation calls, reducing the
post-stack-reuse total from 371 thousand to 100 thousand. Compilation time
improves slightly from about 277ms to 275ms, and output is byte-identical.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 01:55:02 -06:00
Behdad Esfahbod 8940e7050b [depend] Retain active glyph set storage
Dependency recursion moves each position glyph set onto the active stack.
Popping the stack then destroys the set and its backing pages, so the next
edge has to allocate them again.

Keep constructed stack slots and track the active depth separately. Reused
slots are cleared before use, preserving the previous empty-set semantics
while retaining their allocations across sibling traversals.

After contextual scratch pooling, this reduces Noto Nastaliq dependency
compilation from about 294ms to 277ms. Allocation calls fall from 1.19
million to 371 thousand, and cumulative allocated bytes fall from 163MB
to 80MB. Serialized output remains byte-identical.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 01:49:31 -06:00
Behdad Esfahbod de89b1a490 [depend] Reuse contextual recursion scratch storage
Contextual dependency traversal repeatedly constructs temporary glyph sets
and pointer vectors. On Noto Nastaliq this causes over five million
allocation or reallocation calls even after recursion memoization.

Keep one scratch bundle per active contextual recursion level and recycle it
across sibling traversals. This retains backing capacity while preserving
the independent state needed by nested lookups.

For NotoNastaliqUrdu-Regular.ttf, dependency compilation drops from about
374ms to 294ms. Allocation calls drop from 5.26 million to 1.19 million,
and cumulative allocated bytes drop from 480MB to 163MB. Output is
byte-identical.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 01:44:31 -06:00
Behdad Esfahbod ebf8ad8718 [util] Separate dependency compile and retrieval modes
The quiet option currently exits immediately after compiling the
dependency graph, making it impossible to measure public API retrieval
separately from formatting and output.

Make -q/--quiet retrieve all selected edges without printing them, and
add --compile for construction-only runs.  Avoid creating a font in
quiet mode since glyph names are not needed.

On Noto Nastaliq, compilation takes 362ms and retrieving every edge adds
about 1.4ms, showing that formatting rather than public API retrieval is
the remaining tool-side cost.

Tested with the full Meson test suite (272/272 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 01:11:59 -06:00
Behdad Esfahbod f454a49034 [depend] Keep covered context positions inline
Contextual dependency traversal uses a set to track sequence positions
already covered by earlier lookup records.  Those positions are bounded
by HB_MAX_CONTEXT_LENGTH, but the general sparse set allocates its first
bit page on every contextual rule.

Use one inline hb_bit_page_t for dependency traversal.  Its 512 bits are
well above the configured 64-position context limit.  This reduces quiet
Noto Nastaliq graph construction from 385ms to 363ms.

Tested with the full Meson test suite (272/272 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 01:06:37 -06:00
Behdad Esfahbod 5aa7a80aa5 [depend] Cache contextual position glyph sets
Dependency graph extraction repeatedly expands identical class
definitions and coverages into temporary sets while traversing
contextual rules.  It also repeatedly interns those same sets when
recording context requirements.

Cache immutable position sets by source identity, reuse their context
set indices, and pass pointers through the short-lived position vectors
instead of copying their contents.  This reduces quiet Noto Nastaliq
graph construction from 685ms to 385ms on the profiling machine while
preserving the graph byte-for-byte.

Tested with the full Meson test suite (272/272 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 00:56:25 -06:00
Garret Rieger f7cef099e1 Fix potential divide by zero in apply_stch(). (#6186)
The product of n_copies * n_repeating can plausibly overflow uint32_t bounds leading to a divide by zero. Cast the values up to int64_t for the multiplication to prevent overflow. Otherwise both n_copies and n_repeating are guaranteed to be non-zero
2026-08-19 16:43:08 -06:00
Behdad Esfahbod 7584482381 [test] Isolate Noto Nastaliq depend parity tests
The Noto Nastaliq fixtures dominate the runtime of a 64-font dependency
closure-parity chunk, obscuring both their cost and the runtime of the
remaining fixtures.

Run each Noto Nastaliq font as its own named test while retaining the
same seed and per-font test count. Keep all other fonts in the normal
chunking flow.

Tested with the full Meson test suite (272/272 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 16:14:40 -06:00
Behdad Esfahbod 5e75e91ebf [set] Add hb_set_intersects API
Expose the exact set-intersection query so callers can test whether two
sets have any elements in common without copying and mutating a set.
The implementation handles inverted sets through the internal helper.

Document the new API with its release placeholder, add it to the docs
section index, and cover regular and inverted set combinations.

Tested with the full Meson test suite (270/270 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 16:00:05 -06:00
Behdad Esfahbod 80529ca839 [set] Add exact set intersection helper
Set-to-set intersection currently only has a conservative may_intersect
helper because sets can be inverted. Callers that know their sets are
not inverted must otherwise reach through two implementation layers.

Add an exact intersects overload that handles all inversion combinations
without allocating. Use it for contextual dependency collection and add
unit coverage for normal, mixed, and inverted pairs.

Tested with the full Meson test suite (270/270 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 15:57:10 -06:00
Behdad Esfahbod 8fe7910b00 [depend] Memoize contextual lookup recursion
Contextual GSUB dependency collection revisits completed lookup states
through each parent path. Complex Nastaliq lookup graphs therefore spend
minutes repeatedly expanding identical subgraphs.

Intern the recursion inputs and cache completed states per top-level
lookup. Remove unused contextual stack bookkeeping and avoid temporary
set allocation for exact intersection checks. Re-enable the Nastaliq
closure-parity fixtures now that they complete quickly.

Tested with the full Meson test suite (270/270 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 15:53:15 -06:00
Behdad Esfahbod c1d4eeda7b [util] Add quiet mode to hb-subset-depend
Add -q/--quiet to build and validate a dependency graph without spending
time formatting or printing it. This makes graph-construction profiling
and performance measurements straightforward.

Tested with the full Meson test suite (270/270 passed).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 15:51:00 -06:00
Behdad Esfahbod fd7c1835ea [cff] Reject non-SEAC charstrings from their suffix (#6184)
SEAC dependency discovery interpreted every CFF1 charstring to inspect
the operand stack at endchar. Most glyphs instead end in a path operator
that has already cleared the stack, making full interpretation needless.

Recognize every Type 2 number encoding that could end immediately before
endchar and retain the full interpreter for those ambiguous cases. Also
retain it for subroutine calls, which can leave operands on the shared
stack. Reject other suffixes without interpreting the charstring.

This reduces 100 dependency scans of the SourceHan test font from 1.38s
to 0.36s and 50 full subsets from 2.56s to 2.05s. The pathological
dependency-fuzzer chunk drops from 1.31s to 0.04s. The full 270-test Meson
suite passes.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 14:59:48 -06:00
Behdad Esfahbod 48541baf09 [test/threads] Use focused shaping corpora (#6183)
The thread-safety test shaped entire books and a twelve-thousand-line word
list in every worker.  That made it behave like a benchmark even though
the races it targets are exercised when threads concurrently initialize
and use a shared font.

Use the existing substantial paragraph corpora instead.  They retain
Latin and Arabic-script coverage across every font backend and both
variable-font modes while reducing standalone runtime from about 1.09s
to 0.16s.

Also reset the worker start gate for every backend so each combination
actually begins concurrently instead of only synchronizing the first.

The full 270-test Meson suite passes, as does an 8-thread, 5-repetition
stress run.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 14:20:54 -06:00
Behdad Esfahbod 0248d1aa45 Merge pull request #6181 from harfbuzz/codex/vector-raster-work-budgets
[vector/raster] Bound per-session output work
2026-08-19 14:19:46 -06:00
Behdad Esfahbod c0133a2fdd [depend] Deduplicate ligature dependency data (#6182)
Ligature dependency extraction built a set of component glyphs, but then
walked the original component array and allocated a distinct copy of the
set for every ligature record.  Repeated components and equivalent
ligature rules consequently generated millions of redundant edge lookups
and set objects on malformed fonts.

Walk the already-deduplicated component set and intern ligature sets using
the existing content-based dependency-set map.  Preserve the unused-set
reuse path by discarding only newly interned sets.

The slow dependency-fuzzer seed improves from about 0.91s and 292MB peak
RSS to 0.24s and 80MB.  The full 270-test Meson suite passes.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-19 14:19:32 -06:00
Behdad Esfahbod fd3fe6c54f [vector/raster] Bound output-session work
VARC's traversal budget still allowed one glyph to amplify into large
serialized paths or millions of raster edges.  Vector paint also
charged outline bytes only after a whole glyph, allowing an unbounded
single-operation overshoot.

Charge complete SVG/PDF path commands against cumulative draw and
paint context budgets, reset on clear.  Cap each raster draw session's
stored edges and stop processing outline callbacks after exhaustion.

The pathological VARC seed now keeps raster chunk 7 below 0.8 seconds
and vector chunk 7 below 1 second in the full suite.  SVG and PDF
outputs remain syntactically valid at the budget boundary.

Tested with the vector, raster, fuzzing, and full Meson test suites.

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-08-19 13:39:49 -06:00