test(benchmarks): add CodSpeed benchmarks for inference, MCP and A2A hot paths - #31716
Conversation
…hot paths Guard the per-request CPU cost of the chat completion, MCP tool and A2A message transforms against regressions on every commit. All benchmarks are pure in-process work with no network I/O so they stay deterministic under CodSpeed's simulation mode, and they import under the base dependency set the benchmark job installs. Inference covers the full SDK overhead via mock_response (simple, multi-turn, tools, streaming) plus convert_to_model_response_object as a deterministic anchor. MCP covers the client-side tool translation and the proxy server-side tool-name prefix round-trip. A2A covers the client request/response transforms and the proxy server-ingress message conversion. Adds the mcp and a2a-sdk packages to the benchmark run since those transform modules need them, and broadens the workflow triggers to litellm_internal_staging so the internal branch flow is benchmarked too.
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR adds CodSpeed coverage for benchmark-only hot paths. The main changes are:
Confidence Score: 5/5Safe to merge based on the benchmark-only scope and absence of code-path issues identified in the changed files. The changes are isolated to benchmark coverage and CodSpeed workflow configuration, with deterministic in-process benchmark targets and no runtime behavior changes.
What T-Rex did
Reviews (1): Last reviewed commit: "test(benchmarks): add CodSpeed benchmark..." | Re-trigger Greptile |
Greptile SummaryThis PR adds CodSpeed benchmark coverage for LiteLLM hot paths. The main changes are:
Confidence Score: 4/5The benchmark additions are isolated and low-risk, with one workflow determinism issue to address before relying on the results long-term. The tests are scoped to in-process benchmark paths and the workflow change is straightforward, but floating benchmark-only dependency ranges can make performance baselines change without a repository change. .github/workflows/codspeed.yml
What T-Rex did
Reviews (2): Last reviewed commit: "test(benchmarks): add CodSpeed benchmark..." | Re-trigger Greptile |
| --with "mcp>=1.26.0,<2.0" | ||
| --with "a2a-sdk>=1.1.0,<2.0" |
There was a problem hiding this comment.
Pin benchmark dependencies
The new benchmark-only dependencies use open version ranges, while the existing benchmark tools are exact-pinned. When a new mcp or a2a-sdk release changes import or runtime behavior, CodSpeed baselines can shift without any repo change. Pin these versions and update them deliberately when the benchmark target changes.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
…hot paths (BerriAI#31716) Guard the per-request CPU cost of the chat completion, MCP tool and A2A message transforms against regressions on every commit. All benchmarks are pure in-process work with no network I/O so they stay deterministic under CodSpeed's simulation mode, and they import under the base dependency set the benchmark job installs. Inference covers the full SDK overhead via mock_response (simple, multi-turn, tools, streaming) plus convert_to_model_response_object as a deterministic anchor. MCP covers the client-side tool translation and the proxy server-side tool-name prefix round-trip. A2A covers the client request/response transforms and the proxy server-ingress message conversion. Adds the mcp and a2a-sdk packages to the benchmark run since those transform modules need them, and broadens the workflow triggers to litellm_internal_staging so the internal branch flow is benchmarked too.
Relevant issues
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewScreenshots / Proof of Fix
These are CodSpeed micro-benchmarks, not a runtime behavior change, so the proof is that the new suite collects and runs green under the exact command the CI job uses. Run from the repo root in an isolated env that installs only the base dependency set the benchmark job uses (
--no-default-groups) plus the benchmark extras:Output (trimmed to the new benchmarks):
The sub-nanosecond transforms read as 0ns only in CodSpeed's local walltime mode; the CI run uses instrumentation mode, which counts CPU instructions and gives them a meaningful, stable number to diff against the base branch
Type
✅ Test
Changes
This adds CodSpeed benchmarks for the three areas of interest so perf regressions in their per-request hot paths surface on every commit going forward. Everything is designed to be lightweight and deterministic: each benchmark is pure in-process CPU work with zero network I/O (a hard requirement of CodSpeed's simulation mode, which counts CPU instructions), and the targets are the transformation functions rather than the full FastAPI proxy, so they import under the constrained dependency set the benchmark job installs
Inference (
tests/benchmarks/test_inference_benchmarks.py) exercises the full SDK overhead throughlitellm.completion(..., mock_response=...)for simple, multi-turn, with-tools and streaming calls, which walks provider resolution, request/response transformation,ModelResponseconstruction, token counting and cost calculation without hitting a provider. It also benchmarksconvert_to_model_response_objectdirectly as a deterministic anchor for the provider-response toModelResponsecore that every non-streaming completion runsMCP (
tests/benchmarks/test_mcp_benchmarks.py) covers the client-side MCP to OpenAI tool translation (a single tool, a 20-tool list mirroring list-tools, and a tool-call dispatch) plus the proxy server-side tool-name prefix round-trip,add_server_prefix_to_nameover a tool list andsplit_server_prefix_from_nameon a call, which is the real per-request CPU cost on the MCP endpointA2A (
tests/benchmarks/test_a2a_benchmarks.py) covers the client direction (convert_messages_to_promptfor the request andextract_text_from_a2a_responsefor message and task-artifact response shapes) and the proxy server-ingressA2ACompletionBridgeTransformation.a2a_message_to_openai_messagesthat runs on every inbound A2A requestThe workflow change adds the
mcpanda2a-sdkpackages to the benchmark run since those transform modules need them at import time, and broadens the push and pull_request triggers to includelitellm_internal_stagingso the internal branch flow, where contributors open PRs against staging rather thanmain, is benchmarked too