Skip to content

Improve intersection performance - #33

Merged
nikku merged 3 commits into
mainfrom
perf/intersection-speedup
Sep 21, 2026
Merged

nikku merged 3 commits into
mainfrom
perf/intersection-speedup

Conversation

@nikku

@nikku nikku commented Sep 20, 2026

Copy link
Copy Markdown
Member

Proposed Changes

Speeds up path intersection computation without changing results (verified bit-identical output against main across 500 randomized path pairs):

  • Precompute bezier segments + bounding boxes once per path instead of re-walking path2 and recomputing bounding boxes per segment pair
  • Skip non-overlapping segment pairs via cheap bounding box precheck before expensive subdivision
  • Compute arc rotation directly instead of per-call caching (cache was rebuilt on every call)
  • Push results instead of repeated concat()

Measured on 60-segment mixed paths: ~25% faster overall, ~57% faster on arc-heavy paths.

Try out:

npm ci && npm run all

Checklist

Ensure you provide everything we need to review your contribution:

  • Contribution meets our definition of done
  • Pull request establishes context
    • Link to related issue(s), i.e. Closes {LINK_TO_ISSUE} or Related to {LINK_TO_ISSUE}
    • Brief textual description of the changes
    • Screenshots or short videos showing UI/UX changes
    • Steps to try out, i.e. using the @bpmn-io/sr tool

nikku and others added 3 commits September 20, 2026 20:27
Walk each path once, extracting bezier segments with their bounding
boxes, instead of re-walking path2 and recomputing every bezier
bounding box for each segment pair.

Non-overlapping segment pairs are now skipped via a cheap bounding
box check before the expensive subdivision-based intersection.

Also push results instead of repeatedly concat()-ing arrays.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The rotate helper inside arcToCurve was wrapped in a cacher whose
cache was rebuilt on every arcToCurve invocation, caching at most a
handful of lookups while paying string key joins on each call.

Replace it with a plain closure over precomputed sin/cos and drop
the now unused cacher machinery.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Guards the bounding box precheck that skips non-overlapping segment
pairs: intersections must be found exactly where segments overlap,
no more, no less.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@nikku
nikku requested review from a team and a lite review from Copilot September 20, 2026 18:31
@bpmn-io-tasks bpmn-io-tasks Bot added the needs review Review pending label Sep 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Consolidate the duplicate bounding-box intersection check in intersect.js.

Review effort: Lite
Findings: None

What changed in this PR

Improves path intersection performance while preserving output by reducing repeated geometry calculations.

Changes:

  • Precomputes Bézier segments and bounding boxes.
  • Adds bounding-box filtering and more efficient result collection.
  • Simplifies arc rotation calculations and adds regression coverage.
File Summary
test/​intersect.spec.js Adds regression coverage for disjoint segment bounding boxes.
intersect.js Implements intersection performance optimizations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@nikku
nikku merged commit 3dc33f4 into main Sep 21, 2026
5 checks passed
@bpmn-io-tasks bpmn-io-tasks Bot removed the needs review Review pending label Sep 21, 2026
@nikku
nikku deleted the perf/intersection-speedup branch September 21, 2026 09:13
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.

3 participants