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-berian-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()
  • ValidationResultSuccess() returns cached singleton
  • MutationMetrics cached Empty singleton, shared empty dictionary
  • ChangeSet cached Empty singleton
  • SideEffect.ResolveContractConcurrentDictionary cache eliminates repeated reflection
  • MutationHistoryEntry / MutationAuditEntry converted from class to readonly record struct zero allocation per materialization
  • MutationHistoryFirstMutationAt/LastMutationAt fixed for struct FirstOrDefault()

Benchmark Results

BenchmarkBeforeAfterΔ TimeΔ Alloc
Success_NoSideEffects88.25 ns / 528 B18.61 ns / 0 B−79%−100%
Success_SingleSideEffect280.39 ns / 792 B18.72 ns / 0 B−93%−100%
Success_MultipleSideEffects899.22 ns / 1960 B18.79 ns / 0 B−98%−100%
HistoryEntry_Materialization688.7 ns / 896 B23.40 ns / 0 B−97%−100%
AuditEntry_Materialization666.0 ns / 848 B24.47 ns / 0 B−96%−100%

Closes#94

@github-actionsgithub-actionsBot added the performance Performance improvements or regressions label Jul 28, 2026
@github-actionsgithub-actionsBot 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 mainJul 28, 2026
28 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

abstractionsPublic abstractions and contractsbenchmarkBenchmark coverage and performance measurement changesperformancePerformance improvements or regressionsruntimeRuntime implementation and execution flowtestsTest 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

@rian-be