Repository navigation
perf(analysis): Must Be Covered By looks each point up in an index of the polygons' boxes (#1252) - #1928
Conversation
… the polygons' boxes (opengeos#1252)
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| 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))); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Code reviewBugs: 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 Performance:
Quality:
AGENTS.md: Compliant. The changed lines stay within the Prior reviews: No existing threads, so no concerns were skipped. Change sizeCompared with main (merge base d3d9405 to PR head f618eee): the whole PR, not just the latest push.
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. |
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 anExtentIndexof 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:
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_coveredbuilds the index once and asks it per point (any_candidate).crates/analysis/src/tools.rs:ExtentIndex, itsnewandany_candidatearepub(crate).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