litellm/.github/workflows/codspeed.yml
yuneng-jiang dc0a852de9
ci: fit the pull request gate into five minutes (#52660)
* ci(unit): upload per-test durations as JUnit XML from each shard

Each unit shard now writes junit.xml and uploads it, so per-test timings can drive shard balancing and the choice of PR core tests.

* ci: fit the pull request gate into five minutes

Lint no longer compiles Rust. The basedpyright env skips installing the
project (same per-rule counts as main's published artifact, 93220) and runs
with four threads, and the python job installs only the dev tools. Import
safety and the OpenAPI gate move to a lint-runtime job in the unit workflow
that reuses the one shared bridge build.

The unit workflow drops coverage, schedules core shards with worksteal so
one big file no longer runs alone at the end, splits the router tests across
two 16-core shards, adds the frequent out-of-core catchers, and adds a
changed-tests job that runs the PR's changed unit tests plus the tests
mirroring its changed source files. The bridge build skips the gateway
wheel on core-mode pull requests, and merge smoke builds the bridge once
instead of once per job on a cache miss.

rust-test, rust-wheel, image-scan and CodeQL move to the integration
cadence, with a rust-tests label to run the Rust jobs on a pull request.
CodSpeed runs on main only.

* ci: build the Rust bridge on a 16-core runner (temporary cache-miss probe)

* ci: reuse the Rust bridge on cost-map-only pull requests

The bridge embeds the cost map, so a pull request that only edits the cost
map JSON used to rebuild Rust in both unit and smoke, about 7 minutes end to
end. The bridge cache key now splits the Rust inputs from the cost map, and a
cost-map-only pull request falls back to a bridge built from the same Rust
inputs with an older embedded map. cost-map-guard still loads the new JSON
through the Rust catalog, and main rebuilds the bridge on every cost map
change.

Unit's bridge job runs on a 16-core runner, which cut a measured cache miss
from 3.5 to 2.0 minutes for pull requests that do change Rust.

* ci: build smoke's Rust bridge on a 16-core runner
2026-11-18 14:41:04 -08:00

86 lines
2.7 KiB
YAML

name: CodSpeed Benchmarks
on:
push:
branches:
- main
paths:
- "litellm/**"
- "tests/benchmarks/**"
- "pyproject.toml"
- "uv.lock"
- ".github/workflows/codspeed.yml"
- ".github/actions/setup-uv-with-retries/**"
- ".github/actions/cache-cargo-build/**"
- ".github/scripts/uv_sync_with_retries.sh"
# Allow CodSpeed to trigger backtest performance analysis
# in order to generate initial data
workflow_dispatch:
permissions:
contents: read
id-token: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
benchmarks:
runs-on: ubuntu-24.04
timeout-minutes: 60
steps:
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.12"
- name: Set up uv
uses: ./.github/actions/setup-uv-with-retries
with:
version: "0.10.9"
- name: Cache the Rust build
uses: ./.github/actions/cache-cargo-build
with:
profile: release
# Build the wheel and resolve every dependency outside the CodSpeed
# runner: the same maturin build took 42 minutes inside `codspeed run`
# versus under 3 minutes as a plain step (LIT-6183)
- name: Build the release wheel
run: uv build --wheel --out-dir dist
- name: Install the wheel into the benchmark environment
run: |
UV_PROJECT_ENVIRONMENT="${RUNNER_TEMP}/benchmark-venv" .github/scripts/uv_sync_with_retries.sh --frozen --no-default-groups --group benchmarks --no-install-project --python 3.12
uv pip install --python "${RUNNER_TEMP}/benchmark-venv/bin/python" --no-deps dist/*.whl
- name: Collect benchmarks
env:
PYTEST_DISABLE_PLUGIN_AUTOLOAD: "1"
LITELLM_REQUIRE_INSTALLED_WHEEL: "1"
run: >
"${RUNNER_TEMP}/benchmark-venv/bin/python" -I -m pytest
--import-mode=importlib
-p pytest_codspeed.plugin
tests/benchmarks/
--codspeed
--collect-only -q
- name: Run benchmarks
uses: CodSpeedHQ/action@1c8ae4843586d3ba879736b7f6b7b0c990757fab # v4.12.1
with:
mode: simulation
run: >
env PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 LITELLM_REQUIRE_INSTALLED_WHEEL=1
"${RUNNER_TEMP}/benchmark-venv/bin/python" -I -m pytest
--import-mode=importlib
-p pytest_codspeed.plugin
tests/benchmarks/
--codspeed