codspeed workflow (pydantic/pydantic)
The codspeed workflow from pydantic/pydantic, explained and optimized by Latchkey.
CI health: D - needs work
Point runs-on at Latchkey and get caching, run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the codspeed workflow from the pydantic/pydantic repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: codspeed
on:
push:
branches:
- main
pull_request:
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:
env:
UV_FROZEN: true
UV_PYTHON: 3.14
permissions:
contents: read
jobs:
codspeed-profiling:
name: CodSpeed profiling
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
# Using this action is still necessary for CodSpeed to work:
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: ${{ env.UV_PYTHON }}
- name: install deps
run: uv sync --all-packages --group testing-extra --extra email --frozen
- name: install rust stable
# no release versioning, see https://github.com/dtolnay/rust-toolchain/issues/180
uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88
with:
components: llvm-tools
toolchain: stable
- name: cache rust
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
with:
workspaces: pydantic-core
- name: install pydantic-core with profiling symbols
run: |
cd pydantic-core
uv pip uninstall pytest-speed
make build-pgo
env:
CARGO_PROFILE_RELEASE_DEBUG: 'line-tables-only'
CARGO_PROFILE_RELEASE_STRIP: 'false'
- name: Run CodSpeed benchmarks
uses: CodSpeedHQ/action@a4a36bb07c0638b0b4ca52bf1f3dad1b4289e52f # v4.18.1
with:
mode: simulation
run: uv run --no-sync pytest ./tests/benchmarks ./tests/pydantic_core/benchmarks --codspeed
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
name: codspeed on: push: branches: - main pull_request: # `workflow_dispatch` allows CodSpeed to trigger backtest # performance analysis in order to generate initial data. workflow_dispatch: env: UV_FROZEN: true UV_PYTHON: 3.14 permissions: contents: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: codspeed-profiling: timeout-minutes: 30 name: CodSpeed profiling runs-on: latchkey-small steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: persist-credentials: false - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 # Using this action is still necessary for CodSpeed to work: - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 with: cache: 'pip' python-version: ${{ env.UV_PYTHON }} - name: install deps run: uv sync --all-packages --group testing-extra --extra email --frozen - name: install rust stable # no release versioning, see https://github.com/dtolnay/rust-toolchain/issues/180 uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 with: components: llvm-tools toolchain: stable - name: cache rust uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1 with: workspaces: pydantic-core - name: install pydantic-core with profiling symbols run: | cd pydantic-core uv pip uninstall pytest-speed make build-pgo env: CARGO_PROFILE_RELEASE_DEBUG: 'line-tables-only' CARGO_PROFILE_RELEASE_STRIP: 'false' - name: Run CodSpeed benchmarks uses: CodSpeedHQ/action@a4a36bb07c0638b0b4ca52bf1f3dad1b4289e52f # v4.18.1 with: mode: simulation run: uv run --no-sync pytest ./tests/benchmarks ./tests/pydantic_core/benchmarks --codspeed
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.