Skip to content

Commit eb45470

Browse files
committed
chore(bench): add benchmarks
1 parent 72af712 commit eb45470

6 files changed

Lines changed: 127 additions & 2 deletions

File tree

.github/workflows/benchmark.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Benchmark v14-alpha
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- v14-alpha
7+
push:
8+
branches:
9+
- v14-alpha
10+
11+
jobs:
12+
benchmark:
13+
name: Benchmark
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Install rust toolchain
19+
uses: dtolnay/rust-toolchain@stable
20+
- name: Set up cargo cache
21+
uses: Swatinem/rust-cache@v2
22+
- name: Install just
23+
uses: extractions/setup-just@v1
24+
with:
25+
just-version: 1.35.0
26+
- name: Install hyperfine
27+
run: cargo install hyperfine
28+
- name: Run Hyperfine
29+
run: just benchmark

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ target/
1111

1212
# Generated packages published to npm
1313
npm/packages
14+
15+
# Benchmarks
16+
dhat-heap.json
17+
flamegraph.svg

Cargo.lock

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ clap = { version = "4.5.40", features = ["cargo"] }
1717
color-print = "0.3.7"
1818
colored = "3.0.0"
1919
ctor = "0.4.2"
20+
dhat = { version = "0.3", optional = true }
2021
env_logger = "0.11.8"
2122
glob = "0.3.2"
2223
globset = "0.4.16"
@@ -34,3 +35,10 @@ serde_json = { version = "1.0.140", features = ["preserve_order"] }
3435
serde_yaml = "0.9"
3536
tokio = { version = "1", features = ["full"] }
3637
thiserror = "2.0.12"
38+
39+
[features]
40+
default = []
41+
dhat-heap = ["dhat"]
42+
43+
[profile.release]
44+
debug = true

justfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ install-system-dependencies:
1717
cargo +stable install cargo-llvm-cov
1818
# https://github.com/killercup/cargo-edit
1919
cargo +stable install cargo-edit
20+
# https://github.com/sharkdp/hyperfine
21+
cargo +stable install hyperfine
22+
# https://github.com/flamegraph-rs/flamegraph
23+
cargo +stable install flamegraph
2024

2125
# ==============================================================================
2226
# Write
@@ -72,6 +76,40 @@ run-release-action:
7276
run-ci-action:
7377
act --workflows .github/workflows/ci.yml pull_request
7478

79+
# ==============================================================================
80+
# Benchmark & Profile
81+
# ==============================================================================
82+
83+
# Build release version with debug symbols for profiling
84+
build-profile-release:
85+
cargo build --release
86+
87+
# Benchmark the current release build with hyperfine
88+
benchmark:
89+
#!/usr/bin/env bash
90+
set -euxo pipefail
91+
92+
just build-profile-release
93+
cd fixtures/fluid-framework
94+
hyperfine --warmup 2 --runs 4 --ignore-failure "../../target/release/syncpack list"
95+
96+
flamegraph:
97+
#!/usr/bin/env bash
98+
set -euxo pipefail
99+
100+
just build-profile-release
101+
cd fixtures/fluid-framework
102+
CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph -- list
103+
104+
dhat:
105+
#!/usr/bin/env bash
106+
set -euxo pipefail
107+
108+
just build-profile-release
109+
cd fixtures/fluid-framework
110+
cargo run --release --features dhat-heap -- lint
111+
echo "Memory profile saved to dhat-heap.json - view at https://nnethercote.github.io/dh_view/dh_view.html"
112+
75113
# ==============================================================================
76114
# Test
77115
# ==============================================================================

src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ use {
88
context::Context,
99
effects::list,
1010
log::{debug, error},
11+
std::process::exit,
1112
visit_formatting::visit_formatting,
1213
visit_packages::visit_packages,
1314
};
1415

16+
#[cfg(feature = "dhat-heap")]
17+
#[global_allocator]
18+
static ALLOC: dhat::Alloc = dhat::Alloc;
19+
1520
#[cfg(test)]
1621
#[path = "test/test.rs"]
1722
mod test;
@@ -37,7 +42,10 @@ mod visit_formatting;
3742
mod visit_packages;
3843

3944
#[tokio::main]
40-
async fn main() -> ! {
45+
async fn main() {
46+
#[cfg(feature = "dhat-heap")]
47+
let _profiler = dhat::Profiler::new_heap();
48+
4149
let cli = Cli::parse();
4250

4351
logger::init(&cli);
@@ -53,7 +61,7 @@ async fn main() -> ! {
5361
match packages.all.len() {
5462
0 => {
5563
error!("Found 0 package.json files");
56-
std::process::exit(1);
64+
exit(1);
5765
}
5866
len => debug!("Found {len} package.json files"),
5967
}
@@ -84,4 +92,7 @@ async fn main() -> ! {
8492
list::run(ctx);
8593
}
8694
};
95+
96+
#[cfg(feature = "dhat-heap")]
97+
drop(_profiler);
8798
}

0 commit comments

Comments
 (0)