Skip to content

Commit e67deab

Browse files
authored
perf(new-execution): optimize tracing memory functions (#1941)
- make `PAGE_SIZE` a const generic in `PagedVec` - use fixed size `[T; PAGE_SIZE]` array instead of slice - update `PagedVec::get` to return a copy of data and not allocate pages - reduce bounds checking - maybe we can just remove all bounds checking in `PagedVec` if we can guarantee the pointers are bounds-checked somewhere else? 🤔 - store a `u8` offset in `AccessMetadata` instead of a `u32` start pointer - pack `timestamp` and `block_size` values into a single `u32` - make `prev_access_time` function a bit more readable - use a stack allocated array (smallvec) instead of heap allocated vector for intermediate variables
1 parent 1f4eebd commit e67deab

File tree

8 files changed

+328
-223
lines changed

8 files changed

+328
-223
lines changed

.github/workflows/lints.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
# list of all unique features across workspace generated using:
4747
# cargo metadata --format-version=1 --no-deps | jq -r '.packages[].features | to_entries[] | .key' | sort -u | tr '\n' ' ' && echo ""
4848
# (exclude mimalloc since it conflicts with jemalloc)
49-
cargo clippy --all-targets --all --tests --features "aggregation bls12_381 bn254 build-binaries default entrypoint evm-prove evm-verify export-intrinsics export-libm function-span getrandom-unsupported halo2-compiler halo2curves heap-embedded-alloc jemalloc jemalloc-prof metrics nightly-features panic-handler parallel perf-metrics rust-runtime static-verifier std test-utils" -- -D warnings
49+
cargo clippy --all-targets --all --tests --features "aggregation bls12_381 bn254 build-elfs default entrypoint evm-prove evm-verify export-intrinsics export-libm function-span getrandom-unsupported halo2-compiler halo2curves heap-embedded-alloc jemalloc jemalloc-prof metrics nightly-features panic-handler parallel perf-metrics rust-runtime static-verifier std test-utils" -- -D warnings
5050
cargo clippy --all-targets --all --tests --no-default-features --features "mimalloc" -- -D warnings
5151
5252
- name: Run fmt, clippy for guest

benchmarks/execute/benches/execute.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ fn setup_leaf_verifier() -> (
298298
(vm, leaf_exe, input_stream)
299299
}
300300

301-
#[divan::bench(sample_count = 3)]
301+
#[divan::bench(sample_count = 5)]
302302
fn benchmark_leaf_verifier_execute(bencher: Bencher) {
303303
bencher
304304
.with_inputs(|| {
@@ -321,7 +321,7 @@ fn benchmark_leaf_verifier_execute(bencher: Bencher) {
321321
});
322322
}
323323

324-
#[divan::bench(sample_count = 3)]
324+
#[divan::bench(sample_count = 5)]
325325
fn benchmark_leaf_verifier_execute_metered(bencher: Bencher) {
326326
bencher
327327
.with_inputs(|| {
@@ -349,7 +349,7 @@ fn benchmark_leaf_verifier_execute_metered(bencher: Bencher) {
349349
});
350350
}
351351

352-
#[divan::bench(sample_count = 3)]
352+
#[divan::bench(sample_count = 5)]
353353
fn benchmark_leaf_verifier_execute_preflight(bencher: Bencher) {
354354
bencher
355355
.with_inputs(|| {

benchmarks/utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ openvm-stark-sdk = { workspace = true, optional = true }
2929

3030
[features]
3131
default = []
32-
build-binaries = []
32+
build-elfs = []
3333
generate-fixtures = [
3434
"dep:bitcode",
3535
"dep:openvm-circuit",

crates/vm/src/arch/execution_mode/metered/memory_ctx.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ impl<const PAGE_BITS: usize> MemoryCtx<PAGE_BITS> {
252252
}
253253
}
254254

255+
// TODO(ayush): check if batching is actually even faster
255256
/// Resolve all lazy updates of each memory access for memory adapters/poseidon2/merkle chip.
256257
#[inline(always)]
257258
pub(crate) fn lazy_update_boundary_heights(&mut self, trace_heights: &mut [u32]) {

0 commit comments

Comments
 (0)