atagen

matrix-rust-sdk

public
Star0
Watch0
ssh://brewery@pls.lobotomise.me:33/atagen/matrix-rust-sdk.git

Blame: benchmarks/README.md

7ff8adafe9e4atagen2026-10-22 12:30 UTC1
# Benchmarks for the rust-sdk crypto layer
7ff8adafe9e4atagen2026-10-22 12:30 UTC2
7ff8adafe9e4atagen2026-10-22 12:30 UTC3
This directory contains various benchmarks that test critical functionality in
7ff8adafe9e4atagen2026-10-22 12:30 UTC4
the crypto layer in the rust-sdk.
7ff8adafe9e4atagen2026-10-22 12:30 UTC5
7ff8adafe9e4atagen2026-10-22 12:30 UTC6
We're using [Criterion] for the benchmarks,
7ff8adafe9e4atagen2026-10-22 12:30 UTC7
[the full documentation for Criterion can be found here](https://bheisler.github.io/criterion.rs/book/criterion_rs.html).
7ff8adafe9e4atagen2026-10-22 12:30 UTC8
7ff8adafe9e4atagen2026-10-22 12:30 UTC9
## Running the benchmarks
7ff8adafe9e4atagen2026-10-22 12:30 UTC10
7ff8adafe9e4atagen2026-10-22 12:30 UTC11
The benchmark can be run by using the `bench` command of `cargo`:
7ff8adafe9e4atagen2026-10-22 12:30 UTC12
7ff8adafe9e4atagen2026-10-22 12:30 UTC13
```bash
7ff8adafe9e4atagen2026-10-22 12:30 UTC14
$ cargo bench
7ff8adafe9e4atagen2026-10-22 12:30 UTC15
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC16
7ff8adafe9e4atagen2026-10-22 12:30 UTC17
This will work from the workspace directory of the rust-sdk.
7ff8adafe9e4atagen2026-10-22 12:30 UTC18
7ff8adafe9e4atagen2026-10-22 12:30 UTC19
To lower compile times, you might be interested in using the `profiling`
7ff8adafe9e4atagen2026-10-22 12:30 UTC20
profile, that's optimized for a fair tradeoff between compile times and runtime
7ff8adafe9e4atagen2026-10-22 12:30 UTC21
performance:
7ff8adafe9e4atagen2026-10-22 12:30 UTC22
7ff8adafe9e4atagen2026-10-22 12:30 UTC23
```bash
7ff8adafe9e4atagen2026-10-22 12:30 UTC24
$ cargo bench --profile profiling
7ff8adafe9e4atagen2026-10-22 12:30 UTC25
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC26
7ff8adafe9e4atagen2026-10-22 12:30 UTC27
If you want to pass options to the benchmark
7ff8adafe9e4atagen2026-10-22 12:30 UTC28
[you'll need to specify the name of the benchmark](https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options):
7ff8adafe9e4atagen2026-10-22 12:30 UTC29
7ff8adafe9e4atagen2026-10-22 12:30 UTC30
```bash
7ff8adafe9e4atagen2026-10-22 12:30 UTC31
$ cargo bench --bench crypto_bench -- # Your options go here
7ff8adafe9e4atagen2026-10-22 12:30 UTC32
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC33
7ff8adafe9e4atagen2026-10-22 12:30 UTC34
If you want to run only a specific benchmark, pass the name of the
7ff8adafe9e4atagen2026-10-22 12:30 UTC35
benchmark as an argument:
7ff8adafe9e4atagen2026-10-22 12:30 UTC36
7ff8adafe9e4atagen2026-10-22 12:30 UTC37
```bash
7ff8adafe9e4atagen2026-10-22 12:30 UTC38
$ cargo bench --bench crypto_bench "Room key sharing/"
7ff8adafe9e4atagen2026-10-22 12:30 UTC39
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC40
7ff8adafe9e4atagen2026-10-22 12:30 UTC41
After the benchmarks are done, a HTML report can be found in
7ff8adafe9e4atagen2026-10-22 12:30 UTC42
`target/criterion/report/index.html`.
7ff8adafe9e4atagen2026-10-22 12:30 UTC43
7ff8adafe9e4atagen2026-10-22 12:30 UTC44
### Using a baseline for the benchmark
7ff8adafe9e4atagen2026-10-22 12:30 UTC45
7ff8adafe9e4atagen2026-10-22 12:30 UTC46
The benchmarks will by default compare the results to the previous run of the
7ff8adafe9e4atagen2026-10-22 12:30 UTC47
benchmark. If you are improving the performance of a specific feature and run
7ff8adafe9e4atagen2026-10-22 12:30 UTC48
the benchmark many times, it may be useful to store a baseline to compare
7ff8adafe9e4atagen2026-10-22 12:30 UTC49
against instead.
7ff8adafe9e4atagen2026-10-22 12:30 UTC50
7ff8adafe9e4atagen2026-10-22 12:30 UTC51
The `--save-baseline` switch can be used to create a baseline for the benchmark.
7ff8adafe9e4atagen2026-10-22 12:30 UTC52
7ff8adafe9e4atagen2026-10-22 12:30 UTC53
```bash
7ff8adafe9e4atagen2026-10-22 12:30 UTC54
$ cargo bench --bench crypto_bench -- --save-baseline libolm
7ff8adafe9e4atagen2026-10-22 12:30 UTC55
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC56
7ff8adafe9e4atagen2026-10-22 12:30 UTC57
After you make your changes you can use the baseline to compare the results like
7ff8adafe9e4atagen2026-10-22 12:30 UTC58
so:
7ff8adafe9e4atagen2026-10-22 12:30 UTC59
7ff8adafe9e4atagen2026-10-22 12:30 UTC60
```bash
7ff8adafe9e4atagen2026-10-22 12:30 UTC61
$ cargo bench --bench crypto_bench -- --baseline libolm
7ff8adafe9e4atagen2026-10-22 12:30 UTC62
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC63
7ff8adafe9e4atagen2026-10-22 12:30 UTC64
### Generating flame graphs for the benchmarks
7ff8adafe9e4atagen2026-10-22 12:30 UTC65
7ff8adafe9e4atagen2026-10-22 12:30 UTC66
The benchmarks support profiling and generating [Flame Graphs] while they run in
7ff8adafe9e4atagen2026-10-22 12:30 UTC67
profiling mode using [pprof].
7ff8adafe9e4atagen2026-10-22 12:30 UTC68
7ff8adafe9e4atagen2026-10-22 12:30 UTC69
Profiling usually requires root permissions, to avoid the need for root
7ff8adafe9e4atagen2026-10-22 12:30 UTC70
permissions you can adjust the value of `perf_event_paranoid`, e.g. the most
7ff8adafe9e4atagen2026-10-22 12:30 UTC71
permisive value is `-1`:
7ff8adafe9e4atagen2026-10-22 12:30 UTC72
7ff8adafe9e4atagen2026-10-22 12:30 UTC73
```bash
7ff8adafe9e4atagen2026-10-22 12:30 UTC74
$ echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid
7ff8adafe9e4atagen2026-10-22 12:30 UTC75
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC76
7ff8adafe9e4atagen2026-10-22 12:30 UTC77
To generate flame graphs feature, enable the profiling mode using the
7ff8adafe9e4atagen2026-10-22 12:30 UTC78
`--profile-time` command line flag:
7ff8adafe9e4atagen2026-10-22 12:30 UTC79
7ff8adafe9e4atagen2026-10-22 12:30 UTC80
```bash
7ff8adafe9e4atagen2026-10-22 12:30 UTC81
$ cargo bench --bench crypto_bench -- --profile-time=5
7ff8adafe9e4atagen2026-10-22 12:30 UTC82
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC83
7ff8adafe9e4atagen2026-10-22 12:30 UTC84
After the benchmarks are done, a flame graph for each individual benchmark can
7ff8adafe9e4atagen2026-10-22 12:30 UTC85
be found in `target/criterion/<name-of-benchmark>/profile/flamegraph.svg`.
7ff8adafe9e4atagen2026-10-22 12:30 UTC86
7ff8adafe9e4atagen2026-10-22 12:30 UTC87
[pprof]: https://docs.rs/pprof/0.5.0/pprof/index.html#
7ff8adafe9e4atagen2026-10-22 12:30 UTC88
[Criterion]: https://docs.rs/criterion/0.3.5/criterion/
7ff8adafe9e4atagen2026-10-22 12:30 UTC89
[Flame Graphs]: https://www.brendangregg.com/flamegraphs.html