From 8e3e8c66e1f58b72b535ca4525e7228592df3c52 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 15 Sep 2025 19:49:11 -0600 Subject: [PATCH 1/2] [iup] Reuse more allocations --- src/hb-ot-var-common.hh | 10 ++++++---- src/hb-ot-var-cvar-table.hh | 3 ++- src/hb-ot-var-gvar-table.hh | 3 ++- src/test-tuple-varstore.cc | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index f53d81450..630512010 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -1216,9 +1216,9 @@ struct TupleVariationData return true; } - bool iup_optimize (const contour_point_vector_t& contour_points) + bool iup_optimize (const contour_point_vector_t& contour_points, + optimize_scratch_t &scratch) { - optimize_scratch_t scratch; for (tuple_delta_t& var : tuple_vars) { if (!var.optimize (contour_points, is_composite, scratch)) @@ -1230,6 +1230,7 @@ struct TupleVariationData public: bool instantiate (const hb_hashmap_t& normalized_axes_location, const hb_hashmap_t& axes_triple_distances, + optimize_scratch_t &scratch, contour_point_vector_t* contour_points = nullptr, bool optimize = false) { @@ -1251,7 +1252,7 @@ struct TupleVariationData if (!merge_tuple_variations (optimize ? contour_points : nullptr)) return false; - if (optimize && !iup_optimize (*contour_points)) return false; + if (optimize && !iup_optimize (*contour_points, scratch)) return false; return !tuple_vars.in_error (); } @@ -1685,8 +1686,9 @@ struct item_variations_t bool instantiate_tuple_vars (const hb_hashmap_t& normalized_axes_location, const hb_hashmap_t& axes_triple_distances) { + optimize_scratch_t scratch; for (tuple_variations_t& tuple_vars : vars) - if (!tuple_vars.instantiate (normalized_axes_location, axes_triple_distances)) + if (!tuple_vars.instantiate (normalized_axes_location, axes_triple_distances, scratch)) return false; if (!build_region_list ()) return false; diff --git a/src/hb-ot-var-cvar-table.hh b/src/hb-ot-var-cvar-table.hh index f8ae0c803..c013f10e3 100644 --- a/src/hb-ot-var-cvar-table.hh +++ b/src/hb-ot-var-cvar-table.hh @@ -158,7 +158,8 @@ struct cvar tuple_variations)) return_trace (false); - if (!tuple_variations.instantiate (c->plan->axes_location, c->plan->axes_triple_distances)) + optimize_scratch_t scratch; + if (!tuple_variations.instantiate (c->plan->axes_location, c->plan->axes_triple_distances, scratch)) return_trace (false); if (!tuple_variations.compile_bytes (c->plan->axes_index_map, c->plan->axes_old_index_tag_map, diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index 730ac7fa8..0562ba471 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -140,6 +140,7 @@ struct glyph_variations_t { unsigned count = plan->new_to_old_gid_list.length; bool iup_optimize = false; + optimize_scratch_t scratch; iup_optimize = plan->flags & HB_SUBSET_FLAGS_OPTIMIZE_IUP_DELTAS; for (unsigned i = 0; i < count; i++) { @@ -147,7 +148,7 @@ struct glyph_variations_t contour_point_vector_t *all_points; if (!plan->new_gid_contour_points_map.has (new_gid, &all_points)) return false; - if (!glyph_variations[i].instantiate (plan->axes_location, plan->axes_triple_distances, all_points, iup_optimize)) + if (!glyph_variations[i].instantiate (plan->axes_location, plan->axes_triple_distances, scratch, all_points, iup_optimize)) return false; } return true; diff --git a/src/test-tuple-varstore.cc b/src/test-tuple-varstore.cc index cef04ab7e..640607f52 100644 --- a/src/test-tuple-varstore.cc +++ b/src/test-tuple-varstore.cc @@ -97,7 +97,8 @@ test_decompile_cvar () hb_hashmap_t axes_triple_distances; axes_triple_distances.set (axis_tag, TripleDistances (1.0, 1.0)); - tuple_variations.instantiate (normalized_axes_location, axes_triple_distances); + OT::optimize_scratch_t scratch; + tuple_variations.instantiate (normalized_axes_location, axes_triple_distances, scratch); hb_always_assert (tuple_variations.tuple_vars[0].indices.length == 65); hb_always_assert (tuple_variations.tuple_vars[1].indices.length == 65); From c56ef9ed8914d4f5e13353181d6d0d6456cf2de5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 15 Sep 2025 20:10:54 -0600 Subject: [PATCH 2/2] [instancer] Reuse more allocations These allocs are scratched. Don't free them, so we reuse. --- src/hb-ot-var-common.hh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index 630512010..fc72ef152 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -745,15 +745,11 @@ struct tuple_delta_t if (opt_point_data.length + opt_deltas_data.length < point_data.length + deltas_data.length) { - indices.fini (); indices = std::move (opt_indices); if (is_comp_glyph_wo_deltas) { - deltas_x.fini (); deltas_x = std::move (opt_deltas_x); - - deltas_y.fini (); deltas_y = std::move (opt_deltas_y); } } @@ -1100,7 +1096,6 @@ struct TupleVariationData for (unsigned i = 0; i < out.length; i++) new_vars.push (std::move (out[i])); } - tuple_vars.fini (); tuple_vars = std::move (new_vars); } return true;