Skip to content

Feat/Add Mediator support to benchmark suites and update documentation#350

Merged
GeWuYou merged 8 commits into
mainfrom
feat/cqrs-optimization
May 12, 2026
Merged

Feat/Add Mediator support to benchmark suites and update documentation#350
GeWuYou merged 8 commits into
mainfrom
feat/cqrs-optimization

Conversation

@GeWuYou
Copy link
Copy Markdown
Owner

@GeWuYou GeWuYou commented May 12, 2026

Summary by CodeRabbit

  • 新功能

    • 在基准测试中新增 NuGet Mediator 的对比路径(包含流启动/冷启动场景)。
  • 文档

    • 为多个基准方法补充/完善返回值说明。
    • 更新 README,明确各基准场景的覆盖边界与结果解读。
  • 修复 / 维护

    • 统一了 Mediator 的运行时注入生命周期以保证基准一致性,并相应收窄了请求生命周期对比矩阵以避免不可复现的配置异常。

Review Change Stack

GeWuYou added 7 commits May 12, 2026 13:17
- 新增 StreamStartupBenchmarks 的 Mediator 初始化与 cold-start benchmark。

- 更新 stream request 与 handler 契约以接入 NuGet Mediator source-generated concrete path。
- 更新 StreamingBenchmarks 的 XML 返回值注释并收口 README 中的 stream startup/gap 描述。

- 补充 cqrs-rewrite tracking 与 trace,记录 PR #349 合并后的新基线、startup parity 进展与下一恢复点。
- 补充 RequestInvokerBenchmarks 公开 benchmark 方法缺失的 XML returns 契约

- 补充 RequestLifetimeBenchmarks 公开 benchmark 方法缺失的 XML returns 契约
- 补充 RequestBenchmarks 公开 benchmark 方法的 XML returns 契约

- 补充 RequestPipelineBenchmarks 公开 benchmark 方法的 XML returns 契约
- 补充 stream 与 notification benchmark 公开方法缺失的 XML returns 契约

- 更新 request startup benchmark 的返回值文档说明

- 同步 cqrs-rewrite 的批处理恢复点与停点决策
- 更新 README 中 stream/request/notification startup benchmark 的覆盖矩阵与适用边界

- 补充 cqrs-rewrite public tracking 与 trace,记录本轮误报剔除、docs-only 收尾与停止判断
- 新增 RequestLifetimeBenchmarks 的 Mediator lifetime parity,并按编译期常量分支生成 Singleton、Scoped、Transient 宿主

- 更新 benchmark README 的 request lifetime coverage 与当前缺口说明,使其反映最新对照矩阵

- 修复 RequestBenchmarks 与 NotificationBenchmarks 的 XML 文档漂移,并同步 ai-plan 恢复点与验证结论
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 12, 2026

Greptile Summary

This PR extends the CQRS benchmark suite by adding NuGet Mediator (source-generated concrete mediator) as a third comparison target alongside GFramework.CQRS and MediatR. It also fixes CreateMediatorServiceProvider to explicitly pin ServiceLifetime.Singleton, preventing a compile-time/runtime lifetime mismatch that would cause startup failures.

  • BenchmarkHostFactory.CreateMediatorServiceProvider now passes an explicit Singleton lifetime option to AddMediator, and the doc comment explains why compile-time source generation forces a single lifetime shape across the whole project.
  • Steady-state benchmarks (RequestBenchmarks, NotificationBenchmarks, NotificationFanOutBenchmarks, StreamingBenchmarks) each gain a *_Mediator method; handlers and request types are updated to implement the corresponding Mediator.* contracts via explicit interface implementation.
  • Startup benchmarks (RequestStartupBenchmarks, StreamStartupBenchmarks) gain Initialization_Mediator and ColdStart_Mediator methods; lifetime and invoker benchmarks document (and correctly omit) Mediator since its lifetime is fixed at compile time and its pipeline model differs.

Confidence Score: 5/5

All changes are confined to the benchmark project; no production or library code is touched.

The Mediator additions are internally consistent: each benchmark class that gains a Mediator path also correctly disposes _mediatorServiceProvider in its Cleanup method, handlers use explicit interface implementation to avoid ambiguity, and the ServiceLifetime.Singleton fix in CreateMediatorServiceProvider prevents a known startup failure. Benchmarks where Mediator lifetime or pipeline integration don't apply are correctly excluded and documented.

