Skip to content

Commit

Permalink
perf: lock-free cycle count increment (#1169)
Browse files Browse the repository at this point in the history
* chore: black_box bench

* perf: lock-free cycle counter increment
  • Loading branch information
jonathanpwang authored Jan 4, 2025
1 parent ac2f619 commit 3735d97
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions benchmarks/benches/regex_execute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use openvm_benchmarks::utils::build_bench_program;
use openvm_circuit::arch::{instructions::exe::VmExe, VmExecutor};
use openvm_keccak256_circuit::Keccak256Rv32Config;
Expand Down Expand Up @@ -33,7 +33,7 @@ fn benchmark_function(c: &mut Criterion) {
group.bench_function("execute", |b| {
b.iter(|| {
executor
.execute(exe.clone(), StdIn::from_bytes(&fe_bytes))
.execute(exe.clone(), black_box(StdIn::from_bytes(&fe_bytes)))
.unwrap();
})
});
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/examples/regex_execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ fn main() {

let data = include_str!("../programs/regex/regex_email.txt");

let timer = std::time::Instant::now();
executor
.execute(exe.clone(), StdIn::from_bytes(data.as_bytes()))
.unwrap();
println!("execute_time: {:?}", timer.elapsed());
}
4 changes: 3 additions & 1 deletion crates/vm/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod cycle_tracker;

#[derive(Clone, Debug, Default)]
pub struct VmMetrics {
pub cycle_count: usize,
pub chip_heights: Vec<(String, usize)>,
/// Maps (dsl_ir, opcode) to number of times opcode was executed
pub counts: BTreeMap<(Option<String>, String), usize>,
Expand Down Expand Up @@ -42,7 +43,7 @@ where
opcode: VmOpcode,
dsl_instr: Option<String>,
) {
counter!("total_cycles").increment(1u64);
self.metrics.cycle_count += 1;

if self.system_config().profiling {
let executor = self.chip_complex.inventory.get_executor(opcode).unwrap();
Expand All @@ -60,6 +61,7 @@ where
}

pub fn finalize_metrics(&mut self) {
counter!("total_cycles").absolute(self.metrics.cycle_count as u64);
counter!("main_cells_used")
.absolute(self.current_trace_cells().into_iter().sum::<usize>() as u64);

Expand Down

0 comments on commit 3735d97

Please sign in to comment.