Skip to content

perf(analysis): Must Be Covered By looks each point up in an index of the polygons' boxes (#1252) - #1928

Merged
pick2510 merged 1 commit into
opengeos:mainfrom
pick2510:perf/topology-not-covered-index
Nov 13, 2026
Merged

pick2510 merged 1 commit into
opengeos:mainfrom
pick2510:perf/topology-not-covered-index

Conversation

@pick2510

@pick2510 pick2510 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1252 (its "Ready" item 1, the no threads track).

The topology check Must Be Covered By (topology::not_covered) tested each point against every polygon of the covering layer, so its time grew with points × polygons. Each point is now looked up in an ExtentIndex of the polygons' boxes, the grid the overlay tools and Summarize Within already use, and only the polygons whose boxes may hold it are tested. The test for each candidate is unchanged, and so is the pole handling.

Measured

98,596 square parcels and random points around Zurich, release build, one thread:

Points Before After
10,000 1.51 s 0.11 s
100,000 14.48 s 0.17 s

The same points are reported before and after (same count and the same rows, compared by a hash of them).

Changes

  • crates/analysis/src/topology.rs: not_covered builds the index once and asks it per point (any_candidate).
  • crates/analysis/src/tools.rs: ExtentIndex, its new and any_candidate are pub(crate).
  • New test not_covered_finds_the_same_points_through_its_index: 100 polygons, so the grid is used. It checks a point inside a polygon, on a shared edge, on a shared corner, on the outer corner, in a gap, and east and west of all of them. Points on a boundary stay reported, as the guide says.

No change to the output, the docs or the saved files.

Summary by CodeRabbit

  • Improvements
    • Geometry coverage checks now more efficiently identify candidate polygons while preserving handling of shared boundaries, gaps, and points outside the covered area.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

ExtentIndex and its constructor and candidate lookup method are now visible across the crate. not_covered builds an index from covering polygon bounds and checks candidate polygons while retaining containment and polar-surround checks. A test covers points inside polygons, on shared boundaries, in gaps, and outside the indexed extent.

Changes: Coverage lookup

Layer / File(s) Summary
Index and coverage check
crates/analysis/src/tools.rs, crates/analysis/src/topology.rs
ExtentIndex, ExtentIndex::new, and ExtentIndex::any_candidate are now crate-visible. not_covered uses the index to select candidate polygons and retains the existing containment and polar-surround checks. A test checks results for 100 polygons and seven points.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related issues

  • opengeos/RustGIS#1252 — The issue describes the full scan in topology::not_covered and proposes indexing polygon extents, which this change implements.

Suggested reviewers: giswqs, flight1973

Merge Risk: Minimal · up to f618e

This change speeds up the Must Be Covered By check by looking up candidate polygons through an index. The checks that decide whether a point is covered are unchanged, and the reported results match the previous output. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: Must Be Covered By now looks up each point in an index of the polygons' boxes, which matches the topology::not_covered change. It also names the perf scope and the is…
Description check Passed The description follows the template's main sections: Summary, Testing, and Related issue. The Summary explains the change, the performance problem, and the new index lookup. Testing gives benchmark n…
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: Title check

Explanation

The title states the main change: Must Be Covered By now looks up each point in an index of the polygons' boxes, which matches the topology::not_covered change. It also names the perf scope and the issue number. The title is long (97 characters), but it is specific and accurate.

Full details: Description check

Explanation

The description follows the template's main sections: Summary, Testing, and Related issue. The Summary explains the change, the performance problem, and the new index lookup. Testing gives benchmark numbers and a new test. The UI evidence section is absent, but the change has no visible UI effect, and the description does not say so in that section. The Related issue section references #1252 only in the opening line, not in the template's section.

Resolution

Optionally, add the 'No visible UI change.' line under a '## UI evidence' heading and move the '#1252' reference into a '## Related issue' section to match the template exactly.

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 checks the bounds with care,
Finds candidate shapes waiting there.
Across shared edges, through every gap,
The indexed path avoids the full-map lap.
Then hops away, its checks complete.

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: eeb50f06-ccb4-46fd-bbde-efffde14ae6e
Commits

