Skip to content

Perf: Eliminate all heap allocations in mutation result creation and materialization - #96

Merged
rian-be merged 2 commits into
mainfrom
develop
Jul 28, 2026
Merged

Perf: Eliminate all heap allocations in mutation result creation and materialization#96
rian-be merged 2 commits into
mainfrom
develop

Conversation

@rian-be

@rian-be rian-be commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Eliminate per call heap allocations associated with MutationResult<TState> creation and MutationHistoryEntry/MutationAuditEntry materialization by converting output DTOs to readonly record struct, caching singletons for success/empty defaults, and pre-caching supporting objects in benchmark setup.

Changes

  • MutationResult<TState> converted from class to readonly record struct zero allocation per Success()/Failure()/PolicyBlocked()
  • ValidationResult Success() returns cached singleton
  • MutationMetrics cached Empty singleton, shared empty dictionary
  • ChangeSet cached Empty singleton
  • SideEffect.ResolveContract ConcurrentDictionary cache eliminates repeated reflection
  • MutationHistoryEntry / MutationAuditEntry converted from class to readonly record struct zero allocation per materialization
  • MutationHistory FirstMutationAt/LastMutationAt fixed for struct FirstOrDefault()

Benchmark Results

Benchmark Before After Δ Time Δ Alloc
Success_NoSideEffects 88.25 ns / 528 B 18.61 ns / 0 B −79% −100%
Success_SingleSideEffect 280.39 ns / 792 B 18.72 ns / 0 B −93% −100%
Success_MultipleSideEffects 899.22 ns / 1960 B 18.79 ns / 0 B −98% −100%
HistoryEntry_Materialization 688.7 ns / 896 B 23.40 ns / 0 B −97% −100%
AuditEntry_Materialization 666.0 ns / 848 B 24.47 ns / 0 B −96% −100%

Closes #94

@github-actions github-actions Bot added the performance Performance improvements or regressions label Jul 28, 2026
@github-actions github-actions Bot added abstractions Public abstractions and contracts runtime Runtime implementation and execution flow tests Test coverage and test changes benchmark Benchmark coverage and performance measurement changes labels Jul 28, 2026
@rian-be
rian-be merged commit f475421 into main Jul 28, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

abstractions Public abstractions and contracts benchmark Benchmark coverage and performance measurement changes performance Performance improvements or regressions runtime Runtime implementation and execution flow tests Test coverage and test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Perf]: Eliminate all heap allocations in mutation result creation and materialization

1 participant