No files require special attention.

Important Files Changed

Filename Overview
GFramework.Cqrs.Benchmarks/Messaging/BenchmarkHostFactory.cs Updated CreateMediatorServiceProvider to explicitly set ServiceLifetime.Singleton and expanded the doc comment explaining why the lifetime is fixed to match the source-generator constraint.
GFramework.Cqrs.Benchmarks/Messaging/StreamStartupBenchmarks.cs Added Mediator support: new _mediatorServiceProvider/_mediator fields, Initialization_Mediator and ColdStart_Mediator benchmarks, and a tri-contract BenchmarkStreamHandler with explicit interface implementations for GFramework, Mediator, and MediatR.
GFramework.Cqrs.Benchmarks/Messaging/RequestBenchmarks.cs Added SendRequest_Mediator benchmark and the corresponding _mediatorServiceProvider/_mediator fields; _mediatorServiceProvider is correctly disposed in Cleanup.
GFramework.Cqrs.Benchmarks/Messaging/NotificationBenchmarks.cs Added PublishNotification_Mediator benchmark; description updated to mention Mediator as a third comparison target; disposal is correctly included.
GFramework.Cqrs.Benchmarks/Messaging/RequestStartupBenchmarks.cs Added Initialization_Mediator and ColdStart_Mediator benchmarks and the supporting _mediatorServiceProvider/_mediator fields; _mediatorServiceProvider is correctly disposed.
GFramework.Cqrs.Benchmarks/Messaging/RequestLifetimeBenchmarks.cs Updated class remarks to explicitly document why Mediator is excluded from the lifetime matrix (compile-time fixed lifetime); no functional changes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph Steady-State Benchmarks
        RB[RequestBenchmarks] --> RB_M[SendRequest_Mediator]
        NB[NotificationBenchmarks] --> NB_M[PublishNotification_Mediator]
        NFO[NotificationFanOutBenchmarks] --> NFO_M[PublishNotification_Mediator]
        SB[StreamingBenchmarks] --> SB_M[Stream_Mediator]
    end
    subgraph Startup Benchmarks
        RSB[RequestStartupBenchmarks] --> RSB_I[Initialization_Mediator]
        RSB --> RSB_C[ColdStart_Mediator]
        SSB[StreamStartupBenchmarks] --> SSB_I[Initialization_Mediator]
        SSB --> SSB_C[ColdStart_Mediator]
    end
    subgraph Factory
        BHF[BenchmarkHostFactory.CreateMediatorServiceProvider]
        BHF --> ADD[services.AddMediator - ServiceLifetime.Singleton]
    end
    RB_M --> BHF
    NB_M --> BHF
    NFO_M --> BHF
    SB_M --> BHF
    RSB_I --> BHF
    RSB_C --> BHF
    SSB_I --> BHF
    SSB_C --> BHF
Loading

Reviews (2): Last reviewed commit: "fix(cqrs-benchmarks): 修正Mediator基准运行时配置" | Re-trigger Greptile

Comment thread GFramework.Cqrs.Benchmarks/Messaging/StreamStartupBenchmarks.cs
@github-actions
Copy link
Copy Markdown

Summary

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
2377 2377 0 0 0 0 38.7s    ↑1.1s

Test Results

passed 2377 passed

Details

tests 2377 tests
clock 38.7s ↑1.1s
tool nunit
build CI - Build & Test arrow-right build-and-test link #1111
pull-request Feat/cqrs optimization link #350

Insights

Average Tests per Run Total Flaky Tests Total Failed Slowest Test (p95)
2263 0 3 4.8s

Fail Rate

Fail Rate 0.00%
Test 📝 Results 📊 Passed ✅ Failed ❌ Fail Rate (%) 📈
CreateStream_Should_Throw_When_Stream_Pipeline_Behavior_Context_Does_Not_Implement_IArchitectureContext 20 19 1 5.00    ↓0.26
PublishAsync_Should_Stop_After_First_Handler_Exception_When_Using_Default_Publisher 38 37 1 2.63    ↓0.07
PublishAsync_Should_Throw_When_Context_Does_Not_Implement_IArchitectureContext 42 41 1 2.38    ↓0.06

build-and-test: Run #1111

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
2377 2377 0 0 0 0 0 38.7s

