Skip to content

perf(geom): lazily index face triangles and memoize smooth_seam in tangent_chain - #27083

Open
AXKore wants to merge 1 commit into
tangency-labs:mainfrom
AXKore:perf/r2-geom-tangent-chain-face-index
Open

AXKore wants to merge 1 commit into
tangency-labs:mainfrom
AXKore:perf/r2-geom-tangent-chain-face-index

Conversation

@AXKore

@AXKore AXKore commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Change

Eliminates O(L * T) full-mesh triangle scans in Mesh::tangent_chain / smooth_seam by building a lazy per-face triangle index (FaceTriIndex) only on the first unflagged edge fallback and memoizing per-edge results in seam_cache. Preserves bit-identical ascending triangle order and adds zero overhead when sharp_edges / smooth_edges decide directly.

Closes #27082
Changes a default: no

Benchmark (--release)

bench_tangent_chain_g1_unflagged_scaling (F=500, T=50,000, L=300, 10 iters, checksum 3000):

Variant Time Speedup
Before 1334.504 ms —
After 24.408 ms 54.67x faster (-98.2%)

Verification

  • tangent_chain_ (2/2 passed)
  • clippy -p solidcraft-geom --lib --tests -- -D warnings clean

Summary by CodeRabbit

  • Performance
    • Improved tangent-chain searches on larger meshes, reducing repeated work and helping results return more efficiently.
  • Tests
    • Added coverage for tangent-chain results across varied mesh configurations, including sparse face IDs and empty or overridden edge settings.
    • Added an ignored benchmark for measuring performance on larger meshes.

@coderabbitai

coderabbitai Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

tangent_chain now lazily indexes triangles by face and caches seam results for candidate edges. Regression tests compare indexed traversal with a reference scan across varied mesh cases. An ignored benchmark exercises a larger chain and seam-branch configuration.

Changes: Tangent chain seam lookup

Layer / File(s) Summary
Indexed seam lookup
crates/geom/src/mesh.rs
FaceTriIndex groups triangle IDs by face and supports dense or sparse storage. smooth_seam uses the index when provided and retains the scan path when no index is supplied.
Chain caching and regression coverage
crates/geom/src/mesh.rs, crates/geom/src/tests.rs
tangent_chain shares a lazy index and caches candidate-edge seam results. Tests compare traversal with a reference implementation and add an ignored scaling benchmark.

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

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 34f5d

This change speeds up tangent-chain seam lookups by indexing triangles per face and caching per-edge results, and it keeps the previous behavior. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title names the main change: lazy per-face triangle indexing and memoized smooth_seam in tangent_chain. It matches the raw summary (FaceTriIndex, seam cache) and the objectives (issue #27082). It …
Description check Passed The description follows the template's main sections (Change, Validation) and gives a clear technical summary, a benchmark table, and verification results. It links issue #27082 and includes the requi…
Linked Issues check Passed [#27082] The issue asks to remove the O(L * T) full-mesh triangle scans in the tangent_chain smooth_seam fallback on G1/unflagged edges. The whole-PR diff of crates/geom/src/mesh.rs (merge base …
Out of Scope Changes check Passed All changes in the whole-PR diff relate to the linked issue. The mesh.rs changes add the lazy index, the seam cache, the indexed lookup path, and the None argument at the tangent_join call site.…
Existing Defaults Unchanged Passed The check fails only if the PR changes a UX default (default setting or preference, usual command or tool behavior, UI default layout or behavior, or shortcuts). Kernel or geometry results are exclude…
Full details: Title check

Explanation

The title names the main change: lazy per-face triangle indexing and memoized smooth_seam in tangent_chain. It matches the raw summary (FaceTriIndex, seam cache) and the objectives (issue #27082). It uses the perf(geom) prefix and is 80 characters, which fits the concise title standard.

Full details: Description check

Explanation

The description follows the template's main sections (Change, Validation) and gives a clear technical summary, a benchmark table, and verification results. It links issue #27082 and includes the required 'Changes a default: no' line. It does not include the template's 'Test change' line, but the PR does not change existing test expectations, so that line is not needed. The Screenshots section is missing. The Integration status section is also missing. Screenshots are not required for this kernel-level performance change with no observable UI behavior. The Change section does not explain the feature in plain words for a newcomer, and it does not describe the user-visible effect. The description is mostly complete, so the check passes.

Full details: Linked Issues check

Explanation

[#27082] The issue asks to remove the O(L * T) full-mesh triangle scans in the tangent_chain smooth_seam fallback on G1/unflagged edges. The whole-PR diff of crates/geom/src/mesh.rs (merge base 46ce128 to head 34f5de2) implements this. (1) FaceTriIndex is added. It maps each face to its triangle IDs in ascending order, using a dense offset layout or a sparse HashMap fallback. (2) tangent_chain creates face_tris: Option<FaceTriIndex> as None and passes Some(&mut face_tris) to smooth_seam. The index is built only on the first fallback, through get_or_insert_with. (3) seam_cache: Vec<Option<bool>> memoizes each candidate edge's smooth_seam result within the chain walk. (4) normal_near uses the index when present and keeps the original linear scan when absent, so tangent_join keeps its prior behavior. Sharp and smooth flags still decide before the fallback, so no index is built for those edges. The tests in crates/geom/src/tests.rs add a reference-comparison regression test and an ignored scaling benchmark. The benchmark reports 1334.504 ms before and 24.408 ms after. This evidence is from the PR summary and the diff. I did not rerun the benchmark or tests.

Full details: Out of Scope Changes check

Explanation

All changes in the whole-PR diff relate to the linked issue. The mesh.rs changes add the lazy index, the seam cache, the indexed lookup path, and the None argument at the tangent_join call site. The tests.rs changes add a regression test for tangent_chain and a scaling benchmark for the same path. The PR description states that the change is not a default change. No unrelated refactoring or feature change appears in the reviewed evidence.

Full details: Existing Defaults Unchanged

Explanation

The check fails only if the PR changes a UX default (default setting or preference, usual command or tool behavior, UI default layout or behavior, or shortcuts). Kernel or geometry results are excluded. Evidence from the reviewed range (refs/coderabbit/pre-merge-check/base to head): - Changed files: crates/geom/src/mesh.rs (modified) and crates/geom/src/tests.rs (modified). No other files changed. - mesh.rs changes are internal performance work. tangent_join and tangent_chain pass a new optional FaceTriIndex argument to smooth_seam. tangent_chain adds a per-edge seam_cache so each candidate edge is evaluated once. The new FaceTriIndex keeps ascending triangle order, and callers without an index keep the original linear-scan path. - No settings, preferences, UI, shortcuts, or command-line defaults appear in the diff. The public API signatures are not changed. - The PR description states Changes a default: no, which matches the diff. The change affects only geometry computation speed. The stated behavior is unchanged (bit-identical ordering). Even if results were affected, the check excludes kernel or geometry results from "changed default". No UX default is changed, so the check passes.

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2ff98ab and 34f5de2.

Files selected for processing: 2

  • crates/geom/src/mesh.rs
  • crates/geom/src/tests.rs

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

@tangency-repo-manager tangency-repo-manager Bot added the approved-for-ci Reviewed: run the full PR CI (build, tests, goldens, Clippy) label Dec 6, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved-for-ci Reviewed: run the full PR CI (build, tests, goldens, Clippy) area:kernel B-rep kernel, booleans, blends, STEP/IGES

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(geom): eliminate O(L * T) full-mesh triangle scans in tangent_chain smooth_seam fallback

1 participant