From 73e9d5f054ccfc0379d7d28f80b97952db0ce8ca Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 9 Nov 2026 18:36:35 -0600 Subject: [PATCH] Revert "[shape-plan] Cache the last shape plan looked up per face (#6550)" (#6618) This reverts commit 708d59a50. The one-entry per-face cache doesn't help the common case: with a single plan per face, the plan is already the first node of the list. When shaping alternates between keys on one face (LTR and RTL, two scripts, different features), every call misses the slot. That costs an extra key.equal() before the list walk, then a write to the slot. From several threads, that write bounces the face's cache line between them on almost every call. This is the same problem as the hb_language_from_string() cache from #6549, which is also being reverted. A long-lived face with many plans walks the uncapped plan list by design. If that becomes a real problem, it should be fixed in the list itself, not with a slot in front of it. hb_atomic_t::set_release(), added in #6549 for these caches, stays. Testing: meson test -C build: 278 OK. Co-authored-by: Claude Opus 5.5 --- src/hb-face.hh | 4 ---- src/hb-shape-plan.cc | 9 --------- 2 files changed, 13 deletions(-) diff --git a/src/hb-face.hh b/src/hb-face.hh index baa1a2e57..77c243721 100644 --- a/src/hb-face.hh +++ b/src/hb-face.hh @@ -71,10 +71,6 @@ struct hb_face_t }; #ifndef HB_NO_SHAPER hb_atomic_t shape_plans; - /* One-entry cache of the last plan looked up, so repeated shaping with the - * same key hits without walking the list. Nodes are never freed before the - * face, so a cached pointer stays valid. */ - hb_atomic_t last_shape_plan; #endif hb_blob_t *reference_table (hb_tag_t tag) const diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index e6a79f9b2..8f5287918 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -567,18 +567,10 @@ retry: shaper_list)) return hb_shape_plan_get_empty (); - hb_face_t::plan_node_t *cached = face->last_shape_plan.get_acquire (); - if (cached && cached->shape_plan->key.equal (&key)) - { - DEBUG_MSG_FUNC (SHAPE_PLAN, cached->shape_plan, "fulfilled from last-plan cache"); - return hb_shape_plan_reference (cached->shape_plan); - } - for (hb_face_t::plan_node_t *node = cached_plan_nodes; node; node = node->next) if (node->shape_plan->key.equal (&key)) { DEBUG_MSG_FUNC (SHAPE_PLAN, node->shape_plan, "fulfilled from cache"); - face->last_shape_plan.set_release (node); return hb_shape_plan_reference (node->shape_plan); } } @@ -605,7 +597,6 @@ retry: goto retry; } DEBUG_MSG_FUNC (SHAPE_PLAN, shape_plan, "inserted into cache"); - face->last_shape_plan.set_release (node); return hb_shape_plan_reference (shape_plan); }