Skip to content

PlanarTriangulation: reusable ISweepLineCache for the sweep-line triangulation - #6750

Draft
Grantim wants to merge 1 commit into
masterfrom
sweep-line-cache-2
Draft

PlanarTriangulation: reusable ISweepLineCache for the sweep-line triangulation#6750
Grantim wants to merge 1 commit into
masterfrom
sweep-line-cache-2

Conversation

@Grantim

@Grantim Grantim commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Re-derivation of #6542 on top of current master: the interim mesh-space plan path (#6555, #6739), the region-copy sweep init (#6584) and the HolesVertIds removal (#6745) rebuilt this area, so the cache was re-implemented from scratch against today's code rather than rebased.

What it does

SweepLineQueue keeps every buffer it grows during a run (patch topology, projected points, winding info, sweep/event/monotonation scratch, the initMeshByLoops_ maps that carried a // TODO: can be cached) in a SweepLineQueue::Cache, referenced by the queue instead of owned. A caller triangulating many contour sets one by one can carry one cache across calls:

  • PlanarTriangulation::ISweepLineCache (abstract) + makeSweepLineCache();
  • optional cache argument on triangulateDisjointContours (2d/2f and mesh-space) and fillContours2DPlan;
  • triangulateDisjointContoursTopology( mesh, loops, normal, outPatchMap, cache ) (MR_BIND_IGNORE): the plan path needs only connectivity, so it triangulates into the cache without materializing a Mesh — the result lives in the cache until its next run;
  • HoleFillPlanner holds one cache per worker, so getPlanarHoleFillPlans reuses buffers across all holes a worker processes, and releases the grown per-worker planners in a parallel pass instead of the serial ETS destructor;
  • MeshTopology::clear() — capacity-keeping reset used by the cache between runs.

Behavior is unchanged: with no cache argument every entry point works on a local cache exactly as before. Plans are bit-identical to master (FNV fingerprint of getPlanarHoleFillPlans + getPlanarHoleFillPlan over 3000 mixed 4-16-vert holes: 5aef970cd4fa279e on both builds), and the boolean/hole-fill/planar-triangulation gtest subset passes identically on both.

Measurements

Release x64, same exe per side, interleaved runs, medians:

workload master this PR
getPlanarHoleFillPlans, 2000 × 16-vert holes 1.477 ms 1.267 ms (−14%)
serial getPlanarHoleFillPlan × 2000, 16-vert holes 23.05 ms 21.45 ms (−7%)
boolean of two 3366-vert spheres (no holes ≥ 14 verts, cache idle) 14.32 ms 14.10 ms

On workloads whose holes stay below cMinSweptHoleSize the cache is never engaged and timings are unchanged.

Replaces #6542.

🤖 Generated with Claude Code

…ngulation

SweepLineQueue now keeps all its buffers in a Cache that a caller can carry
between runs via the optional cache argument of triangulateDisjointContours
and fillContours2DPlan, so batch hole planning does not reallocate them per
hole; HoleFillPlanner holds one cache per worker. The plan path triangulates
into the cache without materializing a Mesh (triangulateDisjointContoursTopology).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant