Skip to content

Add continuous benchmarking with CodSpeed - #1

Merged
maksimtech merged 1 commit into
masterfrom
codspeed-wizard-1786967135660
Aug 17, 2026
Merged

Add continuous benchmarking with CodSpeed#1
maksimtech merged 1 commit into
masterfrom
codspeed-wizard-1786967135660

Conversation

@codspeed-hq

@codspeed-hq codspeed-hq Bot commented Aug 17, 2026

Copy link
Copy Markdown

What

Sets up continuous performance measurement for the CLI with CodSpeed, and adds benchmarks for a number of hot paths that were not covered yet.

Changes

CI (.github/workflows/codspeed.yml)

  • New codspeed workflow, running on pull requests, pushes to master/release branches, and workflow_dispatch (the latter allows CodSpeed to backfill initial data).
  • Uses the walltime instrument, which is the only instrument currently supported for Go.
  • Authentication uses OIDC (id-token: write), so no token secret is needed.
  • Follows the conventions of the existing workflows: actions pinned by commit hash with a version comment, persist-credentials: false, explicit permissions, ubuntu-24.04 runner, Go 1.26.4 via actions/setup-go.
  • Like the host job in test.yml, the workflow symlinks vendor.mod/vendor.sum to go.mod/go.sum so the benchmarks run in module mode against the vendored dependencies.
  • Only the packages that contain benchmarks are passed to go test -bench, to keep the CI run short. The cli/command/formatter/tabwriter benchmarks are intentionally left out: they are a copy of the upstream text/tabwriter benchmarks and include cases with 100k rows, which take minutes on their own.

Benchmarks

Existing benchmarks (BenchmarkStatsFormat, BenchmarkPrettyPrintInfo) are picked up as-is. Added benchmarks for paths that are hit on virtually every CLI invocation:

Benchmark Package What it covers
BenchmarkAddCommands cli/command/commands Constructing the cobra command-tree, done on every invocation of the CLI and when generating completion scripts and docs
BenchmarkLoadFromReader cli/config Loading config.json
BenchmarkParseRun cli/command/container Parsing docker run flags into container-, host- and networking-config (minimal and "many flags" cases)
BenchmarkMountOptSet opts Parsing --mount values (volume, bind, tmpfs)
BenchmarkContainerWrite cli/command/formatter Rendering docker ps output (table, table with size, quiet, raw, json, custom format)
BenchmarkImageWrite cli/command/formatter Rendering docker image ls output (table, table with digest, quiet, raw, json, custom format)
BenchmarkParse / BenchmarkExecute templates Parsing and executing --format templates

The new benchmarks use b.Loop() and b.ReportAllocs(), and are placed in the existing _test.go files next to the tests of the code they measure.

Docs

  • CodSpeed badge added to README.md.
  • A short "Benchmarks" section added to TESTING.md describing the naming convention, how to run benchmarks locally, and how to reproduce the CodSpeed run.

Verification

The full set was run locally with the CodSpeed runner in walltime mode (codspeed run --skip-upload --mode walltime -- go test -bench=. ...): 26 benchmarks across the 7 packages were discovered and measured, in roughly two minutes. golangci-lint run (v2.10.1, the version used by make lint) and gofumpt are clean on the touched packages, and go test still passes for them.

Note on runners

docker/cli is hosted on a personal account here, and CodSpeed macro runners are only available for organization repositories, so the workflow uses the standard ubuntu-24.04 runner. Walltime measurements on shared GitHub-hosted runners have significantly higher variance than on macro runners, so expect noisier results and treat small deltas with care. See https://codspeed.io/docs/instruments/walltime/index#usage-on-personal-github-accounts.

Next steps

  • Merge, then let the first run on master establish the performance baseline (or trigger the workflow manually to backfill data).
  • If the run turns out to be too slow as more benchmarks are added, the go test -bench invocation can be sharded across matrix jobs with -bench=<filter>.
  • If the repository is moved to an organization, switch the runner to codspeed-macro for much more stable walltime results.

Add a CodSpeed workflow that runs the Go benchmarks on every pull request
and push to master, using the walltime instrument.

Next to the benchmarks that already existed, add benchmarks for some of
the hot paths of the CLI:

- constructing the command-tree (done on every invocation of the CLI)
- loading the CLI configuration file
- parsing "docker run" flags
- parsing "--mount" flags
- formatting "docker ps" and "docker image ls" output
- parsing and executing "--format" templates
@codspeed-hq

codspeed-hq Bot commented Aug 17, 2026

Copy link
Copy Markdown
Author

Congrats! CodSpeed is installed 🎉

🆕 27 new benchmarks were detected.

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

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Detected benchmarks


ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.


Open in CodSpeed

@codspeed-hq
codspeed-hq Bot marked this pull request as ready for review August 17, 2026 12:06
@codspeed-hq
codspeed-hq Bot requested a review from maksimtech August 17, 2026 12:08
@maksimtech
maksimtech merged commit 061f89a into master Aug 17, 2026
97 of 99 checks passed
@maksimtech
maksimtech deleted the codspeed-wizard-1786967135660 branch August 17, 2026 12:09
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