Repository navigation
Region build: test candidate pairs once in their lowest shared cell - #2436
Conversation
The region build kept a SipHash HashSet of tested pairs over a SipHash HashMap grid. Each pair is now tested only in the lowest grid cell both segments occupy, and the grid is a flat Vec. The pairs tested, the visit and distinct-pair budgets and the output are unchanged; the old search is kept as a test oracle. Closes storytold#2430 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Bounded deterministic pair search crates/geom/src/region.rs |
The search replaces the hash-based grid and pair deduplication with flat-grid traversal. It tests pairs in their lowest shared cell and returns None when either budget is exceeded. Randomized tests compare results with the former search. |
Builder integration and graph validation crates/geom/src/region.rs |
build delegates to build_with using the production search. build_with accepts an injected search function. Randomized tests compare graph outputs from the oracle-backed builder and production build. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Refactor
Possibly related issues
- The PR implements the performance proposal to replace hash-based pair tracking with lowest-shared-cell testing, while comparing results against the prior algorithm.
Suggested reviewers: echelon, dylanmtaylor, marekspodbiedry
Merge Risk: 
Minimal · up to 08ea2
-
No identified issue prevents merging after the normal checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title "Region build: test candidate pairs once in their lowest shared cell" matches the main change. The raw summary and PR objectives both describe testing each candidate segment pair once, in the lowest grid cell shared by both segments, inside region::build. The title does not mention the flat Vec grid or the budget changes, but those are secondary to the main change. The title is 67 characters and 11 words, which is longer than ideal but still readable and specific.
Full details: Linked Issues check
-
Explanation
The PR satisfies the coding requirements in [
#2430].pair_splits_limitedremoves the tested-pairHashSet, tests each shared pair in its lowest shared cell, and uses a flatVecgrid. The long-segment path preserves one test per pair. The code preserves visit and distinct-pair budgets. Tests compare sorted split bits with the oracle across 150 seeds and budget sweeps, cover long segments and exhausted budgets, and compare full graph output across 60 drawings.
Full details: Out of Scope Changes check
-
Explanation
The diff is limited to
crates/geom/src/region.rs. The production refactoring, injected search function, oracle, and regression tests directly support [#2430]. No unrelated behavior or files appear in the reviewed changes.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. 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 7 functions across 1 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
Overview of the three independent speedups in
All three keep their results bit-identical to the old code: the old implementation stays as a test-only oracle and tests compare the outputs with Known limits: #2435 only does the band-limited loops; band storage with one factorisation for both right-hand sides is a possible follow-up. The pair-budget exit in the long-segment phase of #2436 is not covered by a test. The full |
austin62jake
left a comment
There was a problem hiding this comment.
Tested on Windows 10 Pro x64 (Rust 1.99.1, cargo-nextest 0.9.150), with this PR merged onto current main (336243e). It merges cleanly, and it works.
- All 113
cadcraft-geomtests pass, including the three that compare the new search with the old one (split lists over the budget sweep, the long-segment path, and the whole graph). cargo xtask cipasses all 7 steps (2622 tests) with this PR merged ontomaintogether with #2434 and #2435, which I tested at the same time, and #2198 so the gate runs on Windows.
Timing on this machine (release build, wall time, three runs each): three region::boundary_at picks in a 55 × 55 grid of separate squares (12,100 segments) take 27.3 ms on main and 22.1 ms with this PR, about 1.2×. My drawing has no lines crossing the squares, so few pairs share more than one cell, and the old HashSet cost less there than in your case with 200 random lines.
On memory: the flat grid is cells * cells lists with cells clamped to 512, so it allocates at most 262,144 empty Vecs (about 6 MB) whatever the input. That's bounded, and the grid.get_mut(gx * cells + gy) access can't go out of range.
FredApps
left a comment
There was a problem hiding this comment.
ReviewerA — source-read COMMENT (not an approval)
I read the first hunk: the region builder is restructured so candidate segment pairs are tested once, in their lowest shared grid cell, instead of in every cell both segments cover (which tests a pair repeatedly), as the title says. That is the standard fix for uniform-grid duplicates. It must give the same set of splits as before; floating-point results can differ in order. I did not read the new code. Add a test that compares the old and new builders on random polylines and on a set with segments crossing several cells (the same splits, compared after sorting), a degenerate zero-length segment, and collinear overlaps. Report timings on a large drawing. Nothing was run.
I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.
Status: waiting_author.
FredApps
left a comment
There was a problem hiding this comment.
Reviewed 08ea23ec2dac90c665f63350fc10cc0e043a91d3. No findings after reviewing the complete region-builder change and its call path. The componentwise maximum of the two lower cell bounds identifies exactly one shared cell; the separate long-segment pass avoids double testing long/long pairs and retains the distinct-pair budget. The randomized split, budget and whole-graph oracle tests are already present. This supersedes my earlier partial review, which asked for existing tests without reading them.
Validation: inspected the hosted gate logs, which checked this head merged into 336243e0 as 16aed82. All seven gate steps passed (fmt, clippy, tests, i18n, assets, layers, wasm), with 2631 tests passed and 1 skipped. The three added oracle comparisons passed, including the long-segment path. CodeRabbit also passed for this head. No local Rust build or benchmark was run.
|
Merged |
What
region::build(HATCH and BOUNDARY picks) remembered which segment pairs it had tested in a SipHashHashSet<(usize, usize)>, over a SipHashHashMapgrid. Now each candidate pair is tested exactly once, in the lowest grid cell both segments occupy (the componentwise maximum of their lowest cells), so no set is needed. The grid is a flatVecindexed by cell.Results do not change:
The old search is kept as a
#[cfg(test)]oracle. New tests compare old and new:pts,adj,src,edge_src) on 60 random drawings.Numbers
Release build,
taskset -c 15,perf stat -e instructions:u, 3 picks on 12k segments (55x55 grid of squares plus 200 random lines). Output hash is identical before and after.Instructions are the reliable number (4.5x fewer); wall times were noisy because other builds were running.
Checks
cargo fmt --check,cargo clippy -p cadcraft-geom --all-targets -- -D warnings,cargo test -p cadcraft-geom(107 passed),cargo xtask layers. Onlycrates/geom/src/region.rschanges.Closes #2430
🤖 Generated with Claude Code
Summary by CodeRabbit