Update iai benchmarks to use iai-callgrind (#7534)

This commit is contained in:
Abner Zheng
2024-04-10 22:48:51 +08:00
committed by GitHub
parent b9c677ef9a
commit 8d3085617d
4 changed files with 96 additions and 25 deletions

View File

@ -40,6 +40,13 @@ jobs:
main -> target main -> target
pr -> target pr -> target
cache-on-failure: true cache-on-failure: true
- name: Install iai-callgrind-runner
run: |
version=$(cargo metadata --format-version=1 |\
jq '.packages[] | select(.name == "iai-callgrind").version' |\
tr -d '"'
)
cargo install iai-callgrind-runner --version $version
- name: Generate test vectors - name: Generate test vectors
run: | run: |
cargo run --bin reth --manifest-path main/Cargo.toml -- test-vectors tables cargo run --bin reth --manifest-path main/Cargo.toml -- test-vectors tables

61
Cargo.lock generated
View File

@ -1021,12 +1021,15 @@ dependencies = [
"itertools 0.12.1", "itertools 0.12.1",
"lazy_static", "lazy_static",
"lazycell", "lazycell",
"log",
"prettyplease",
"proc-macro2", "proc-macro2",
"quote", "quote",
"regex", "regex",
"rustc-hash", "rustc-hash",
"shlex", "shlex",
"syn 2.0.58", "syn 2.0.58",
"which",
] ]
[[package]] [[package]]
@ -3270,6 +3273,15 @@ dependencies = [
"hmac 0.8.1", "hmac 0.8.1",
] ]
[[package]]
name = "home"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
dependencies = [
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "hostname" name = "hostname"
version = "0.3.1" version = "0.3.1"
@ -3491,10 +3503,39 @@ dependencies = [
] ]
[[package]] [[package]]
name = "iai" name = "iai-callgrind"
version = "0.1.1" version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71a816c97c42258aa5834d07590b718b4c9a598944cd39a52dc25b351185d678" checksum = "e99bf26f496b13ac6273014f40afda46a233fbfb0289ce50fb4daaad2f2ffc80"
dependencies = [
"bincode",
"bindgen",
"cc",
"iai-callgrind-macros",
"iai-callgrind-runner",
"regex",
]
[[package]]
name = "iai-callgrind-macros"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2a4bb39225592c0a28cfca6f70af52ebd8da23f533c2cdd0a3329c1fa252d56"
dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn 2.0.58",
]
[[package]]
name = "iai-callgrind-runner"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c23a951b9eccaa1e38556d27473d1462a9c247a27961812edcaac156af861282"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "iana-time-zone" name = "iana-time-zone"
@ -6173,7 +6214,7 @@ dependencies = [
"criterion", "criterion",
"derive_more", "derive_more",
"eyre", "eyre",
"iai", "iai-callgrind",
"metrics", "metrics",
"modular-bitfield", "modular-bitfield",
"once_cell", "once_cell",
@ -9571,6 +9612,18 @@ dependencies = [
"rustls-pki-types", "rustls-pki-types",
] ]
[[package]]
name = "which"
version = "4.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
dependencies = [
"either",
"home",
"once_cell",
"rustix",
]
[[package]] [[package]]
name = "widestring" name = "widestring"
version = "1.1.0" version = "1.1.0"

View File

@ -60,7 +60,7 @@ test-fuzz.workspace = true
pprof = { workspace = true, features = ["flamegraph", "frame-pointer", "criterion"] } pprof = { workspace = true, features = ["flamegraph", "frame-pointer", "criterion"] }
criterion.workspace = true criterion.workspace = true
iai = "0.1.1" iai-callgrind = "0.10.2"
arbitrary = { workspace = true, features = ["derive"] } arbitrary = { workspace = true, features = ["derive"] }
proptest.workspace = true proptest.workspace = true

View File

