Skip to content

perf(modeling): skip distant hole containment tests - #1500

Open
snowyukitty wants to merge 1 commit into
jscad:masterfrom
snowyukitty:perf/skip-distant-hole-tests
Open

snowyukitty wants to merge 1 commit into
jscad:masterfrom
snowyukitty:perf/skip-distant-hole-tests

Conversation

@snowyukitty

Copy link
Copy Markdown

Related to #1428.

assignHoles currently runs the polygon crossings test for every solid/hole pair, including distant outlines. Cache each solid's minimum X and Y range, then reject representative hole points outside those bounds before calling the existing predicate. The hierarchy, point order and nested-parent selection stay unchanged, and the single-solid case avoids computing bounds.

The right X bound is deliberately omitted: the existing crossings calculation can round an intersection past that bound. Keeping the original test there preserves its current floating-point behavior. This remains a quadratic pair traversal; it reduces expensive polygon tests rather than introducing a spatial index.

Add hierarchy coverage for separated outlines, concave overlapping bounds, single-solid holes and empty/no-hole inputs, plus a standalone benchmark with hierarchy and analytic-volume checks.

Linux x86-64 / Node 22.23.1, median milliseconds across seven alternating pairs of fresh Node processes (each process reports a warmed median):

Rings / layout Hole assignment, before -> after Complete extrusion, before -> after
1 / row 0.042 -> 0.042 0.222 -> 0.223
32 / grid 1.378 -> 1.268 6.742 -> 6.507
128 / grid 8.653 -> 6.155 36.330 -> 30.791
512 / row 85.197 -> 64.577 272.570 -> 229.022
512 / grid 78.119 -> 41.698 248.902 -> 183.003

Reproduce on either revision using the same benchmark file:

node packages/modeling/benchmarks/assignHoles.js 512 grid

These are synthetic, non-overlapping 32-segment rings; timing depends on geometry and runtime. Independent compatibility probes compared complete hierarchies on 158 cases, including boundaries at several scales, and complete extrusion polygon arrays on eight fixtures. All matched the unmodified base. On the 512-ring grid, polygon-containment calls fell from 262144 to 6093.

Validation:

  • Root native test command npm test -- --concurrency 1 -- --concurrency 2 passes all 23 package scripts on Node 20 and 22: 817 AVA tests pass, with the same two existing skipped web tests. The concurrency options cap Lerna and AVA workers.

  • npm run test:tsd, modeling build, and StandardX on the three changed files pass.

  • Rebuilt UMD modeling bundle produces exactly the same polygons and serialized ASCII STL as source for a multi-outline extrusion; its analytic volume also passes.

  • Root npm run lint still fails: the candidate and untouched base have the same 367 existing diagnostics, with no new diagnostics.

  • Followed the contributing guide.

  • Checked open PRs and issue-linked work for overlap.

  • Tests pass; generated build files are excluded.

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