Skip to content

perf(analysis): Intersect, Identity, Union and Symmetrical Difference work on several cores (#1252) - #1740

Merged
pick2510 merged 1 commit into
opengeos:mainfrom
pick2510:perf/overlay-on-cores
Nov 10, 2026
Merged

pick2510 merged 1 commit into
opengeos:mainfrom
pick2510:perf/overlay-on-cores

Conversation

@pick2510

@pick2510 pick2510 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

#1252 step 2, first part: the overlay tools (Intersect, Identity, Union, Symmetrical Difference) work on several cores. The polar-geometry stack that blocked them (#1347, #1348, #1349) merged on 7 November.

Measured in a release build on a Xeon Silver 4114 (40 threads), with 100,000 input polygons against 20,000 overlay polygons (64-vertex circles, overlapping):

Tool 1 thread 16 threads (the default limit)
Intersect 2.36 s 0.29 s
Identity 4.09 s 0.58 s
Union 4.39 s 0.66 s
Symmetrical Difference 4.48 s 0.60 s

How

Each of the overlay's three steps runs item by item on parallel::try_map_on, and the output rows are made in order on the calling thread, as before:

  • Overlay zones (overlay_zones): a feature of several parts is a union. Erase, Update and Split share this step, so their zones are made on several cores too.
  • Each input feature's cut by the zones it meets: its part in each zone, and its part outside them all. For Symmetrical Difference only the zone's index is kept, not the part, since that tool drops it.
  • For Union and Symmetrical Difference, each zone's part outside the input polygons that cover it.

The cut, the masks and the differences are the same code as before. It only moved into the closures.

The #1252 rules hold:

  • the output is the same as on one thread, bit for bit;
  • one thread below the usual threshold of features (PARALLEL_FEATURES) and in the browser;
  • the thread count comes from rustgis_data::threads;
  • Cancel is looked at, and progress counted, item by item.

Tests

overlay_on_several_threads_is_overlay_on_one runs all four tools on 1, 2, 7 and 16 threads and compares every row's geometry and attributes. Its data covers 600 input polygons against 200 overlay polygons, overlay features of two overlapping parts, and input features without geometry. The existing overlay, Erase, Update and Split tests pass unchanged.

No visible UI change.

Summary by CodeRabbit

  • Performance
    • Overlay operations—including Intersect, Identity, Union, and Symmetrical Difference—now process features and zones in parallel, which can reduce processing time.
    • Results remain in input order, preserving consistent output ordering across single-threaded and multi-threaded processing.

… work on several cores (opengeos#1252)

opengeos#1252 step 2, the overlay tools. Each of their three steps works item by item on
`parallel::try_map_on`, and the output rows are made in order on the calling thread, so the
output is the same as on one thread, bit for bit:

- the overlay zones (a feature of several parts is a union), in `overlay_zones`, which Erase,
  Update and Split share;
- each input feature's cut by the zones it meets (its part in each and its part outside them);
- for Union and Symmetrical Difference, each zone's part outside the input polygons covering it.

Cancel is looked at, and progress counted, item by item as before; one thread in the browser and
below the usual threshold of features.
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Overlay zone construction, feature cutting, and Union and Symmetrical Difference remainder calculations now use parallel mapping with an optional thread limit. Results remain in input order. A test compares outputs across single-thread and multi-thread runs.

Changes: Parallel Overlay Processing

Layer / File(s) Summary
Parallel zone construction
crates/analysis/src/tools.rs
Zone construction accepts an optional thread limit and uses parallel mapping. The collected zones retain input order.
Parallel overlay operations
crates/analysis/src/tools.rs
Feature cuts run in parallel, and Union and Symmetrical Difference compute zone remainders in parallel. Output assembly retains input order. Tests compare feature counts, geometries, and attributes across thread counts.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Possibly related issues

Possibly related PRs

  • opengeos/RustGIS#982: Adds Identity and Union, which this PR processes in parallel.
  • opengeos/RustGIS#980: Adds Intersect, whose feature cutting and zone construction this PR parallelizes.
  • opengeos/RustGIS#1103: Adds Symmetrical Difference, whose feature cutting and remainder processing this PR parallelizes.

Suggested reviewers: giswqs

Merge Risk: Minimal · up to 91641

The change parallelizes overlay tools while keeping output order deterministic, and a test compares results across thread counts. No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly identifies the four overlay tools and their parallel execution across multiple cores.
Description check Passed The description explains the change, reports testing and benchmark results, states that there is no visible UI change, and references issue #1252. It covers the template’s required information, althou…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the change, reports testing and benchmark results, states that there is no visible UI change, and references issue #1252. It covers the template’s required information, although it does not use all of the template’s section headings.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 0 files. (1 skipped: 1 too large.)

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit watches polygons run,
In ordered rows, their work is done.
Zones take turns? No, threads now race,
Yet outputs keep their rightful place.
Four overlay paths hop along,
While matching results prove them strong.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 572032f1-ed35-40ab-9b43-369c9276c7fe
Commits

Reviewing files that changed from the base of the PR and between bc603c0 and 91641d9.

Files selected for processing: 1

  • crates/analysis/src/tools.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Comment thread crates/analysis/src/tools.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the diff against the surrounding code in crates/analysis/src/tools.rs, parallel.rs and control.rs. I found no bugs, crash paths, silent data loss or AGENTS.md violations. I could not compile or run the tests (no shell here), so the claimed bit-for-bit equality rests on reading, not on a run.

Bugs: none found. The parallel closures are pure over shared read-only data, and the serial pass preserves row order. try_map_on returns results in input order, and cuts lines up with input_rows. Symmetrical Difference still records covering and drops the inside piece, as before. Missing features and geometry take the same paths as before.

Security: none. No input handling changed; all lookups use get().

Performance: no issues beyond a low-confidence question (about 20%). Overlay workers use threads_for without a scratch budget, so a few very large features could multiply peak memory by the thread count. Other vector tools such as geodesic buffers do the same, so this may be intended.

Quality (nits, for the release quality pass):

  • tools.rs:1925-1930: op.keeps_inside() now runs inside the parallel closure and is passed through an Option flag. The local let cut = … also shadows the cut() function. I posted this as an inline comment.
  • The closure threads_for shares its name with crate::parallel::threads_for.

AGENTS.md: compliant as far as I can tell. The work uses try_map_on, the thread count comes from threads_for, Cancel is checked per item, progress is counted, and wasm gets one thread. The Intersect, Identity, Union and Symmetrical Difference entries are already in the cancellation test list, so no new registry entry is needed.

Already raised: none. prior-reviews.json has no threads, so I left no earlier concerns alone.

Change size

Compared with the base branch: the whole PR against main (merge base 2d47925 to PR head 91641d9).

Measure Value
Files changed 1 (added 0, modified 1, removed 0, renamed 0)
Size before 702.8 KB
Size after 706.9 KB
Total size change +4.2 KB
Path Before After Change
crates/analysis/src/tools.rs 702.8 KB 706.9 KB +4.2 KB

@pick2510
pick2510 merged commit 5a26547 into opengeos:main Nov 10, 2026
18 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-1740/
Web app https://preview.rustgis.app/pr-1740/app/
Commit 91641d9

GitHub Pages takes a minute or two to publish a new commit.

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