[repacker] Only charge node duplication to the graph work budget Charging every overflow-resolution iteration its V+L against a budget of 256 * (V+L) would make a real font that needs more than ~256 iterations fail to repack, though HB_REPACKER_MAX_ITERATIONS (500) allows it. Iterations are already capped, so drop the per-iteration charge and keep only the duplication charge in graph_t::duplicate(), which bounds the links the graph can grow to (the vertex limit does not). Each pass's work is then bounded by the grown graph times the iteration cap. The always_recalculate_extensions retry reuses the same graph, clones included, so not re-arming the budget there is consistent: it counts links that are still in the graph. test_work_budget still exhausts the budget and expects both duplicate() and hb_resolve_graph_overflows() (which must duplicate to succeed) to return LIMIT_EXCEEDED. Full meson test: 278 OK. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
diff --git a/src/graph/graph.hh b/src/graph/graph.hh index 3fcadb2..7120858 100644 --- a/src/graph/graph.hh +++ b/src/graph/graph.hh
@@ -1756,7 +1756,7 @@ } /* - * Charges vertices and links that are about to be walked or added + * Charges vertices and links that are about to be added * against the work budget of this graph. */ graph_result_t<void> charge_ops (size_t ops)
diff --git a/src/hb-limits.hh b/src/hb-limits.hh index c65457f..7afc2b5 100644 --- a/src/hb-limits.hh +++ b/src/hb-limits.hh
@@ -282,11 +282,11 @@ #endif /* Work budget of one repacker graph, per vertex and link it starts out - * with. Each overflow-resolution pass walks every vertex and link, and an - * isolating pass does not count as a round, so the limits on iterations and - * vertices bound neither their product nor the number of links, which node - * duplication copies freely. Sized like HB_SANITIZE_MAX_OPS, proportional - * to the input with a floor. */ + * with, charged by node duplication. HB_REPACKER_MAX_VERTICES does not + * bound the number of links, which duplication copies freely, and every + * overflow-resolution pass (at most HB_REPACKER_MAX_ITERATIONS) walks all + * of them. Sized like HB_SANITIZE_MAX_OPS, proportional to the input with + * a floor. */ #ifndef HB_BUDGET_REPACKER_FACTOR #define HB_BUDGET_REPACKER_FACTOR 256 #endif
diff --git a/src/hb-repacker.hh b/src/hb-repacker.hh index 598256c..e3eda74 100644 --- a/src/hb-repacker.hh +++ b/src/hb-repacker.hh
@@ -420,9 +420,6 @@ hb_vector_t<graph::overflow_record_t> overflows; // TODO(garretrieger): select a good limit for max rounds. while (round < max_rounds && total_iterations < HB_REPACKER_MAX_ITERATIONS) { - // Each iteration checks every link for overflow and re-sorts the whole graph. - TRY (sorted_graph.charge_ops (sorted_graph.total_vertices_and_links ())); - TRY_ASSIGN (bool overflows_exist, graph::will_overflow (sorted_graph, &overflows)); if (!overflows_exist) break;