@ -1,38 +1,42 @@
#![allow(missing_docs, non_snake_case, unreachable_pub)] #![allow(missing_docs, non_snake_case, unreachable_pub)]
use iai_callgrind::{
library_benchmark, library_benchmark_group, LibraryBenchmarkConfig, RegressionConfig,
};
use paste::paste; use paste::paste;
use reth_db::table::{Compress, Decode, Decompress, Encode, Table}; use reth_db::table::{Compress, Decode, Decompress, Encode, Table};
mod utils; mod utils;
use utils::*; use utils::*;
macro_rules! impl_iai_inner { macro_rules! impl_iai_callgrind_inner {
( (
$(($name:ident, $mod:ident, $compress:ident, $decompress:ident, $encode:ident, $decode:ident, $seqread:ident, $randread:ident, $seqwrite:ident, $randwrite:ident))+ $(($name:ident, $group_name:ident, $mod:ident, $compress:ident, $decompress:ident, $encode:ident, $decode:ident, $seqread:ident, $randread:ident, $seqwrite:ident, $randwrite:ident))+
) => { ) => {
use std::hint::black_box;
$( $(
mod $mod { #[library_benchmark]
use super::*;
use std::hint::black_box;
pub fn $compress() { pub fn $compress() {
for (_, _, v, _) in black_box(load_vectors::<reth_db::tables::$name>()) { for (_, _, v, _) in black_box(load_vectors::<reth_db::tables::$name>()) {
black_box(v.compress()); black_box(v.compress());
} }
} }
#[library_benchmark]
pub fn $decompress() { pub fn $decompress() {
for (_, _, _, comp) in black_box(load_vectors::<reth_db::tables::$name>()) { for (_, _, _, comp) in black_box(load_vectors::<reth_db::tables::$name>()) {
let _ = black_box(<reth_db::tables::$name as Table>::Value::decompress(comp)); let _ = black_box(<reth_db::tables::$name as Table>::Value::decompress(comp));
} }
} }
#[library_benchmark]
pub fn $encode() { pub fn $encode() {
for (k, _, _, _) in black_box(load_vectors::<reth_db::tables::$name>()) { for (k, _, _, _) in black_box(load_vectors::<reth_db::tables::$name>()) {
black_box(k.encode()); black_box(k.encode());
} }
} }
#[library_benchmark]
pub fn $decode() { pub fn $decode() {
for (_, enc, _, _) in black_box(load_vectors::<reth_db::tables::$name>()) { for (_, enc, _, _) in black_box(load_vectors::<reth_db::tables::$name>()) {
let _ = black_box(<reth_db::tables::$name as Table>::Key::decode(enc)); let _ = black_box(<reth_db::tables::$name as Table>::Key::decode(enc));
@ -50,34 +54,41 @@ macro_rules! impl_iai_inner {
#[allow(dead_code)] #[allow(dead_code)]
pub fn $randwrite() {} pub fn $randwrite() {}
}
use $mod::*;
library_benchmark_group!(
name = $group_name;
config = LibraryBenchmarkConfig::default()
.regression(
RegressionConfig::default().fail_fast(false)
);
benchmarks =
$compress,
$decompress,
$encode,
$decode,
);
)+ )+
iai::main!( iai_callgrind::main!(
$( config = LibraryBenchmarkConfig::default();
$compress, library_benchmark_groups = $($group_name),+);
$decompress,
$encode,
$decode,
)+
);
}; };
} }
macro_rules! impl_iai { macro_rules! impl_iai_callgrind {
($($name:ident),+) => { ($($name:ident),+) => {
paste! { paste! {
impl_iai_inner!( impl_iai_callgrind_inner!(
$( $(
( $name, [<$name _mod>], [<$name _ValueCompress>], [<$name _ValueDecompress>], [<$name _ValueEncode>], [<$name _ValueDecode>], [<$name _SeqRead>], [<$name _RandomRead>], [<$name _SeqWrite>], [<$name _RandomWrite>]) ( $name, [<$name _group>],[<$name _mod>], [<$name _ValueCompress>], [<$name _ValueDecompress>], [<$name _ValueEncode>], [<$name _ValueDecode>], [<$name _SeqRead>], [<$name _RandomRead>], [<$name _SeqWrite>], [<$name _RandomWrite>])
)+ )+
); );
} }
}; };
} }
impl_iai!( impl_iai_callgrind!(
CanonicalHeaders, CanonicalHeaders,
HeaderTerminalDifficulties, HeaderTerminalDifficulties,
HeaderNumbers, HeaderNumbers,