Reviewing files that changed from the base of the PR and between d3d9405 and f618eee.

Files selected for processing: 2

  • crates/analysis/src/tools.rs
  • crates/analysis/src/topology.rs

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

pub fn not_covered(ds: &Dataset, rows: &[usize], by: &Dataset) -> Checked {
let all: Vec<usize> = (0..by.features.len()).collect();
let polys = polygons(by, &all);
let index = crate::tools::ExtentIndex::new(polys.iter().map(|(_, _, bb)| Extent::new(bb.min().x, bb.min().y, bb.max().x, bb.max().y)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Possible performance gap (medium confidence, not a correctness issue). ExtentIndex::new drops the grid and falls back to a linear scan of every polygon once the cell references exceed MAX_REFERENCES (1,000,000, tools.rs around line 6405). The grid is capped at 256 × 256 cells, so a covering layer with many polygons that each span several cells (for example 100k irregular administrative polygons over a national extent) can cross that cap. Then not_covered is back to points × polygons, with no notice and no change in output. The 98k small parcels in the PR's measurement stay under the cap, so the benchmark doesn't exercise this path.

Suggestion: add a test with a covering layer large enough to hit the cap (or a unit assertion that ExtentIndex::new keeps a grid for this shape), or note the fallback in the doc comment of not_covered so the speed-up is not overstated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed here. Past MAX_REFERENCES the index has no grid and every polygon is a candidate, which is exactly the scan this check did before, so such a layer is no slower than on main and the output is the same either way; the cap is what keeps the grid's memory bounded. It is the same fallback every other ExtentIndex user (Clip, the overlays, Summarize Within, Spatial Join, Near) has, so a different strategy for very large polygons (a coarser grid, or an R-tree) belongs in a change to the index itself rather than in this check.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs: None found. I checked the index against the old test. The grid only ever returns a superset of the polygons whose boxes hold the point, and the per-candidate test is unchanged. Pole handling runs before the index, as before. Non-finite and NaN boxes fall back to the same test, or to a linear scan, so nothing is missed.

Security: None found. No new input parsing, no unwrap/expect/unsafe, and the index lookups use get().

Performance:

  • Medium confidence: ExtentIndex::new falls back to a linear scan over all polygons once the grid would hold more than 1,000,000 cell references. The grid is capped at 256 × 256, so a covering layer with many multi-cell polygons can hit that cap and lose the speed-up, with no notice. The PR's 98k small parcels stay under the cap. Posted as an inline comment on topology.rs:1066.
  • Low confidence, nit: any_candidate creates a HashSet per point on the grid path. Measured timings make this immaterial.

Quality:

  • Nit: topology.rs now reaches into tools::ExtentIndex, a private helper in the tools module. Moving it to its own module would make the dependency clearer. Left for the release quality pass.
  • Nit: the new test's expected output relies on exact floating-point equality between computed grid edges (e.g. 8.0 + 2 × 0.1) and literal points. I checked the main cases by hand and they round the same way, so I'm not raising it as a defect.

AGENTS.md: Compliant. The changed lines stay within the rustfmt width of 140 as far as I can count. The new test covers both boundary and interior points, and the pub(crate) changes stay inside the crate. The change does not touch the cancel or background paths.

Prior reviews: No existing threads, so no concerns were skipped.

Change size

Compared with main (merge base d3d9405 to PR head f618eee): the whole PR, not just the latest push.

Measure Value
Files changed 2 (0 added, 2 modified, 0 removed, 0 renamed)
Size before 898.6 KB
Size after 900.6 KB
Total size change +2.0 KB
Path Before After Change
crates/analysis/src/topology.rs 82.5 KB 84.5 KB +2.0 KB
crates/analysis/src/tools.rs 816.6 KB 816.6 KB +33 B

@pick2510
pick2510 enabled auto-merge (squash) November 13, 2026 08:15
@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-1928/
Web app https://preview.rustgis.app/pr-1928/app/
Commit f618eee

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

@pick2510
pick2510 merged commit 25eedca into opengeos:main Nov 13, 2026
18 checks passed
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