Add continuous benchmarking with CodSpeed - #1
Merged
Conversation
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
Author
Congrats! CodSpeed is installed 🎉
You will start to see performance impacts in the reports once the benchmarks are run from your default branch.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)codspeedworkflow, running on pull requests, pushes tomaster/release branches, andworkflow_dispatch(the latter allows CodSpeed to backfill initial data).walltimeinstrument, which is the only instrument currently supported for Go.id-token: write), so no token secret is needed.persist-credentials: false, explicit permissions,ubuntu-24.04runner, Go 1.26.4 viaactions/setup-go.hostjob intest.yml, the workflow symlinksvendor.mod/vendor.sumtogo.mod/go.sumso the benchmarks run in module mode against the vendored dependencies.go test -bench, to keep the CI run short. Thecli/command/formatter/tabwriterbenchmarks are intentionally left out: they are a copy of the upstreamtext/tabwriterbenchmarks 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:BenchmarkAddCommandscli/command/commandsBenchmarkLoadFromReadercli/configconfig.jsonBenchmarkParseRuncli/command/containerdocker runflags into container-, host- and networking-config (minimal and "many flags" cases)BenchmarkMountOptSetopts--mountvalues (volume, bind, tmpfs)BenchmarkContainerWritecli/command/formatterdocker psoutput (table, table with size, quiet, raw, json, custom format)BenchmarkImageWritecli/command/formatterdocker image lsoutput (table, table with digest, quiet, raw, json, custom format)BenchmarkParse/BenchmarkExecutetemplates--formattemplatesThe new benchmarks use
b.Loop()andb.ReportAllocs(), and are placed in the existing_test.gofiles next to the tests of the code they measure.Docs
README.md.TESTING.mddescribing 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 bymake lint) andgofumptare clean on the touched packages, andgo teststill passes for them.Note on runners
docker/cliis hosted on a personal account here, and CodSpeed macro runners are only available for organization repositories, so the workflow uses the standardubuntu-24.04runner. 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
masterestablish the performance baseline (or trigger the workflow manually to backfill data).go test -benchinvocation can be sharded across matrix jobs with-bench=<filter>.codspeed-macrofor much more stable walltime results.