Hyperlight uses the Criterion framework to run and analyze benchmarks. A benefit to this framework is that it doesn't require the nightly toolchain.
-
Daily (scheduled)
- Benchmarks run daily via
DailyBenchmarks.yml. Results are stored as workflow artifacts with 90-day retention, and are what pull requests are compared against. The daily run also benchmarks mshv3 on the MSHV 6.18 kernel pools, asbenchmarks_Linux_mshv3-6.18_<cpu_vendor>.
sandboxes/create_sandbox time: [33.803 ms 34.740 ms 35.763 ms] change: [+0.7173% +3.7017% +7.1346%] (p = 0.03 < 0.05) Change within noise threshold.* - Benchmarks run daily via
-
For each pull request
- Benchmarks run on every hypervisor and cpu vendor in
ValidatePullRequest.yml, which invokesdep_benchmarks.yml. The results are reported against the daily benchmarks of the commit the pull request branched from, and posted as a comment.
- Benchmarks run on every hypervisor and cpu vendor in
-
For each release
- For each release, benchmarks are run as part of the release pipeline in
CreateRelease.yml, which invokesdep_benchmarks.yml. These benchmark results are compared to the previous release, and are uploaded as part of the "Release assets" on the GitHub release page.
- For each release, benchmarks are run as part of the release pipeline in
Currently, benchmarks are run on windows, linux-kvm (ubuntu), and linux-hyperv (mariner). Only release builds are benchmarked, not debug.
When running cargo bench -- --save-baseline my_baseline, criterion runs all benchmarks defined in src/hyperlight_host/benches/, prints the results to the stdout, as well as produces several artifacts. All artifacts can be found in target/criterion/. For each benchmarking group, for each benchmark, a subfolder with the name of the benchmark is created. This folder in turn contains folders my_baseline, new and report. When running cargo bench, criterion always creates new and report, which always contains the most recent benchmark result and html report, but because we provided the --save-baseline flag, we also have a my_baseline folder, which is an exact copy of new. Moreover, if this my_baseline folder already existed before we ran cargo bench -- --save-baseline my_baseline, criterion would also compare the benchmark results with the old my_baseline folder, and then overwrite the folder.
The first time we run cargo bench -- --save-baseline my_baseline (starting with a clean project), we get the following structure.
target/criterion/
|-- report
`-- sandboxes
|-- create_sandbox
| |-- my_baseline
| |-- new
| `-- report
|-- create_sandbox_and_call_context
| |-- my_baseline
| |-- new
| `-- report
`-- report
If we run the exact same command again, we get
target/criterion/
|-- report
`-- sandboxes
|-- create_sandbox
| |-- change
| |-- my_baseline
| |-- new
| `-- report
|-- create_sandbox_and_call_context
| |-- change
| |-- my_baseline
| |-- new
| `-- report
`-- report
Note that it overwrote the previous my_baseline with the new result. But notably, there is a new change folder, which contains the benchmarking difference between the two runs. In addition, on stdout you'll also find a comparison to our previous my_baseline run.
time: [40.434 ms 40.777 ms 41.166 ms]
change: [+0.0506% +1.1399% +2.2775%] (p = 0.06 > 0.05)
No change in performance detected.
Found 1 outliers among 100 measurements (1.00%)
Note that Criterion does not differ between release and debug/dev benchmark results, so it's up to the developer to make sure baselines of the same config are compared.
Use just bench to run benchmarks with release builds (the only supported configuration). Comparing local benchmark results to the ones CI measures doesn't say much, since you'd be using different hardware, but cargo ci bench-report fetches them for you.
cargo ci bench-report renders the comparison. --candidate and --baseline say where each side comes from: a criterion directory, run:<ID> for a CI run, pr:<NUMBER> for the latest run of a pull request, commit:<SHA> for the benchmarks of the default branch taken at or before a commit, base-of:<NUMBER> for the ones taken where a pull request branched, or release:<TAG> for the ones a release carries. Criterion keeps the last run of a directory in new and the one before it in base, so a directory on its own reports the last run against the previous one.
The default branch is benchmarked daily rather than per commit, so commit: and base-of: take the closest run that does not carry changes the commit never had. A pull request defaults to the branch point it was built from, since nothing within its own results says what they mean. Workflow artifacts are swept away after 90 days, so reaching further back means the results a release carries. CI results cover every hypervisor and cpu vendor, so results are paired with the ones measured on the same kind of machine. A run records its own operating system, cpu vendor and hypervisor, and CI artifacts are named after the configuration that produced them. Results that fit no counterpart, or several, are reported without a comparison.
# a pull request against the branch point it was built from
cargo ci bench-report --candidate pr:1529
# this machine against the configuration in CI that matches it
cargo ci bench-report --baseline pr:1529
# this machine against what a release measured
cargo ci bench-report --baseline release:v0.17.0Important: The just bench command uses release builds by default to ensure meaningful performance measurements. For profiling purposes, you can compile benchmarks with debug symbols by running cargo bench directly.