Skip to content

Avoid call stack overflow on deeply nested splits - #216

Open
EpicDima wants to merge 1 commit into
mapbox:mainfrom
EpicDima:epicdima/nested-split-stack
Open

EpicDima wants to merge 1 commit into
mapbox:mainfrom
EpicDima:epicdima/nested-split-stack

Conversation

@EpicDima

@EpicDima EpicDima commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #215.

With this PR nested splits no longer recurse. The outermost split keeps the pending halves on an explicit stack and
triangulates them in a loop. Halves come off it in the same depth-first order as before, so the output is the same, in
the same order. earcut() and earcutLinked are unchanged, and the new code runs only after a split diagonal has
been found.

main this PR
example from the issue, 32,768 vertices RangeError same triangles as main with --stack-size=7000
bench/bench-tiles.js, median of 6 runs 363 ms 363.5 ms

The output is also identical to main's on the test fixtures, all polygons of bench/tiles-fixture.bin and about
228,000 random polygons. The new test runs in a worker with a 0.35 MB stack, so that it overflows on main quickly and
reliably.

@EpicDima
EpicDima requested a review from a team as a code owner October 9, 2026 11:07
@EpicDima
EpicDima requested review from stepankuzmin and removed request for a team October 9, 2026 11:07

This branch has not been deployed

No deployments
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.

RangeError: Maximum call stack size exceeded on deeply nested splits

1 participant