Skip to content

Replace HashSet.Contains with bool[] in RemoveTriangles#10

Merged
MichaConrad merged 5 commits intomainfrom
copilot/optimize-kdtree-node-data
Feb 22, 2026
Merged

Replace HashSet.Contains with bool[] in RemoveTriangles#10
MichaConrad merged 5 commits intomainfrom
copilot/optimize-kdtree-node-data

Conversation

Copy link
Contributor

Copilot AI commented Feb 22, 2026

RemoveTriangles called HashSet<int>.Contains up to 5 times per triangle across three loops (mapping, compaction, neighbor remap). For ~5 200 triangles that's ~26 000 hash lookups — hash computation + bucket chase on every call.

Change

Build a bool[] isRemoved from the HashSet once up front, then use direct indexed reads everywhere:

var isRemoved = new bool[_trianglesCount];
foreach (int i in removed) isRemoved[i] = true;
// all subsequent removed.Contains(i) → isRemoved[i]

Benchmark delta (Sweden dataset, ShortRun)

Benchmark Before After Δ
EraseSuperTriangle – Auto 2.142 ms 1.934 ms −9.7%
EraseOuterTriangles – Auto 2.470 ms 2.308 ms −6.6%
Full pipeline – Auto 2.636 ms 2.561 ms −2.8%
All others within noise

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 22, 2026 21:51
… stack, eliminate layer allocs, bool[] in RemoveTriangles, hoist fixed-edge check)

Co-authored-by: MichaCo <5837539+MichaCo@users.noreply.github.com>
Co-authored-by: MichaCo <5837539+MichaCo@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace KdTree node data with InlineArray struct 5 targeted allocations/hot-path optimizations in KdTree and Triangulation Feb 22, 2026
Copilot AI requested a review from MichaConrad February 22, 2026 22:12
Copilot AI and others added 2 commits February 22, 2026 22:44
Co-authored-by: MichaCo <5837539+MichaCo@users.noreply.github.com>
Co-authored-by: MichaCo <5837539+MichaCo@users.noreply.github.com>
Copilot AI changed the title 5 targeted allocations/hot-path optimizations in KdTree and Triangulation Replace HashSet.Contains with bool[] in RemoveTriangles Feb 22, 2026
@MichaConrad MichaConrad marked this pull request as ready for review February 22, 2026 22:51
@github-actions
Copy link

Summary

Summary
Generated on: 2/22/2026 - 10:52:36 PM
Coverage date: 2/22/2026 - 10:52:33 PM
Parser: Cobertura
Assemblies: 1
Classes: 17
Files: 7
Line coverage: 85.1% (1269 of 1490)
Covered lines: 1269
Uncovered lines: 221
Coverable lines: 1490
Total lines: 3731
Branch coverage: 80.1% (619 of 772)
Covered branches: 619
Total branches: 772
Method coverage: Feature is only available for sponsors
Tag: 61_22287058099

Coverage

CDT.Core - 85.1%
Name Line Branch
CDT.Core 85.1% 80.1%
CDT.Box2d`1 73.6% 100%
CDT.CdtUtils 83.1% 72.8%
CDT.CovariantReadOnlyDictionary`3 18.1% 50%
CDT.DictionaryExtensions 100% 100%
CDT.DuplicatesInfo 100%
CDT.DuplicateVertexException 66.6%
CDT.Edge 75% 66.6%
CDT.IntersectingConstraintsException 0%
CDT.KdTree`1 72.7% 65%
CDT.LayerDepth 0%
CDT.Predicates.PredicatesAdaptive 97.6% 91.5%
CDT.Predicates.PredicatesExact 33.7% 100%
CDT.TopologyVerifier 77.2% 63.8%
CDT.Triangle 66.6% 71.4%
CDT.Triangulation`1 93.8% 84.1%
CDT.TriangulationException 100%
CDT.V2d`1 44.4% 25%

@MichaConrad MichaConrad merged commit b3b5a99 into main Feb 22, 2026
3 checks passed
@MichaConrad MichaConrad deleted the copilot/optimize-kdtree-node-data branch February 22, 2026 22:54
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.

2 participants