From b04cd416f36748c808aae4d8a9f399bce2eac10f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Aug 2026 22:24:44 -0600 Subject: [PATCH] [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 --- src/hb-aat-layout-common.hh | 11 +++++++++++ src/hb-aat-layout-kerx-table.hh | 2 ++ src/hb-aat-layout-morx-table.hh | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index 6d9c10ffb..9bba40323 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -49,6 +49,17 @@ struct ankr; using hb_aat_class_cache_t = hb_ot_layout_mapping_cache_t; +/* The state-machine 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 in the hottest loop of AAT + * shaping. Forcing them inline is worth 3-10% instructions on + * morx/kerx-heavy fonts, for about 16KB of code. */ +#ifndef HB_OPTIMIZE_SIZE +#define HB_AAT_TRANSITION_INLINE HB_ALWAYS_INLINE +#else +#define HB_AAT_TRANSITION_INLINE +#endif + struct hb_aat_scratch_t { hb_aat_scratch_t () = default; diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index db7cd6f54..5d5b2e173 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -258,6 +258,7 @@ struct KerxSubTableFormat1 depth (0), crossStream (table->header.coverage & table->header.CrossStream) {} + HB_AAT_TRANSITION_INLINE void transition (hb_buffer_t *buffer, StateTableDriver *driver, const Entry &entry) @@ -551,6 +552,7 @@ struct KerxSubTableFormat4 mark_set (false), mark (0) {} + HB_AAT_TRANSITION_INLINE void transition (hb_buffer_t *buffer, StateTableDriver *driver, const Entry &entry) diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 4811f12be..aa6081131 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -84,6 +84,7 @@ struct RearrangementSubtable table (table_), start (0), end (0) {} + HB_AAT_TRANSITION_INLINE void transition (hb_buffer_t *buffer, StateTableDriver *driver, const Entry &entry) @@ -243,6 +244,7 @@ struct ContextualSubtable mark (0), subs (table+table->substitutionTables) {} + HB_AAT_TRANSITION_INLINE void transition (hb_buffer_t *buffer, StateTableDriver *driver, const Entry &entry) @@ -490,6 +492,7 @@ struct LigatureSubtable ligature (table+table->ligature), match_length (0) {} + HB_AAT_TRANSITION_INLINE void transition (hb_buffer_t *buffer, StateTableDriver *driver, const Entry &entry) @@ -787,6 +790,7 @@ struct InsertionSubtable mark (0), insertionAction (table+table->insertionAction) {} + HB_AAT_TRANSITION_INLINE void transition (hb_buffer_t *buffer, StateTableDriver *driver, const Entry &entry)