Predicate benchmarks + two rounds of implementation optimization guided by dotnet-trace profiling#11
Merged
MichaConrad merged 3 commits intomainfrom Feb 23, 2026
Conversation
…ntations Co-authored-by: MichaCo <5837539+MichaCo@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add benchmarking for Optimizing PredicatesAdaptive and PredicatesExact
Add PredicatesBenchmarks and optimize Orient2d/InCircle implementations
Feb 22, 2026
…eExpansion, ExactInCircle Co-authored-by: MichaCo <5837539+MichaCo@users.noreply.github.com>
Copilot
AI
changed the title
Add PredicatesBenchmarks and optimize Orient2d/InCircle implementations
Predicate benchmarks + two rounds of implementation optimization guided by dotnet-trace profiling
Feb 22, 2026
SummarySummary
CoverageCDT.Core - 85%
|
MichaConrad
approved these changes
Feb 23, 2026
There was a problem hiding this comment.
Pull request overview
This pull request adds comprehensive benchmarks for geometric predicates and applies two rounds of profiler-guided performance optimizations to the predicate implementation. The optimizations target the expensive expansion arithmetic used in exact geometric predicates, achieving significant speedups (10-51%) without changing any mathematical algorithms.
Changes:
- Added
PredicatesBenchmarksclass covering all 8 predicate method variants (Orient2d/InCircle × double/float × general/near-degenerate cases) - Applied micro-optimizations including
[SkipLocalsInit], aggressive inlining, SIMD vectorization, tiered stackalloc, and bounds-check elimination using unsafe code - Eliminated unnecessary temporary stack allocations in
PredicatesExact.InCirclethrough in-place negation
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| benchmark/CDT.Benchmarks/PredicatesBenchmarks.cs | Adds comprehensive benchmark suite with 16 benchmark methods covering all predicate variants, plus helper methods for generating test data |
| src/CDT.Core/Predicates/PredicatesExact.cs | Adds optimization attributes and eliminates 1536 bytes of stack allocation per InCircle call via in-place negation |
| src/CDT.Core/Predicates/PredicatesAdaptive.cs | Extensive optimization: SIMD vectorization in Estimate/NegateInto, tiered stackalloc in ExpansionSum, bounds-check elimination throughout, and Split function inlining |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
PredicatesBenchmarksclass and applies two rounds of implementation-level optimizations toPredicatesAdaptiveandPredicatesExact. No mathematical algorithms were changed.Benchmarks
PredicatesBenchmarkscovers all 8 method variants:Orient2d/InCircle×double/float× general-position (Stage A fast path) × near-degenerate (forces full expansion path). UsesShortRun,MemoryDiagnoser, andEventPipeProfiler.Round 1 — static hotspot analysis
[SkipLocalsInit]onExpansionSum,ScaleExpansionSum,PredicatesExact.InCircle,PredicatesExact.Orient2d,PredicatesAdaptive.InCircle[AggressiveInlining]onTwoTwoDiffSplitintoMultTailandDekkersPresplitValueTuple<double,double>allocations perTwoTwoDiffcallVector256<double>) inEstimateandNegateIntoRound 2 —
dotnet-traceprofilingTop hotspots from
dotnet-trace collect(76 284 events, inclusive call-time):ExpansionSumUnsafe.Add;Unsafe.CopyBlockUnalignedfor tail copies and the elen/flen=0 fast paths;[AggressiveOptimization]ScaleExpansionSum[SkipLocalsInit]retained;AggressiveInliningdeliberately withheld — see regression note belowSpanHelpers.MemmoveSpan.CopyToinExpansionSumfast pathsScaleExpansion[AggressiveInlining | AggressiveOptimization],[SkipLocalsInit], bounds-check-free loopTwoTwoDiff[SkipLocalsInit]PredicatesExact.InCirclestackbdetPos[96]+ddetPos[96](saves 1 536 B per call);[AggressiveOptimization]PredicatesExact.Orient2dcallsite[AggressiveInlining]allows inlining intoAdaptiveOrient2dStage DRegression caught during R2: adding
[AggressiveInlining]toScaleExpansionSumcaused it to inline 3× intoAdaptiveInCircle, each copy cascading into 4 inlinedScaleExpansioncalls — 12 total. This bloated the JIT frame, polluted the instruction cache, and regressedAdaptive InCircle doubleby +52% even for Stage-A calls that never touch expansion code. Removed the hint; full recovery confirmed.Results (N = 4 000 calls/iteration, .NET 10, AVX2)
decimal, not expansion arithmetic)💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.