Skip to content

Reduce validation and collection allocations - #574

Open
runceel wants to merge 5 commits into
mainfrom
runceel-dotnet-11-performance
Open

runceel wants to merge 5 commits into
mainfrom
runceel-dotnet-11-performance

Conversation

@runceel

@runceel runceel commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Relates to #569.

Changes

  • Reuse R3 validator snapshots under the existing registration lock and avoid rebuilding unchanged errors, while checking the published aggregate for mutation.
  • Index R3 range-removal items directly and reuse fixed-name R3 property-change arguments.
  • Replace Core validation LINQ intermediates with a single ordered pass.
  • Recover and extend the earlier regression tests; preserve all target frameworks.

Deferred

The Core and Legacy property-path DynamicInvoke rewrite remains open: a compatibility-safe replacement must preserve reflection argument conversion, value-type behavior, accessor failures, and TargetInvocationException wrapping. Neither implementation was benchmarked here. This PR does not complete the issue. Core validation's eight-validator all-failure case was tested but not benchmarked.

Measurements

BenchmarkDotNet 0.15.8 ShortRun, Windows 11 Arm64 (Snapdragon X), .NET 11.0.0, Release; one launch, 3 warmups/3 iterations, sequential separate baseline and candidate runs. Dry runs preceded measurement. The normal BDN toolchain did not recognize .NET 11; all results use the in-process toolchain. Error is the 99.9% confidence-interval half-width. These are microbenchmarks, not application-level speedups; wide intervals and the in-process setup limit timing conclusions.

Scenario Before mean ± error; allocated After mean ± error; allocated
R3 validation, 1 validator, unchanged success 79.37 ± 7.08 ns; 144 B 41.77 ± 73.54 ns; 0 B
R3 validation, 8 validators, unchanged success 1,415 ± 1,093 ns; 984 B 257 ± 235 ns; 0 B
R3 validation, 1 validator, unchanged error 108.5 ± 18.0 ns; 208 B 64.6 ± 31.0 ns; 32 B
R3 validation, 8 validators, unchanged errors 1,629 ± 463 ns; 1,944 B 841 ± 47 ns; 256 B
R3 validation, 1 validator, alternating 114 ± 69 ns; 176 B 129 ± 132 ns; 136 B
R3 validation, 8 validators, alternating 1,642 ± 318 ns; 1,548 B 1,807 ± 324 ns; 1,396 B
R3 filtered collection, remove and restore 256 items 261.7 ± 41.5 µs; 152.78 KB 152.4 ± 35.4 µs; 132.78 KB
R3 collection replacement with notification subscriber 140.8 ± 16.4 ns; 488 B 153.0 ± 49.4 ns; 440 B
Core validation, 0 validators 23.22 ± 12.97 ns; 80 B 1.34 ± 0.27 ns; 0 B
Core validation, 1 successful validator 47.27 ± 3.14 ns; 184 B 2.62 ± 5.80 ns; 0 B
Core validation, 1 failing validator 64.08 ± 12.02 ns; 216 B 34.96 ± 0.78 ns; 120 B
Core validation, 8 successful validators 71.96 ± 42.09 ns; 184 B 16.96 ± 1.05 ns; 0 B
Core validation, 8 validators, mixed errors 170.04 ± 68.57 ns; 240 B 84.50 ± 101.45 ns; 144 B

Alternating R3 errors and collection replacement do not show a reliable timing improvement; their allocation reductions are measured. Core low-nanosecond results should be treated cautiously due to in-process optimization and measurement noise.

Verification

  • dotnet test ReactiveProperty.slnx -c Release --no-restore -m:1 passed all .NET 10 and .NET 11 test legs on Windows.
  • dotnet build ReactiveProperty.slnx -c Release --no-restore -m:1 passed including netstandard2.0 and net472 targets; existing warnings remain.
  • An initial parallel full-suite run timed out in the existing 10-second large-collection performance test; the serialized full-suite retry passed.
  • The three original R3 commits and their ignored build artifacts were inspected read-only. The old validation benchmark source was adapted in a session-local harness; no old checkouts were modified.

kaota_microsoft and others added 5 commits November 17, 2026 16:33
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@runceel

runceel commented Nov 17, 2026

Copy link
Copy Markdown
Owner Author

Reproducible benchmark source, project settings, original result tables, and run instructions: https://gist.github.com/runceel/0798793e06ba86c46bd347bfc1f0e202. The result file records the incremental commit revisions and the in-process ShortRun limitations.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants