Conversation
7 tasks
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.
Problem Statement
Every mutation execution allocated
MutationAuditEntryandMutationHistoryEntryobjects unconditionally, even when the registeredIMutationAuditorandIMutationHistoryStoreimplementations discarded them immediately. The factory ran first, allocated, then passed the result to a consumer that ignored it pure waste on every call.Additionally,
CreateHistoryEntrycalledresult.SideEffects.ToList()on every commit mutation, allocating redundant defensive copy of an already-read-only collection.Solution Overview
1. Default Interface Method:
IsEnabledtrue), no source changes requiredNoOpimplementations override tofalse2. Guard OutcomeProcessor Before Factory Calls
MutationAuditEntry,MutationHistoryEntry, and all intermediate allocations when auditor/store is disabledAuditFailureAsyncandStoreInHistoryAsync3. Remove Redundant Defensive Copy
MutationHistoryEntry.SideEffectsalready acceptsIReadOnlyList<SideEffect>, so no additional copy is requiredList<SideEffect>allocation per commit mutationPerformance Impact
Benchmark Results
Optimized Path Analysis
.ToList()defensive copyKey Design Decisions
Why default interface method instead of separate `INoOpAuditor` interface?
Every auditor can explicitly declare whether it consumes audit entries. A separate marker interface would require runtime type checks (
is INoOpAuditor) at the call site and couple the runtime to specific no op implementations. A default interface member keeps the capability part of the existing abstraction and preserves compatibility with existing implementations.Why check in OutcomeProcessor instead of the factory?
The factory job is to create entries. Adding a
bool createparameter would leak infrastructure concerns into the factory. Checking at the call site (OutcomeProcessor) keeps the factory pure and lets the caller decide the same pattern used throughout the pipeline for policy evaluation and interception.Why not pass raw data to the auditor and let it create the entry?
That would require new method on
IMutationAuditor(breaking change) and couple the audit entry schema to the interface. The current approach keeps the existing factory and audit entry schema while avoiding any breaking API changes.Why not remove factory calls at the engine level?
The engine doesn't know which auditor/store implementation is registered. Only the OutcomeProcessor, which holds the concrete references, can make the decision. Centralizing the check there avoids leaking implementation awareness upward.
Files Changed
IMutationAuditor.cs
bool IsEnabled => true;— default interface methodIMutationHistoryStore.cs
bool IsEnabled => true;— default interface methodMutationExecutionOutcomeProcessor.cs
AuditSuccessAsync/AuditFailureAsyncwithif (!_auditor.IsEnabled) return;StoreInHistoryAsyncwithif (!_historyStore.IsEnabled) return;MutationAuditEntryFactory.cs
result.SideEffects.ToList()withresult.SideEffectsNoOpAuditor.cs / NoOpHistoryStore.cs
bool IsEnabled => false;overrideMigration
Note
No migration steps required.
IsEnabledis additive with defaulttrue. ExistingIMutationAuditorandIMutationHistoryStoreimplementations continue to work without modification. Implementations that do not consume entries (such asNoOpAuditor) can override the property tofalseto enable the allocation free fast path.