🎉 All tests passed!

Slowest Tests

Test 📝 Results 📊 Duration (avg) ⏱️ Duration (p95) ⏱️
CreateStream_Should_ResolveCqrsRuntime_OnlyOnce_When_AccessedConcurrently 38 4.2s 4.8s
SendRequestAsync_Should_ResolveCqrsRuntime_OnlyOnce_When_AccessedConcurrently 53 1.2s 4.7s
Does_Not_Report_When_FieldInjectedModel_Is_Registered 53 2.2s 2.3s
Generates_Scene_Behavior_Boilerplate 53 1.9s 2.0s
CleanupDuringAcquire_Should_NotCauseRaceCondition 53 1.1s 1.1s
Append_ShouldNotBlock 53 1.0s 1.0s
Context_Caching_Should_Improve_Performance 53 781ms 794ms
PendingCount_ShouldReflectQueuedEntries 53 501ms 501ms
Cleanup_Should_NotRemoveActiveLocks 53 404ms 405ms
Cleanup_Should_RemoveUnusedLocks 53 401ms 402ms

± Comparison with run #1110 at 3a47abe | 🍂 No flaky tests detected across all runs. | ⏱️ Measured over 53 runs.

Github Test Reporter by CTRF 💚

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 12, 2026

⚠️MegaLinter analysis: Success with warnings

Descriptor Linter Files Fixed Errors Warnings Elapsed time
⚠️ CSHARP dotnet-format yes 1 no 5.75s
✅ REPOSITORY gitleaks yes no no 9.23s
✅ REPOSITORY trufflehog yes no no 6.24s

Detailed Issues

⚠️ CSHARP / dotnet-format - 1 error
Welcome to .NET 9.0!
---------------------
SDK Version: 9.0.114

----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate, run 'dotnet dev-certs https --trust'
Learn about HTTPS: https://aka.ms/dotnet-https

