Skip to content

perf(boolean-intersects): delegate flattening to booleanDisjoint#3103

Merged
mfedderly merged 2 commits into
Turfjs:masterfrom
rexxars:perf/intersects-disjoint-delegate
Jul 22, 2026
Merged

perf(boolean-intersects): delegate flattening to booleanDisjoint#3103
mfedderly merged 2 commits into
Turfjs:masterfrom
rexxars:perf/intersects-disjoint-delegate

Conversation

@rexxars

@rexxars rexxars commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

booleanIntersects flattens both features into every pair of simple geometries and calls booleanDisjoint per pair. But booleanDisjoint performs the exact same nested flattenEach internally, with the inverse accumulation ("all pairs disjoint" vs "any pair intersects"). Since intersects == !disjoint holds for multi-geometries too, the entire body can be reduced to:

return !booleanDisjoint(feature1, feature2, { ignoreSelfIntersections });

This is the same category of #3011 - deduplicating/delegating to what the negated variant does, and reducing maintenance surface. I also removed @turf/meta and @turf/helpers from the package's dependencies since nothing in the package imports them anymore (helpers was unused even before this change). Let's see if CI complains.

Benchmarks show a marked improvement on my M4 MacBook Pro:

Fixture Before After Change
Point-Point 9.67M 19.27M +99%
Point-LineString-1 8.68M 16.51M +90%
LineString-Point-2 8.65M 16.92M +96%
MultiPoint-Point 4.73M 9.46M +100%
MultiPoint-MultiPoint 2.62M 5.75M +120%
Point-Polygon 6.53M 10.38M +59%
LineString-In-Polygon 7.03M 11.97M +70%
LineString-LineString 1.14M 1.23M +8%
Polygon-Polygon 0.84M 0.91M +8%
Polygon-MultiPolygon 409K 419K +3%

Please provide the following when creating a PR:

  • Meaningful title, including the name of the package being modified.
  • Summary of the changes.
  • Heads up if this is a breaking change.
  • Any issues this resolves.
  • Inclusion of your details in the contributors field of package.json - you've earned it! 👏
  • Confirmation you've read the steps for preparing a pull request.

…Disjoint`

`booleanDisjoint` already compares every flattened geometry pair internally.
I also removed @turf/meta and @turf/helpers from the package's dependencies
since nothing in the package imports them anymore (helpers was unused even
before this change).

Benchmarks show between +50% and +100% improvement in speed on MacBook M4 Pro.
@rexxars
rexxars force-pushed the perf/intersects-disjoint-delegate branch from 8765bc6 to ed121a1 Compare July 21, 2026 22:47

@mfedderly mfedderly left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you!

@mfedderly mfedderly added this to the v7.4 milestone Jul 22, 2026
@mfedderly
mfedderly merged commit 104f994 into Turfjs:master Jul 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants