From 8940e7050b8a4e85fa8a79bd67a073525704a15f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 20 Aug 2026 01:49:31 -0600 Subject: [PATCH] [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 --- src/hb-ot-layout-gsubgpos.hh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index ea06aa0ef..54cc39397 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -484,25 +484,29 @@ struct hb_depend_context_t : const hb_set_t& parent_active_glyphs () { - if (!active_glyphs_stack) + if (!active_glyphs_stack_depth) return *glyphs; - return active_glyphs_stack.tail (); + return active_glyphs_stack[active_glyphs_stack_depth - 1]; } hb_set_t* push_cur_active_glyphs () { - if (unlikely (!active_glyphs_stack.push_or_fail ())) + if (active_glyphs_stack_depth == active_glyphs_stack.length && + unlikely (!active_glyphs_stack.push_or_fail ())) return nullptr; - return &active_glyphs_stack.tail (); + + hb_set_t *set = &active_glyphs_stack[active_glyphs_stack_depth++]; + set->clear (); + return set; } bool pop_cur_done_glyphs () { - if (!active_glyphs_stack) + if (!active_glyphs_stack_depth) return false; - active_glyphs_stack.pop (); + active_glyphs_stack_depth--; return true; } @@ -627,6 +631,7 @@ struct hb_depend_context_t : hb_face_t *face; hb_set_t *glyphs; hb_vector_t active_glyphs_stack; + unsigned active_glyphs_stack_depth = 0; recurse_func_t recurse_func; hb_codepoint_t lookup_index = HB_CODEPOINT_INVALID; hb_set_t lookups_seen;