Benchmark MCP protocol helpers

HA
8h ago
+338-0

Summary

The benchmark harness currently has no dedicated MCP cases. This PR establishes reproducible baselines for metadata validation, header mirroring, result serialization and subscription intersection, so future optimizations can be evaluated against consistent workloads.

Adds 22 deterministic microbenchmarks, registered and linked only when SOURCEMETA_CORE_MCP is enabled. No production APIs or validation behavior change.

Benchmark coverage

Area | Workloads -- | -- JSON parsing | Parse cached metadata envelopes with 0 and 128 additional metadata keys, separately from MCP validation Metadata validation | Validate already parsed requests, including valid inputs and invalid progress tokens Header mirroring | Generate and validate headers with 2 and 64 descriptors, including Unicode sentinel encoding, unrelated headers and late mismatches Result serialization | Serialize 1 and 256 resources through const-input and move-taking writers; measure invalid-result rejection separately Subscription intersection | Intersect overlapping and disjoint lists containing 8 and 512 URIs per side

Measurement boundaries

  • Fixture construction and preflight correctness checks occur outside timed loops.

  • Preflight checks remain active in Release builds.

  • Results use the existing benchmark optimization barrier.

  • Per-iteration output allocation and destruction are included.

  • The move-writer benchmark explicitly includes the fresh-payload copy required for each repetition. It is labelled copy + move-write, rather than implying a copy-free comparison.

  • Parsing, successful validation, rejection and serialization have distinct benchmark names.

benchmark/MCP.markdown documents fixture sizes, timing boundaries, execution commands and the compiler, build, allocator and machine information needed for reproducible comparisons.

Files changed

  • benchmark/CMakeLists.txt -conditional MCP benchmark registration and linkage.

  • benchmark/mcp.cc - workloads and Release-active correctness controls.

  • benchmark/MCP.markdown - measurement and reproduction instructions.

Verification

  • Release build passed with GCC 13.3 and the system allocator.

  • All 22 filtered MCP benchmarks completed successfully.

  • JSON output verified for unique registrations, finite positive timings and three repetitions.

  • Existing MCP unit suite: 1,420 passed, zero failed.

  • MCP-disabled configuration verified to exclude benchmark/mcp.cc.

  • Repository clang-format checks and git diff --check passed.

Limitations

These are authored microbenchmark fixtures, not captured production traffic. They measure local helper operations, not model generation, network latency or a complete MCP transport runtime.

This PR establishes baselines; it makes no speedup claim and introduces no CI timing thresholds. Allocation profiling, the full repository test matrix and Windows/macOS builds were not run locally.