From 59df4309fd2e1314a22794feecf85b6daa55bba5 Mon Sep 17 00:00:00 2001 From: "Rian.be" Date: Sat, 4 Jul 2026 02:05:21 +0200 Subject: [PATCH 1/2] benchmarks: add governed execution orchestration --- ...overnedExecutionOrchestrationBenchmarks.cs | 94 ++++++++++++ .../GovernedExecutionBenchmarkSupport.cs | 136 ++++++++++++++++++ Benchmarks/README.md | 1 + 3 files changed, 231 insertions(+) create mode 100644 Benchmarks/Governance/Execution/GovernedExecutionOrchestrationBenchmarks.cs create mode 100644 Benchmarks/Governance/Execution/Support/GovernedExecutionBenchmarkSupport.cs diff --git a/Benchmarks/Governance/Execution/GovernedExecutionOrchestrationBenchmarks.cs b/Benchmarks/Governance/Execution/GovernedExecutionOrchestrationBenchmarks.cs new file mode 100644 index 0000000..10cb603 --- /dev/null +++ b/Benchmarks/Governance/Execution/GovernedExecutionOrchestrationBenchmarks.cs @@ -0,0 +1,94 @@ +using BenchmarkDotNet.Attributes; +using ModularityKit.Mutator.Governance.Abstractions.Execution.Model; +using ModularityKit.Mutator.Governance.Abstractions.Resolution.Model; +using ModularityKit.Mutator.Governance.Abstractions.Resolution.Strategies; +using ModularityKit.Mutator.Benchmarks.Governance.Execution.Support; + +namespace ModularityKit.Mutator.Benchmarks.Governance.Execution; + +/// +/// Benchmarks governed execution orchestration paths in the governance runtime. +/// +[BenchmarkCategory("Governance")] +[MemoryDiagnoser] +[InProcess] +public class GovernedExecutionOrchestrationBenchmarks +{ + private const string ApprovedRequestId = "governance-execution-approved"; + private const string StaleRequestId = "governance-execution-stale"; + private const string RevalidateRequestId = "governance-execution-revalidate"; + + private GovernedExecutionBenchmarkSupport.GovernedExecutionBenchmarkFixture _approvedFixture = null!; + private GovernedExecutionBenchmarkSupport.GovernedExecutionBenchmarkFixture _staleFixture = null!; + private GovernedExecutionBenchmarkSupport.GovernedExecutionBenchmarkFixture _revalidateFixture = null!; + + /// + /// Prepares fresh fixtures for each benchmark iteration. + /// + [IterationSetup] + public void Setup() + { + _approvedFixture = GovernedExecutionBenchmarkSupport.CreateFixture( + ApprovedRequestId, + currentStateVersion: "v10", + nextStateVersion: "v11"); + + _staleFixture = GovernedExecutionBenchmarkSupport.CreateFixture( + StaleRequestId, + currentStateVersion: "v15", + nextStateVersion: "v16"); + + _revalidateFixture = GovernedExecutionBenchmarkSupport.CreateFixture( + RevalidateRequestId, + currentStateVersion: "v15", + nextStateVersion: "v16"); + } + + /// + /// Measures an approved request executing through governed orchestration with matching state version. + /// + [Benchmark(Baseline = true)] + public async Task ExecuteApproved_MatchingVersion() + { + var result = await _approvedFixture.ExecutionManager.ExecuteApproved( + _approvedFixture.Request.RequestId, + _approvedFixture.Mutation, + _approvedFixture.State, + governanceContext: _approvedFixture.Mutation.Context, + strategy: VersionedRequestResolutionStrategy.RejectStale).ConfigureAwait(false); + + GC.KeepAlive(result); + } + + /// + /// Measures an approved request being rejected as stale before the core engine executes. + /// + [Benchmark] + public async Task ExecuteApproved_RejectStale() + { + var result = await _staleFixture.ExecutionManager.ExecuteApproved( + _staleFixture.Request.RequestId, + _staleFixture.Mutation, + _staleFixture.State, + governanceContext: _staleFixture.Mutation.Context, + strategy: VersionedRequestResolutionStrategy.RejectStale).ConfigureAwait(false); + + GC.KeepAlive(result); + } + + /// + /// Measures an approved request being revalidated against the latest state and then executed. + /// + [Benchmark] + public async Task ExecuteApproved_RevalidateAndExecute() + { + var result = await _revalidateFixture.ExecutionManager.ExecuteApproved( + _revalidateFixture.Request.RequestId, + _revalidateFixture.Mutation, + _revalidateFixture.State, + governanceContext: _revalidateFixture.Mutation.Context, + strategy: VersionedRequestResolutionStrategy.RevalidateOnLatestState).ConfigureAwait(false); + + GC.KeepAlive(result); + } +} diff --git a/Benchmarks/Governance/Execution/Support/GovernedExecutionBenchmarkSupport.cs b/Benchmarks/Governance/Execution/Support/GovernedExecutionBenchmarkSupport.cs new file mode 100644 index 0000000..d1c847d --- /dev/null +++ b/Benchmarks/Governance/Execution/Support/GovernedExecutionBenchmarkSupport.cs @@ -0,0 +1,136 @@ +using ModularityKit.Mutator.Abstractions.Changes; +using ModularityKit.Mutator.Abstractions.Context; +using ModularityKit.Mutator.Abstractions; +using ModularityKit.Mutator.Abstractions.Engine; +using ModularityKit.Mutator.Abstractions.Intent; +using ModularityKit.Mutator.Abstractions.Policies; +using ModularityKit.Mutator.Abstractions.Results; +using ModularityKit.Mutator.Benchmarks.Engine; +using ModularityKit.Mutator.Governance.Abstractions.Execution.Contracts; +using ModularityKit.Mutator.Governance.Abstractions.Lifecycle.Model; +using ModularityKit.Mutator.Governance.Abstractions.Requests.Factory; +using ModularityKit.Mutator.Governance.Abstractions.Requests.Model; +using ModularityKit.Mutator.Governance.Abstractions.Resolution.Strategies; +using ModularityKit.Mutator.Governance.Runtime.Execution.Orchestration; +using ModularityKit.Mutator.Governance.Runtime.Resolution.Execution; +using ModularityKit.Mutator.Governance.Runtime.Storage; + +namespace ModularityKit.Mutator.Benchmarks.Governance.Execution.Support; + +/// +/// Builds repeatable governed execution benchmark fixtures. +/// +internal static class GovernedExecutionBenchmarkSupport +{ + public const string StateId = "governance-benchmark:execution"; + + /// + /// Creates a fresh execution fixture for a single scenario run. + /// + public static GovernedExecutionBenchmarkFixture CreateFixture( + string requestId, + string currentStateVersion, + string nextStateVersion) + { + var engine = MutationEngineBenchmarkSupport.BuildEngine(MutationEngineOptions.Strict); + var store = new InMemoryMutationRequestStore(); + var resolutionManager = new MutationRequestVersionResolutionManager(store, new MutationRequestVersionResolver()); + var executionManager = new GovernanceExecutionManager(store, resolutionManager, engine); + var request = store.Create(CreateApprovedRequest(requestId)) + .GetAwaiter() + .GetResult(); + + return new GovernedExecutionBenchmarkFixture( + ExecutionManager: executionManager, + Request: request, + State: new GovernedExecutionState(StateId, 42, currentStateVersion), + Mutation: new IncrementValueMutation( + MutationContext.User("operator", "Operator", "Execute governed request"), + nextStateVersion)); + } + + /// + /// Creates the approved request used by governed execution benchmarks. + /// + private static MutationRequest CreateApprovedRequest(string requestId) + where TMutation : IMutation + => MutationRequestFactory.Approved( + stateId: StateId, + intent: CreateIntent(), + context: MutationContext.User("requester", "Requester", "Need governed execution"), + expectedStateVersion: "v10") + with + { + RequestId = requestId + }; + + /// + /// Creates the intent used by governed execution scenarios. + /// + private static MutationIntent CreateIntent() + => new() + { + OperationName = "ExecuteGovernedRequest", + Category = "Governance", + Description = "Execute a governed request through orchestration", + RiskLevel = MutationRiskLevel.Low, + IsReversible = true + }; + + /// + /// Minimal versioned state used by governed execution benchmarks. + /// + /// Stable state identifier. + /// Benchmark counter value. + /// Current state version. + internal sealed record GovernedExecutionState(string StateId, int Value, string Version) : IVersionedState; + + /// + /// Minimal mutation used to measure governed execution orchestration. + /// + internal sealed class IncrementValueMutation(MutationContext context, string nextVersion) + : IMutation + { + public MutationIntent Intent { get; } = new() + { + OperationName = "IncrementGovernedValue", + Category = "Governance", + Description = "Increment a governed benchmark value", + RiskLevel = MutationRiskLevel.Low, + IsReversible = true + }; + + public MutationContext Context { get; } = context; + + public MutationResult Apply(GovernedExecutionState state) + { + var next = state with + { + Value = state.Value + 1, + Version = nextVersion + }; + + return MutationResult.Success( + next, + ChangeSet.Single(StateChange.Modified(nameof(GovernedExecutionState.Value), state.Value, next.Value))); + } + + public ValidationResult Validate(GovernedExecutionState state) + { + return state.Value < 0 + ? ValidationResult.WithError(nameof(GovernedExecutionState.Value), "Value must be non-negative.") + : ValidationResult.Success(); + } + + public MutationResult Simulate(GovernedExecutionState state) => Apply(state); + } + + /// + /// Shared execution fixture for a benchmark scenario. + /// + internal sealed record GovernedExecutionBenchmarkFixture( + GovernanceExecutionManager ExecutionManager, + MutationRequest Request, + GovernedExecutionState State, + IncrementValueMutation Mutation); +} diff --git a/Benchmarks/README.md b/Benchmarks/README.md index aea25e4..ef6cc1f 100644 --- a/Benchmarks/README.md +++ b/Benchmarks/README.md @@ -16,6 +16,7 @@ This folder contains BenchmarkDotNet measurements for `ModularityKit.Mutator`. - mutation result creation and history/audit output materialization in the core runtime - governance approval workflow overhead in the governance runtime - governance request lifecycle overhead in the governance runtime +- governance execution orchestration overhead in the governance runtime The throughput benchmarks use cloned array backed state so state size effects remain visible in the actual mutation path rather than being hidden behind an artificial inner loop. From bff6015438373f0ce4fd707f6cee4dfbd5063208 Mon Sep 17 00:00:00 2001 From: "Rian.be" Date: Sat, 4 Jul 2026 02:17:28 +0200 Subject: [PATCH 2/2] benchmarks: add governance version resolution --- .../GovernanceVersionResolutionBenchmarks.cs | 90 +++++++++++++ ...rnanceVersionResolutionBenchmarkSupport.cs | 120 ++++++++++++++++++ Benchmarks/README.md | 1 + 3 files changed, 211 insertions(+) create mode 100644 Benchmarks/Governance/Resolution/GovernanceVersionResolutionBenchmarks.cs create mode 100644 Benchmarks/Governance/Resolution/Support/GovernanceVersionResolutionBenchmarkSupport.cs diff --git a/Benchmarks/Governance/Resolution/GovernanceVersionResolutionBenchmarks.cs b/Benchmarks/Governance/Resolution/GovernanceVersionResolutionBenchmarks.cs new file mode 100644 index 0000000..63af10a --- /dev/null +++ b/Benchmarks/Governance/Resolution/GovernanceVersionResolutionBenchmarks.cs @@ -0,0 +1,90 @@ +using BenchmarkDotNet.Attributes; +using ModularityKit.Mutator.Governance.Abstractions.Resolution.Model; +using ModularityKit.Mutator.Governance.Abstractions.Resolution.Strategies; +using ModularityKit.Mutator.Benchmarks.Governance.Resolution.Support; + +namespace ModularityKit.Mutator.Benchmarks.Governance.Resolution; + +/// +/// Benchmarks governance version resolution paths in the governance runtime. +/// +[BenchmarkCategory("Governance")] +[MemoryDiagnoser] +[InProcess] +public class GovernanceVersionResolutionBenchmarks +{ + private const string MatchingRequestId = "governance-resolution-matching"; + private const string StaleRequestId = "governance-resolution-stale"; + private const string RevalidateRequestId = "governance-resolution-revalidate"; + + private GovernanceVersionResolutionBenchmarkSupport.GovernanceVersionResolutionBenchmarkFixture _matchingFixture = null!; + private GovernanceVersionResolutionBenchmarkSupport.GovernanceVersionResolutionBenchmarkFixture _staleFixture = null!; + private GovernanceVersionResolutionBenchmarkSupport.GovernanceVersionResolutionBenchmarkFixture _revalidateFixture = null!; + + /// + /// Prepares fresh fixtures for each benchmark iteration. + /// + [IterationSetup] + public void Setup() + { + _matchingFixture = GovernanceVersionResolutionBenchmarkSupport.CreateFixture( + MatchingRequestId, + expectedStateVersion: "v10", + currentStateVersion: "v10"); + + _staleFixture = GovernanceVersionResolutionBenchmarkSupport.CreateFixture( + StaleRequestId, + expectedStateVersion: "v10", + currentStateVersion: "v15"); + + _revalidateFixture = GovernanceVersionResolutionBenchmarkSupport.CreateFixture( + RevalidateRequestId, + expectedStateVersion: "v10", + currentStateVersion: "v15"); + } + + /// + /// Measures version comparison when approved request matches the current state version. + /// + [Benchmark(Baseline = true)] + public async Task ResolveApproved_MatchingVersion() + { + var result = await _matchingFixture.ResolutionManager.ResolveAndStore( + _matchingFixture.Request.RequestId, + currentStateVersion: _matchingFixture.CurrentStateVersion, + resolutionContext: _matchingFixture.ResolutionContext, + strategy: VersionedRequestResolutionStrategy.RejectStale).ConfigureAwait(false); + + GC.KeepAlive(result); + } + + /// + /// Measures stale request detection and classification during version resolution. + /// + [Benchmark] + public async Task ResolveApproved_RejectStale() + { + var result = await _staleFixture.ResolutionManager.ResolveAndStore( + _staleFixture.Request.RequestId, + currentStateVersion: _staleFixture.CurrentStateVersion, + resolutionContext: _staleFixture.ResolutionContext, + strategy: VersionedRequestResolutionStrategy.RejectStale).ConfigureAwait(false); + + GC.KeepAlive(result); + } + + /// + /// Measures revalidation-driven request resolution against the latest state version. + /// + [Benchmark] + public async Task ResolveApproved_Revalidate() + { + var result = await _revalidateFixture.ResolutionManager.ResolveAndStore( + _revalidateFixture.Request.RequestId, + currentStateVersion: _revalidateFixture.CurrentStateVersion, + resolutionContext: _revalidateFixture.ResolutionContext, + strategy: VersionedRequestResolutionStrategy.RevalidateOnLatestState).ConfigureAwait(false); + + GC.KeepAlive(result); + } +} diff --git a/Benchmarks/Governance/Resolution/Support/GovernanceVersionResolutionBenchmarkSupport.cs b/Benchmarks/Governance/Resolution/Support/GovernanceVersionResolutionBenchmarkSupport.cs new file mode 100644 index 0000000..2198af2 --- /dev/null +++ b/Benchmarks/Governance/Resolution/Support/GovernanceVersionResolutionBenchmarkSupport.cs @@ -0,0 +1,120 @@ +using ModularityKit.Mutator.Abstractions; +using ModularityKit.Mutator.Abstractions.Changes; +using ModularityKit.Mutator.Abstractions.Context; +using ModularityKit.Mutator.Abstractions.Engine; +using ModularityKit.Mutator.Abstractions.Intent; +using ModularityKit.Mutator.Abstractions.Results; +using ModularityKit.Mutator.Benchmarks.Engine; +using ModularityKit.Mutator.Governance.Abstractions.Execution.Contracts; +using ModularityKit.Mutator.Governance.Abstractions.Requests.Factory; +using ModularityKit.Mutator.Governance.Abstractions.Requests.Model; +using ModularityKit.Mutator.Governance.Runtime.Resolution.Execution; +using ModularityKit.Mutator.Governance.Runtime.Storage; + +namespace ModularityKit.Mutator.Benchmarks.Governance.Resolution.Support; + +/// +/// Builds repeatable governance version resolution benchmark fixtures. +/// +internal static class GovernanceVersionResolutionBenchmarkSupport +{ + public const string StateId = "governance-benchmark:resolution"; + + /// + /// Creates a fresh resolution fixture for a single scenario run. + /// + public static GovernanceVersionResolutionBenchmarkFixture CreateFixture( + string requestId, + string expectedStateVersion, + string currentStateVersion) + { + _ = MutationEngineBenchmarkSupport.BuildEngine(MutationEngineOptions.Strict); + + var store = new InMemoryMutationRequestStore(); + var resolver = new MutationRequestVersionResolver(); + var resolutionManager = new MutationRequestVersionResolutionManager(store, resolver); + var request = store.Create(CreateApprovedRequest( + requestId, + expectedStateVersion)) + .GetAwaiter() + .GetResult(); + + return new GovernanceVersionResolutionBenchmarkFixture( + ResolutionManager: resolutionManager, + Request: request, + CurrentStateVersion: currentStateVersion, + ResolutionContext: MutationContext.System("governance-resolution-benchmark")); + } + + /// + /// Creates the approved request used by governance version resolution benchmarks. + /// + private static MutationRequest CreateApprovedRequest( + string requestId, + string expectedStateVersion) + where TMutation : IMutation + => MutationRequestFactory.Approved( + stateId: StateId, + intent: CreateIntent(), + context: MutationContext.User("requester", "Requester", "Need governed version resolution"), + expectedStateVersion: expectedStateVersion) + with + { + RequestId = requestId + }; + + /// + /// Creates the intent used by governance version resolution scenarios. + /// + private static MutationIntent CreateIntent() + => new() + { + OperationName = "ResolveGovernedVersion", + Category = "Governance", + Description = "Resolve governance request version against the current state snapshot", + RiskLevel = MutationRiskLevel.Low, + IsReversible = true + }; + + /// + /// Minimal versioned state used by governance version resolution benchmarks. + /// + /// Stable state identifier. + /// Current state version. + internal sealed record GovernanceVersionResolutionState(string StateId, string Version) : IVersionedState; + + /// + /// Minimal mutation type used to anchor governed request metadata for version resolution benchmarks. + /// + internal sealed class NoOpGovernanceResolutionMutation : IMutation + { + public MutationIntent Intent { get; } = new() + { + OperationName = "NoOpGovernanceResolution", + Category = "Governance", + Description = "Anchor request metadata for governed version resolution benchmarks", + RiskLevel = MutationRiskLevel.Low, + IsReversible = true + }; + + public MutationContext Context { get; } = MutationContext.System("governance-resolution-benchmark"); + + public MutationResult Apply(GovernanceVersionResolutionState state) + => MutationResult.Success( + state, + ChangeSet.Empty); + + public ValidationResult Validate(GovernanceVersionResolutionState state) => ValidationResult.Success(); + + public MutationResult Simulate(GovernanceVersionResolutionState state) => Apply(state); + } + + /// + /// Shared fixture for a governance version resolution scenario. + /// + internal sealed record GovernanceVersionResolutionBenchmarkFixture( + MutationRequestVersionResolutionManager ResolutionManager, + MutationRequest Request, + string CurrentStateVersion, + MutationContext ResolutionContext); +} diff --git a/Benchmarks/README.md b/Benchmarks/README.md index ef6cc1f..c8740b9 100644 --- a/Benchmarks/README.md +++ b/Benchmarks/README.md @@ -17,6 +17,7 @@ This folder contains BenchmarkDotNet measurements for `ModularityKit.Mutator`. - governance approval workflow overhead in the governance runtime - governance request lifecycle overhead in the governance runtime - governance execution orchestration overhead in the governance runtime +- governance version resolution overhead in the governance runtime The throughput benchmarks use cloned array backed state so state size effects remain visible in the actual mutation path rather than being hidden behind an artificial inner loop.