Skip to content

Commit

Permalink
perf: re-order gas check
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Apr 28, 2024
1 parent 8cbc50c commit 86f531a
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 51 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Benchmark

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
LLVM_VERSION: "17" # Must be just the major version

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
iai:
runs-on: ubuntu-latest
env:
BASELINE: base
IAI_CALLGRIND_RUNNER: iai-callgrind-runner
steps:
- uses: actions/checkout@v4
- name: Install LLVM
run: sudo .github/scripts/install_llvm_ubuntu.sh ${{ env.LLVM_VERSION }}
- name: Install Valgrind
run: sudo apt update && sudo apt install valgrind
- uses: dtolnay/rust-toolchain@stable
- name: Install cargo-binstall
uses: taiki-e/install-action@cargo-binstall
- name: Install iai-callgrind-runner
run: |
echo "::group::Install"
version=$(cargo metadata --format-version=1 |\
jq '.packages[] | select(.name == "iai-callgrind").version' |\
tr -d '"'
)
cargo binstall iai-callgrind-runner --version $version --no-confirm --no-symlinks --force
echo "::endgroup::"
echo "::group::Verification"
which iai-callgrind-runner
echo "::endgroup::"
- name: Checkout base
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref || 'main' }}
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Save baseline
run: cargo bench -p revm-jit-cli --bench iai -- --save-baseline=$BASELINE
- name: Checkout PR
uses: actions/checkout@v4
with:
clean: false
- name: Compare PR benchmarks
run: cargo bench -p revm-jit-cli --bench iai -- --baseline=$BASELINE
43 changes: 1 addition & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches: [main]
pull_request:
branches: [main]

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -53,48 +54,6 @@ jobs:
- name: test
run: cargo test --all-features --workspace --profile ${{ matrix.profile }}

iai:
runs-on: ubuntu-latest
env:
BASELINE: base
IAI_CALLGRIND_RUNNER: iai-callgrind-runner
steps:
- uses: actions/checkout@v4
- name: Install LLVM
run: sudo .github/scripts/install_llvm_ubuntu.sh ${{ env.LLVM_VERSION }}
- name: Install Valgrind
run: sudo apt update && sudo apt install valgrind
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Install cargo-binstall
uses: taiki-e/install-action@cargo-binstall
- name: Install iai-callgrind-runner
run: |
echo "::group::Install"
version=$(cargo metadata --format-version=1 |\
jq '.packages[] | select(.name == "iai-callgrind").version' |\
tr -d '"'
)
cargo binstall iai-callgrind-runner --version $version --no-confirm --no-symlinks --force
echo "::endgroup::"
echo "::group::Verification"
which iai-callgrind-runner
echo "::endgroup::"
- name: Checkout base
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref || 'main' }}
- name: Save baseline
run: cargo bench -p revm-jit-cli --bench iai -- --save-baseline=$BASELINE
- name: Checkout PR
uses: actions/checkout@v4
with:
clean: false
- name: Compare PR benchmarks
run: cargo bench -p revm-jit-cli --bench iai -- --baseline=$BASELINE

feature-checks:
runs-on: ubuntu-latest
timeout-minutes: 30
Expand Down
26 changes: 20 additions & 6 deletions crates/revm-jit-cli/benches/iai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ binary_benchmark_group!(
);

fn setup_group(group: &mut BinaryBenchmarkGroup, is_ct: bool) {
let make_run = |name: &str| {
let make_run = |name: &str, small: bool| {
let mut args = Vec::with_capacity(3);
args.push(name);
// let out_dir = std::env::temp_dir().join("revm-jit-cli-iai");
// let so = out_dir.join(name).join("a.so");
if is_ct {
args.extend(["--aot", "--no-link"]);
// args.extend(["--aot", "--no-link", "-o", out_dir.to_str().unwrap()]);
} else {
args.push("1");
// args.extend(["1", "--shared-library", so.to_str().unwrap()]);
}
let arg = Arg::new(name, args);
let mut run = Run::with_cmd(CMD, arg);
Expand All @@ -35,22 +39,32 @@ fn setup_group(group: &mut BinaryBenchmarkGroup, is_ct: bool) {

let mut regression = RegressionConfig::default();
if is_ct {
regression.limits([(EventKind::EstimatedCycles, 10.0)]);
let cycles = if small { 50.0 } else { 20.0 };
regression.limits([(EventKind::EstimatedCycles, cycles)]);
} else {
regression.limits([(EventKind::EstimatedCycles, 5.0)]);
}
run.regression(regression);

if !is_ci() {
if small && !is_ci() {
let flamegraph = FlamegraphConfig::default();
run.flamegraph(flamegraph);
}

run
};
let benches = ["fibonacci", "counter", "push0_proxy", "weth", "hash_20k", "usdc_proxy"];
for bench in &benches {
group.bench(make_run(bench));
let benches = [
("fibonacci", true),
("counter", true),
("hash_20k", true),
("usdc_proxy", false),
("weth", false),
];
for (bench, small) in benches {
if !is_ct && !small {
continue;
}
group.bench(make_run(bench, small));
}
}

Expand Down
7 changes: 4 additions & 3 deletions crates/revm-jit/src/compiler/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1324,16 +1324,17 @@ impl<'a, B: Backend> FunctionCx<'a, B> {
return;
}

// `Gas::record_cost`
// Modified from `Gas::record_cost`.
let gas_remaining = self.load_gas_remaining();
let (res, overflow) = self.bcx.usub_overflow(gas_remaining, cost);
self.build_check(overflow, InstructionResult::OutOfGas);

let nomem = self.gas_remaining_nomem.load(&mut self.bcx, "gas_remaining_nomem");
let nomem = self.bcx.isub(nomem, cost);
self.gas_remaining_nomem.store(&mut self.bcx, nomem);

self.store_gas_remaining(res);
self.gas_remaining_nomem.store(&mut self.bcx, nomem);

self.build_check(overflow, InstructionResult::OutOfGas);
}

/*
Expand Down

0 comments on commit 86f531a

Please sign in to comment.