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 e3fd793
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ jobs:
- 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
Expand All @@ -86,6 +83,9 @@ jobs:
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
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 e3fd793

Please sign in to comment.