Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance regression in @turf/union from v7.1.0 to v7.2.0 #2851

Open
neave opened this issue Mar 7, 2025 · 1 comment
Open

Performance regression in @turf/union from v7.1.0 to v7.2.0 #2851

neave opened this issue Mar 7, 2025 · 1 comment

Comments

@neave
Copy link

neave commented Mar 7, 2025

There is a significant performance regression in the @turf/union module when upgrading from version 7.1.0 to 7.2.0. Union operations are more than 10 times slower in 7.2.0.

Reproduction Steps

  1. Create a test file (e.g., test-union.js) with the following content:
import { circle } from '@turf/circle';
import { featureCollection } from '@turf/helpers';
import { union } from '@turf/union';

const circles = [];
for (let i = 0; i < 1000; i++) {
  circles.push(circle([i * 0.1, 0], 200));
}

console.time('union');
union(featureCollection(circles));
console.timeEnd('union');
  1. Install Dependencies with v7.1.0:
    npm install @turf/circle @turf/helpers @turf/[email protected]
    Run the test file:
    node test-union.js
    Observe the timing output (around 500 ms).

  2. Upgrade to version 7.2.0:
    npm install @turf/[email protected]
    Run the test file again:
    node test-union.js
    Note the increased timing output (around 5.5 s).

Expected Behavior:
The union operation should complete in a similar timeframe across these minor versions (around 500 ms for the provided test).

Observed Behavior:
• v7.1.0: ~500 ms
• v7.2.0: ~5.5 s

This performance degradation is critical, especially for workflows involving large numbers of geometries.

Environment:
• Node.js version: 22
• OS: macOS, Ubuntu

Additional Context:
This slowdown might be due to changes in the union implementation or dependencies in v7.2.0. Any investigation or fixes to address this regression would be greatly appreciated.

@kade-robertson
Copy link

Just looking to confirm that this is due to the change to polyclip-ts. Running the bechmarks from that repo (modified to also include the old polygon-clipping library), polyclip-ts is pretty much always behind by an order of magnitude, if not worse.

Hole_Hole
polyclip-ts x 1,327 ops/sec ±0.47% (96 runs sampled)
w8r x 69,672 ops/sec ±0.30% (98 runs sampled)
JSTS x 7,563 ops/sec ±0.75% (98 runs sampled)
polygon-clipping x 21,782 ops/sec ±0.22% (99 runs sampled)
- Fastest is w8r

Asia union
polyclip-ts x 2.37 ops/sec ±1.13% (10 runs sampled)
w8r x 19.85 ops/sec ±1.99% (37 runs sampled)
JSTS x 27.36 ops/sec ±1.24% (49 runs sampled)
polygon-clipping x 14.31 ops/sec ±2.57% (40 runs sampled)
- Fastest is JSTS

States clip
polyclip-ts x 30.90 ops/sec ±1.03% (55 runs sampled)
w8r x 422 ops/sec ±0.28% (94 runs sampled)
JSTS x 336 ops/sec ±0.63% (90 runs sampled)
polygon-clipping x 333 ops/sec ±0.45% (90 runs sampled)
- Fastest is w8r

Based on what I can see on that repo, it's implied their results are at least the most correct, at least compared to the library its based on, but the drop in performance to achieve this (if it is the case) seems really unfortunate.

Fortunately, the turf methods that use this are relatively thin wrappers around the underlying library, so duplicating the old 7.1 version (or just installing it separately) is pretty doable (ignoring the negative effect on bundle size that might have if that matters for your use case)

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

No branches or pull requests

2 participants