Repository navigation
Add CodSpeed continuous performance benchmarks - #23676
1 commit merged into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
| pip install pytest pytest-codspeed==4.3.0 | ||
|
|
||
| - name: Run benchmarks | ||
| uses: CodSpeedHQ/action@v4 |
Check warning
Code scanning / CodeQL
Unpinned tag for a non-immutable Action in workflow Medium
Congrats! CodSpeed is installed 🎉
You will start to see performance impacts in the reports once the benchmarks are run from your default branch.
|
Greptile SummaryThis PR integrates CodSpeed for continuous performance monitoring of litellm's hot paths by adding a benchmark suite, a GitHub Actions workflow, and a README badge. Key changes:
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| .github/workflows/codspeed.yml | New GitHub Actions workflow that installs litellm and pytest-codspeed, then runs benchmarks via the CodSpeedHQ/action@v4 in simulation mode with OIDC authentication. Configuration is correct and follows CodSpeed's recommended setup. |
| README.md | Adds a CodSpeed performance badge. The badge image URL is missing the project-specific path (BerriAI/litellm) and will not display the correct project stats. |
| tests/benchmarks/init.py | Empty init file that makes the benchmarks directory a Python package. No issues. |
| tests/benchmarks/test_benchmarks.py | 16 benchmarks covering token counting, model info lookup, provider resolution, cost calculation, and model cost key resolution. All tested functions are local (no network calls). Two benchmarks access a private function via litellm.utils._get_model_cost_key instead of a direct import, which is fragile. |
Sequence Diagram
sequenceDiagram
participant GH as GitHub Actions
participant CS as CodSpeed Action
participant PT as pytest
participant LM as litellm (local)
GH->>CS: Trigger workflow (push/PR/dispatch)
CS->>PT: Run pytest tests/benchmarks/ --codspeed
PT->>LM: token_counter(model, messages/text)
PT->>LM: get_model_info(model)
PT->>LM: get_llm_provider(model)
PT->>LM: cost_per_token(model, tokens)
PT->>LM: utils._get_model_cost_key(key)
LM-->>PT: Local results (no network calls)
PT-->>CS: Benchmark measurements
CS->>CS: Authenticate via OIDC
CS-->>GH: Upload results to CodSpeed
GH-->>GH: Post performance report on PR
Last reviewed commit: 03b0083
| <img src="https://img.shields.io/static/v1?label=Chat%20on&message=Slack&color=black&logo=Slack&style=flat-square" alt="Slack"> | ||
| </a> | ||
| <a href="https://codspeed.io/BerriAI/litellm?utm_source=badge"> | ||
| <img src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" alt="CodSpeed"/> |
There was a problem hiding this comment.
Badge URL missing project path
The badge image URL points to a generic https://codspeed.io/badge.json endpoint which does not include the project name. This will either fail to load or show a generic/empty badge rather than litellm's specific performance stats.
The standard CodSpeed badge format includes the owner and repository in the path:
| <img src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" alt="CodSpeed"/> | |
| <img src="https://img.shields.io/endpoint?url=https://codspeed.io/BerriAI/litellm/badge.json" alt="CodSpeed"/> |
| litellm.cost_per_token( | ||
| model="claude-sonnet-4-20250514", | ||
| prompt_tokens=1000, | ||
| completion_tokens=500, | ||
| ) | ||
|
|
||
|
|
There was a problem hiding this comment.
Benchmarking a private implementation detail
litellm.utils._get_model_cost_key is a private function (underscore-prefixed). Benchmarking it directly via module attribute access creates a fragile coupling — if the function is renamed, moved, or its internal contract changes, these benchmarks will break silently rather than helping catch regressions.
Consider importing it explicitly at the top of the file to make the dependency clear:
from litellm.utils import _get_model_cost_keyand then calling:
@pytest.mark.benchmark
def test_get_model_cost_key_exact_match():
_get_model_cost_key("gpt-4o")
@pytest.mark.benchmark
def test_get_model_cost_key_case_insensitive():
_get_model_cost_key("GPT-4o")This also surfaces an import error immediately at collection time if the function moves, rather than at benchmark runtime.
Co-authored-by: codspeed-hq[bot] <117304815+codspeed-hq[bot]@users.noreply.github.com>
Summary
This PR integrates CodSpeed for continuous performance monitoring of litellm's core hot paths.
Changes
tests/benchmarks/test_benchmarks.py): 16 benchmarks usingpytest-codspeedcovering the most performance-critical functions:.github/workflows/codspeed.yml): GitHub Actions workflow triggered on pushes tomain, pull requests, and manual dispatch. Uses OIDC authentication and CPU simulation mode.Next steps
main.tests/benchmarks/following the same@pytest.mark.benchmarkpattern.