----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
Unhandled exception: System.Exception: Restore operation failed.
   at Microsoft.CodeAnalysis.Tools.CodeFormatter.OpenMSBuildWorkspaceAsync(String solutionOrProjectPath, WorkspaceType workspaceType, Boolean noRestore, Boolean requiresSemantics, String binaryLogPath, Boolean logWorkspaceWarnings, ILogger logger, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.CodeFormatter.FormatWorkspaceAsync(FormatOptions formatOptions, ILogger logger, CancellationToken cancellationToken, String binaryLogPath)
   at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.FormatAsync(FormatOptions formatOptions, ILogger`1 logger, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.Commands.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
   at System.CommandLine.Invocation.InvocationPipeline.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)

See detailed reports in MegaLinter artifacts
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2b7033ed-0953-43c4-9da0-e3c8f86fb917

📥 Commits

Reviewing files that changed from the base of the PR and between e3532fc and 2dd9435.

📒 Files selected for processing (5)
  • GFramework.Cqrs.Benchmarks/Messaging/BenchmarkHostFactory.cs
  • GFramework.Cqrs.Benchmarks/Messaging/RequestLifetimeBenchmarks.cs
  • GFramework.Cqrs.Benchmarks/README.md
  • ai-plan/public/cqrs-rewrite/todos/cqrs-rewrite-migration-tracking.md
  • ai-plan/public/cqrs-rewrite/traces/cqrs-rewrite-migration-trace.md
✅ Files skipped from review due to trivial changes (2)
  • GFramework.Cqrs.Benchmarks/README.md
  • GFramework.Cqrs.Benchmarks/Messaging/RequestLifetimeBenchmarks.cs
📜 Recent review details
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build and Test
  • GitHub Check: Code Quality & Security
  • GitHub Check: Analyze (C#)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.cs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.cs: Apply [Log] attribute for automatic logging field and logging helper method generation
Apply [Priority] attribute for automatic priority comparison implementation generation
Apply [GenerateEnumExtensions] attribute to generate enumeration extension capabilities
Apply [ContextAware] attribute to automatically implement IContextAware boilerplate logic

**/*.cs: All public, protected, and internal types and members MUST include XML documentation comments (///)
XML documentation comments MUST use <summary>, <param>, <returns>, <exception>, and <remarks> where applicable, explaining intent, contract, and usage constraints instead of restating syntax
If a member participates in lifecycle, threading, registration, or disposal behavior, document that behavior explicitly in XML documentation
Add inline comments for non-trivial logic, concurrency or threading behavior, performance-sensitive paths, workarounds and compatibility constraints, edge cases, registration order, lifecycle sequencing, and generated code assumptions
Avoid obvious comments such as // increment i
Methods with non-trivial logic MUST document: The core idea, Key decisions, and Edge case handling, if any
Comments MUST NOT be trivial, redundant, or misleading. Prefer explaining why and when, not just what. Code should remain understandable without requiring external context. Prefer slightly more explanation over too little for framework code
Do not rely on implicit imports. Declare every required using explicitly
Write null-safe code that respects nullable annotations instead of suppressing warnings by default
Use the namespace pattern GFramework.{Module}.{Feature} with PascalCase segments
Follow standard C# naming: Types, methods, properties, events, and constants use PascalCase; Interfaces use I prefix; Parameters and locals use camelCase; Private fields use _camelCase
Use 4 spaces for indentation. Do not use tabs
Use Allman braces
Keep using directives at the top...

Files:

  • GFramework.Cqrs.Benchmarks/Messaging/BenchmarkHostFactory.cs
ai-plan/public/**

📄 CodeRabbit inference engine (AGENTS.md)

ai-plan/public/**: Contributors MUST keep committed ai-plan/public/** content safe to publish in Git history
Active tracking and trace files are recovery entrypoints, not append-only changelogs. They MUST stay concise enough for boot to locate the current recovery point quickly
When completed and validated stages begin to accumulate, contributors MUST archive their detailed history out of the active todos/ and traces/ entry files in the same change. Keep only the current recovery point, active facts, active risks, immediate next step, and pointers to the relevant archive files in the default boot path
When a topic is fully complete, move the entire topic directory under ai-plan/public/archive/<topic>/ and remove it from ai-plan/public/README.md in the same change
When a task spans multiple commits or is likely to exceed a single agent context window, update both the recovery document and the trace at each meaningful milestone before pausing or handing work off
If subagents are used on a complex task, the main agent MUST capture the delegated scope and any accepted findings in the active recovery document or trace before continuing implementation

Files:

  • ai-plan/public/cqrs-rewrite/todos/cqrs-rewrite-migration-tracking.md
  • ai-plan/public/cqrs-rewrite/traces/cqrs-rewrite-migration-trace.md
ai-plan/**

📄 CodeRabbit inference engine (AGENTS.md)

ai-plan/**: Never write secrets, tokens, credentials, private keys, machine usernames, home-directory paths, hostnames, IP addresses, proprietary URLs, or other sensitive environment details into any ai-plan/** file
Never record absolute file-system paths in ai-plan/**; use repository-relative paths, branch names, PR numbers, or stable document identifiers instead

Files:

  • ai-plan/public/cqrs-rewrite/todos/cqrs-rewrite-migration-tracking.md
  • ai-plan/public/cqrs-rewrite/traces/cqrs-rewrite-migration-trace.md
ai-plan/public/**/todos/**

📄 CodeRabbit inference engine (AGENTS.md)

ai-plan/public/**/todos/**: When working from a tracked implementation plan, contributors MUST update the corresponding tracking document under ai-plan/public/<topic>/todos/ in the same change
Tracking updates MUST reflect completed work, newly discovered issues, validation results, and the next recommended recovery point
For any multi-step refactor, migration, or cross-module task, contributors MUST create or adopt a dedicated recovery document under ai-plan/public/<topic>/todos/ before making substantive code changes
Recovery documents MUST record the current phase, the active recovery point identifier, known risks, and the next recommended resume step so another contributor or subagent can continue the work safely

Files:

  • ai-plan/public/cqrs-rewrite/todos/cqrs-rewrite-migration-tracking.md
ai-plan/public/**/traces/**

📄 CodeRabbit inference engine (AGENTS.md)

Contributors MUST maintain a matching execution trace under ai-plan/public/<topic>/traces/ for complex work. The trace should record the current date, key decisions, validation milestones, and the immediate next step

Files:

  • ai-plan/public/cqrs-rewrite/traces/cqrs-rewrite-migration-trace.md
🧠 Learnings (2)
📚 Learning: 2026-04-06T12:45:43.921Z
Learnt from: GeWuYou
Repo: GeWuYou/GFramework PR: 190
File: GFramework.Game/Config/GameConfigBootstrap.cs:1-3
Timestamp: 2026-04-06T12:45:43.921Z
Learning: In the GeWuYou/GFramework repository, C# files may omit explicit `using System*` imports because the project-wide `GlobalUsings.cs` (referenced via manual global `using` directives) supplies common namespaces (e.g., `System`, `System.Threading`, `System.Threading.Tasks`). During code review, do not flag missing `using System...` directives in `.cs` files as long as `GlobalUsings.cs` is present/used to provide those namespaces.

Applied to files:

  • GFramework.Cqrs.Benchmarks/Messaging/BenchmarkHostFactory.cs
📚 Learning: 2026-05-11T06:15:15.057Z
Learnt from: GeWuYou
Repo: GeWuYou/GFramework PR: 348
File: GFramework.Cqrs.Benchmarks/Messaging/NotificationLifetimeBenchmarks.cs:52-68
Timestamp: 2026-05-11T06:15:15.057Z
Learning: In the GeWuYou/GFramework repo, do not treat a missing [GenerateEnumExtensions] attribute as a code review issue for every enum. Skip the check for:
1) local/private benchmark enums (e.g., enums defined for benchmarks such as HandlerLifetime in GFramework.Cqrs.Benchmarks),
2) enums located in projects that do NOT reference the source-generator abstractions package (the generator won’t apply there), and
3) core framework/runtime-style code paths that AGENTS.md explicitly restricts from using generator-attribute usage.
If an enum falls into any of these cases, do not flag the missing [GenerateEnumExtensions] (it has been triaged as a generalized false positive for these scenarios).

Applied to files:

  • GFramework.Cqrs.Benchmarks/Messaging/BenchmarkHostFactory.cs
🪛 LanguageTool
ai-plan/public/cqrs-rewrite/traces/cqrs-rewrite-migration-trace.md

[uncategorized] ~58-~58: 您的意思是“"不"齐”?
Context: ...tBenchmarks.cs - 将 handler XML 文档说明补齐为同时实现GFramework.CQRS、NuGet Mediator...

(BU)


[uncategorized] ~60-~60: 您的意思是“"不"齐”?
Context: ...chmarks.cs - 将类说明与 handler XML 文档说明补齐为同时覆盖GFramework.CQRS、NuGet Mediator...

(BU)


[uncategorized] ~74-~74: 动词的修饰一般为‘形容词(副词)+地+动词’。您的意思是否是:新"地"实现
Context: ... 0 error- 当前 stop decision: - 不继续开启新的实现波次 - 原因不是 branch-size 阈值耗尽;当前分支仍只有...

(wb4)


[uncategorized] ~78-~78: 您的意思是“"不"跑”?
Context: ...ks会显著提高作用域与 review 成本 - 当前下一步: - 主线程补跑python3 scripts/license-header.py --c...

(BU)


[uncategorized] ~147-~147: 单纯方位词与名词结合不加“的”,您的意思是否是:"契约下 或 契约以下 或 契约的下"边
Context: ...证通过,决定是在当前自然停点提交收尾,还是继续 request 侧 XML 契约的下一波低风险批处理 ### 阶段:request benchmark XML ...

(wa2)


[uncategorized] ~157-~157: 您的意思是“"不"公开”?
Context: ... - RequestStartupBenchmarks.cs - 只补公开 benchmark 方法缺失的 <returns> - wor...

(BU)


[uncategorized] ~160-~160: 您的意思是“"不"公开”?
Context: ...+ RequestPipelineBenchmarks.cs - 只补公开 benchmark 方法缺失的 <returns> - wor...

(BU)


[uncategorized] ~163-~163: 您的意思是“"不"公开”?
Context: ...+ RequestLifetimeBenchmarks.cs - 只补公开 benchmark 方法缺失的 <returns> - wor...

(BU)

🔇 Additional comments (10)
GFramework.Cqrs.Benchmarks/Messaging/BenchmarkHostFactory.cs (2)

278-281: LGTM!


287-287: LGTM!

ai-plan/public/cqrs-rewrite/todos/cqrs-rewrite-migration-tracking.md (3)

15-17: LGTM!


18-34: LGTM!


38-83: LGTM!

ai-plan/public/cqrs-rewrite/traces/cqrs-rewrite-migration-trace.md (5)

10-43: LGTM!


44-80: LGTM!


81-109: LGTM!


110-172: LGTM!


173-213: LGTM!


📝 Walkthrough

Walkthrough

本 PR 为请求和流基准添加 NuGet 源生成 Generated Mediator 路径、为请求/流记录与处理器实现 Mediator 契约、增加对应基准方法,并在多处基准方法上补齐 <returns> XML 文档;同时更新 README 与迁移追踪文档以精化覆盖边界。

变更

Mediator 奇偶校验和文档收口

Layer / File(s) Summary
Stream/请求 Mediator 路径与宿主工厂
GFramework.Cqrs.Benchmarks/Messaging/StreamStartupBenchmarks.cs, GFramework.Cqrs.Benchmarks/Messaging/BenchmarkHostFactory.cs
为流启动添加 NuGet Mediator concrete 路径:新增 mediator 主机字段、Setup/Cleanup 构建与释放、Initialization_Mediator()ColdStart_Mediator() 基准,添加 CreateMediatorServiceProvider() 工厂;BenchmarkHostFactory 中 CreateMediatorServiceProvider 调用 services.AddMediator(...) 并在 options 中将生成 Mediator 的 ServiceLifetime 设置为 Singleton(文档注释同步更新)。
请求生命周期 Mediator 注释与锚点调整
GFramework.Cqrs.Benchmarks/Messaging/RequestLifetimeBenchmarks.cs, RequestStartupBenchmarks.cs
更新类级备注以说明 NuGet 源生成 Mediator 的 DI lifetime 在编译期固定,调整基准矩阵说明(仅比较 GFramework.Cqrs 与 MediatR 生命周期开销),并为若干 SendRequest_* 方法补充 <returns> 文档;同时对附近 XML 注释行进行重锚。
基准 Methods <returns> 文档补齐
GFramework.Cqrs.Benchmarks/Messaging/*(通知/扇出/请求/调用器/管线/启动/流/流生命周期/流消费基准)
为多达数十个基准方法补充或更新 <returns> XML 注释,明确各派遣路径完成时返回 Task/ValueTask 的语义;更新若干类级别摘要以包含 NuGet Mediator 覆盖说明。
覆盖范围与迁移追踪文档
GFramework.Cqrs.Benchmarks/README.md, ai-plan/public/cqrs-rewrite/todos/*, ai-plan/public/cqrs-rewrite/traces/*
收窄/精化启动/冷启动覆盖边界为“单处理程序最小主机 + 手动注册”模型,列出流启动四种初始化/冷启动变体(MediatR、GFramework 反射、GFramework 生成、NuGet Mediator),并在迁移跟踪中记录 RP-137..RP-141 相关验证与决策条目(包括针对 Mediator DI lifetime 的发现与宿主级 fix)。

Sequence Diagram(s)

sequenceDiagram
  participant GlobalSetup
  participant MediatorHost as Mediator ServiceProvider
  participant GeneratedMediator
  participant SendRequest as SendRequest_Mediator()
  participant Handler as BenchmarkRequestHandler

  GlobalSetup->>MediatorHost: Create/resolve GeneratedMediator per lifetime
  SendRequest->>MediatorHost: (if Scoped) Create scope and resolve GeneratedMediator
  SendRequest->>GeneratedMediator: GeneratedMediator.Send(BenchmarkRequest)
  GeneratedMediator->>Handler: Invoke IRequestHandler.Handle
  Handler-->>GeneratedMediator: Return BenchmarkResponse
  GeneratedMediator-->>SendRequest: Return ValueTask<BenchmarkResponse>
Loading
sequenceDiagram
  participant GlobalSetup
  participant Factory as CreateMediatorServiceProvider()
  participant MediatorHost as ServiceProvider
  participant GeneratedMediator
  participant Initialization as Initialization_Mediator()
  participant ColdStart as ColdStart_Mediator()

  GlobalSetup->>Factory: Build minimal Mediator host
  Factory-->>MediatorHost: Return configured ServiceProvider
  Initialization->>MediatorHost: Resolve GeneratedMediator
  Initialization-->>Initialization: Return GeneratedMediator instance
  ColdStart->>GeneratedMediator: CreateStream(BenchmarkStreamRequest)
  GeneratedMediator->>ColdStart: Return IAsyncEnumerable and yield first item
  ColdStart-->>ColdStart: Consume first element and complete
Loading

评审工作量评估

🎯 3 (中等) | ⏱️ ~25 分钟

可能相关的 PR

  • GeWuYou/GFramework#349:与本 PR 在流基准与 Mediator 支持点上直接重叠(新增/支持 NuGet Mediator 路径与契约实现)。
  • GeWuYou/GFramework#347:修改基准宿主/mediator 集成点,涉及相同文件区域与生命周期处理逻辑。
  • GeWuYou/GFramework#326:在相同基准套件中对 Mediator 路径与 XML 注释进行调整,覆盖类似的通知/请求/流基准。
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确地总结了此 PR 的主要改动:向基准测试套件添加 Mediator 支持并更新文档。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cqrs-optimization

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@GeWuYou GeWuYou changed the title Feat/cqrs optimization Feat/Add Mediator support to benchmark suites and update documentation May 12, 2026
@GeWuYou
Copy link
Copy Markdown
Owner Author

GeWuYou commented May 12, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

✅ Actions performed

Full review triggered.

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 12, 2026
- 修正 BenchmarkHostFactory 的 Mediator 宿主接线,统一使用 Singleton 编译期 lifetime

- 更新 RequestLifetimeBenchmarks 与 README,撤回当前不可运行的 Mediator 生命周期矩阵并同步覆盖边界

- 补充 cqrs-rewrite 跟踪,记录 PR #350 评审真值、故障根因与 smoke run 验证结果
@github-actions
Copy link
Copy Markdown

Summary

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
2377 2377 0 0 0 0 39.1s    ↑388ms

Test Results

passed 2377 passed

Details

tests 2377 tests
clock 39.1s ↑388ms
tool nunit
build CI - Build & Test arrow-right build-and-test link #1112
pull-request Feat/Add Mediator support to benchmark suites and update documentation link #350

Insights

Average Tests per Run Total Flaky Tests Total Failed Slowest Test (p95)
2265 0 3 4.8s

Fail Rate

Fail Rate 0.00%
Test 📝 Results 📊 Passed ✅ Failed ❌ Fail Rate (%) 📈
CreateStream_Should_Throw_When_Stream_Pipeline_Behavior_Context_Does_Not_Implement_IArchitectureContext 21 20 1 4.76    ↓0.24
PublishAsync_Should_Stop_After_First_Handler_Exception_When_Using_Default_Publisher 39 38 1 2.56    ↓0.07
PublishAsync_Should_Throw_When_Context_Does_Not_Implement_IArchitectureContext 43 42 1 2.33    ↓0.05

build-and-test: Run #1112

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
2377 2377 0 0 0 0 0 39.1s

🎉 All tests passed!

Slowest Tests

Test 📝 Results 📊 Duration (avg) ⏱️ Duration (p95) ⏱️
CreateStream_Should_ResolveCqrsRuntime_OnlyOnce_When_AccessedConcurrently 39 4.2s 4.8s
SendRequestAsync_Should_ResolveCqrsRuntime_OnlyOnce_When_AccessedConcurrently 54 1.2s 4.7s
Does_Not_Report_When_FieldInjectedModel_Is_Registered 54 2.2s 2.3s
Generates_Scene_Behavior_Boilerplate 54 1.9s 2.0s
CleanupDuringAcquire_Should_NotCauseRaceCondition 54 1.1s 1.1s
Append_ShouldNotBlock 54 1.0s 1.0s
Context_Caching_Should_Improve_Performance 54 781ms 794ms
PendingCount_ShouldReflectQueuedEntries 54 501ms 501ms
Cleanup_Should_NotRemoveActiveLocks 54 404ms 406ms
Cleanup_Should_RemoveUnusedLocks 54 401ms 402ms

± Comparison with run #1111 at 61d23ea | 🍂 No flaky tests detected across all runs. | ⏱️ Measured over 54 runs.

Github Test Reporter by CTRF 💚

@GeWuYou GeWuYou merged commit 4837aa2 into main May 12, 2026
7 checks passed
@GeWuYou GeWuYou deleted the feat/cqrs-optimization branch May 12, 2026 12:37
@coderabbitai coderabbitai Bot mentioned this pull request May 14, 2026
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.

1 participant