How to track Rust compile times in CI
Everett Pompeii
Compile times can be a significant part of your build time, especially in Rust. Continuous Benchmarking is the practice of running benchmarks on every changeset to ensure the changes do not introduce a performance regressions. You can treat compile times as a benchmark and track them in CI to catch slow compile times. The easiest way to implement Continuous Benchmarking for Rust compile times is to use Bencher.
What is Bencher?
Bencher is a suite of continuous benchmarking tools. Have you ever had a performance regression impact your users? Bencher could have prevented that from happening. Bencher allows you to detect and prevent performance regressions before they make it to production.
- Run: Run your benchmarks locally or in CI using your favorite benchmarking tools. The
bencher
CLI simply wraps your existing benchmark harness and stores its results. - Track: Track the results of your benchmarks over time. Monitor, query, and graph the results using the Bencher web console based on the source branch, testbed, benchmark, and measure.
- Catch: Catch performance regressions in CI. Bencher uses state of the art, customizable analytics to detect performance regressions before they make it to production.
For the same reasons that unit tests are run in CI to prevent feature regressions, benchmarks should be run in CI with Bencher to prevent performance regressions. Performance bugs are bugs!
Steps for Bencher Cloud
- Create a Bencher Cloud account.
- Create an API token and add it to your CI as a secret.
- Create a workflow for your CI, like GitHub Actions or GitLab CI/CD.
- Install the Bencher CLI in your CI workflow.
-
Compile your Rust code with the
bencher run
subcommand in your CI workflow using the--build-time
flag with thejson
adapter.
Steps for Bencher Self-Hosted
- Create a Bencher Self-Hosted instance.
- Create an account on your Bencher Self-Hosted instance.
- Create an API token and add it to your CI as a secret.
- Create a workflow for your CI, like GitHub Actions or GitLab CI/CD.
- Install the Bencher CLI in your CI workflow. Make sure the CLI version matches the version of your Bencher Self-Hosted instance.
-
Compile your Rust code with the
bencher run
subcommand in your CI workflow using the--build-time
flag with thejson
adapter and setting the--host
option to your Bencher Self-Hosted instance URL.
⏱️ Build Time
The bencher run
CLI subcommand
can be used to track the build time (ie compile time) of your deliverables with the --build-time
flag.
Under the hood, bencher run
outputs the results as Bencher Metric Format (BMF) JSON.
It is therefore good practice to explicitly use the json
adapter.
For more details see how to track build time.
The build-time
Measure (ie seconds (s)
) is gathered.
Only the build time value (ie value
) is available.
Neither lower_value
nor upper_value
are collected.
The build-time
Measure is not created by default for all Projects.
However, when you use the --build-time
flag, this Measure will be automatically created for your Project.
Track your benchmarks in CI
Have you ever had a performance regression impact your users? Bencher could have prevented that from happening with continuous benchmarking.