Skip to content

ci: add CodSpeed latency benchmarks (baseline infra) - #70

Merged
yisding merged 4 commits into
mainfrom
claude/codspeed-benchmarks
Jun 14, 2026
Merged

yisding merged 4 commits into
mainfrom
claude/codspeed-benchmarks

Conversation

@yisding

@yisding yisding commented Jun 14, 2026

Copy link
Copy Markdown
Owner

What

Stand up the CodSpeed latency-benchmark infrastructure on its own, off main, so it establishes a pre-optimization baseline. The performance work in #69 can then be measured as real deltas against that baseline once #69 rebases on the updated main.

Contains only the benchmark infra — no library code changes:

  • benchmarks/test_latency_codspeed.pypytest-codspeed benchmarks for the latency paths: segment() (short/medium/large), should_wait_for_more(), StreamSegmenter.feed() (conservative/aggressive), and segment() for zh (CJK resplit path) and ru (Cyrillic abbreviation/resplit path). 10 benchmarks total.
  • .github/workflows/codspeed.yml — runs them on push to main and on PRs, authenticated via OIDC (id-token: write, no CODSPEED_TOKEN secret).
  • pyproject.toml / uv.lock — isolated bench dependency group (pytest + pytest-codspeed), separate from dev so the main test/lint matrix is untouched.

Why separate from #69

CodSpeed compares each commit against the default branch. If the benchmarks first landed inside #69, the baseline would already include the optimizations and the gains would be invisible. Landing this on main first captures the slow baseline; #69 then shows the speedups.

Isolation / safety

  • Main CI targets tests/ only, so it never collects this file or installs pytest-codspeed.
  • Benchmarks call only public APIs present on main (segment, should_wait_for_more, StreamSegmenter), so they run identically pre- and post-optimization.
  • Smoke-verified locally: all 10 collect and pass; ruff clean.

Setup

One-time: install the CodSpeed GitHub App on the repo (already done — the bot is commenting). OIDC means no secret to manage.

https://claude.ai/code/session_01RBqMKEGgvcZEAXLTPP5FiV


Generated by Claude Code

claude added 3 commits June 14, 2026 00:53
Add deterministic instruction-count benchmarks (pytest-codspeed) for the
latency-sensitive paths — segment(), should_wait_for_more(), and
StreamSegmenter.feed() — plus a CodSpeed workflow that runs them on push
and pull_request and posts per-PR regression/speedup deltas.

CodSpeed counts CPU instructions under instrumentation, so results are
stable on noisy shared GitHub runners (a real algorithmic regression like
the prior streaming double-segmentation shows up as an instruction delta,
not jitter). The benchmark tooling is isolated in a new 'bench'
dependency group and a dedicated benchmarks/test_latency_codspeed.py; the
main test matrix targets tests/ only, so it never collects the file or
installs the plugin.

Requires a maintainer to install the CodSpeed GitHub App and add a
CODSPEED_TOKEN secret; without it the job still runs but skips the upload.
Grant id-token: write and drop the token input from the CodSpeed action.
The action exchanges GitHub's short-lived OIDC token for upload
credentials, so no CODSPEED_TOKEN secret is required — only the CodSpeed
GitHub App install.
Cover non-Latin scripts so CodSpeed tracks regressions the English
samples would miss: zh exercises the whitespace-free CJK resplit path and
ru exercises the abbreviation/resplit rules over a non-ASCII alphabet.
@codspeed

codspeed Bot commented Jun 14, 2026

Copy link
Copy Markdown

Congrats! CodSpeed is installed 🎉

🆕 10 new benchmarks were detected.

You will start to see performance impacts in the reports once the benchmarks are run from your default branch.

Detected benchmarks


Open in CodSpeed

@yisding
yisding marked this pull request as ready for review June 14, 2026 00:56

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0dd081f62b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/codspeed.yml Outdated
A plain 'uv run' implicitly re-syncs the default dev group before pytest,
pulling unrelated dev tooling (mypy, nltk, hypothesis, ...) back into the
benchmark environment and running install work under CodSpeed
instrumentation. --no-sync runs in the exact bench-only environment the
prior 'uv sync --no-default-groups --group bench' step created.

Verified empirically: after a plain 'uv run', mypy reappears in the env;
with --no-sync it stays absent and all 10 benchmarks still run.
@yisding
yisding merged commit 772fda5 into main Jun 14, 2026
9 checks passed
@yisding
yisding deleted the claude/codspeed-benchmarks branch June 14, 2026 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants