From b68989768daa9db1610f109d5423c89f6bae76b8 Mon Sep 17 00:00:00 2001 From: Panos <25664832+mechpanos@users.noreply.github.com> Date: Tue, 8 Sep 2026 13:08:35 +0300 Subject: [PATCH] perf: look the draw depth up only where it is used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `arena-post partition=55.2ms blocks=5.9ms curves=2.5ms` — the partition is the whole of the 73 ms an arena patch spends after patching, and it runs on every drawn point over the entire resident set. Inside it, `wire_draw_depth` is a hash lookup whose result feeds only the analytical circle and ellipse extraction, and it was computed before the test that decides whether either will run. So every patch paid 236 956 lookups to serve the ~56 000 wires that are circles or ellipses. Moving it inside that branch is behaviour-preserving: the value was unused on every path that skipped it. This does not make the partition incremental — it still walks the resident set for a one-entity change — but that walk is memory-bound and a structural fix needs the cached partition to survive a patch, which the borrows in `PartitionedWires` make its own piece of work. Co-Authored-By: Claude Opus 5 --- src/scene/pipeline/wire_arena.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/scene/pipeline/wire_arena.rs b/src/scene/pipeline/wire_arena.rs index bbaddb773..954e2fd8e 100644 --- a/src/scene/pipeline/wire_arena.rs +++ b/src/scene/pipeline/wire_arena.rs @@ -199,12 +199,16 @@ pub fn partition_wires<'a>( instanced.push(wire); continue; } - let depth = super::wire_gpu::wire_draw_depth(wire, depth_map); + // `wire_draw_depth` is a hash lookup and its result is used only by the + // analytical extractions below, which most wires never reach. Computing + // it first cost one lookup per resident wire on every patch — 236 956 + // of them for the ~56 000 that are circles or ellipses. if !wire.tangent_geoms.is_empty() && wire.fill_tris.is_empty() && wire.pick_tris.is_empty() && wire.text_verts.is_empty() { + let depth = super::wire_gpu::wire_draw_depth(wire, depth_map); if let Some(insts) = super::circle_gpu::extract_circle_instances(wire, depth) { circle_instances.extend(insts); continue;