-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: improve internal profiler
- Accumulate runtimes, improving profiling accuracy of - loops (like in `Stark::verify()`), and - repeated runs (like in benchmarks). - Completely disable profiling in optimized builds. This removes all runtime overhead from the performance-critical path. The profiler is enabled if - `cfg!(debug_assertions)` is true or - `--no-default-features` is passed to `cargo`. - Use a global profiler instance to avoid passing the profiler as an explicit argument. - Combine the `prof_start!` and `prof_stop!` macros into one `profiler!` macro. BREAKING CHANGE: Remove internal profiler from the public API.
- Loading branch information
Showing
18 changed files
with
818 additions
and
756 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,44 @@ | ||
use criterion::criterion_group; | ||
use criterion::criterion_main; | ||
use criterion::BenchmarkId; | ||
use criterion::Criterion; | ||
|
||
use triton_vm::profiler::TritonProfiler; | ||
use triton_vm::prelude::NonDeterminism; | ||
use triton_vm::prelude::PublicInput; | ||
use triton_vm::proof::Claim; | ||
use triton_vm::stark::Stark; | ||
use triton_vm::table::master_table::TableId; | ||
use triton_vm::triton_program; | ||
|
||
criterion_main!(benches); | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = Criterion::default().sample_size(10); | ||
targets = prove_halt | ||
} | ||
|
||
/// cargo criterion --bench prove_halt | ||
fn prove_halt(criterion: &mut Criterion) { | ||
fn prove_halt(c: &mut Criterion) { | ||
let program = triton_program!(halt); | ||
let (aet, output) = program.trace_execution([].into(), [].into()).unwrap(); | ||
let (aet, output) = program | ||
.trace_execution(PublicInput::default(), NonDeterminism::default()) | ||
.unwrap(); | ||
|
||
let stark = Stark::default(); | ||
let claim = Claim::about_program(&program).with_output(output); | ||
let mut profiler = Some(TritonProfiler::new("Prove Halt")); | ||
let proof = stark.prove(&claim, &aet, &mut profiler).unwrap(); | ||
let mut profiler = profiler.unwrap(); | ||
profiler.finish(); | ||
let proof = stark.prove(&claim, &aet).unwrap(); | ||
|
||
let bench_id = BenchmarkId::new("ProveHalt", 0); | ||
let mut group = criterion.benchmark_group("prove_halt"); | ||
group.sample_size(10); | ||
group.bench_function(bench_id, |bencher| { | ||
bencher.iter(|| { | ||
let _proof = stark.prove(&claim, &aet, &mut None); | ||
}); | ||
triton_vm::profiler::start("Prove Halt"); | ||
c.bench_function("Prove Halt", |b| { | ||
b.iter(|| stark.prove(&claim, &aet).unwrap()) | ||
}); | ||
group.finish(); | ||
let profile = triton_vm::profiler::finish(); | ||
|
||
let padded_height = proof.padded_height().unwrap(); | ||
let fri = stark.derive_fri(padded_height).unwrap(); | ||
let report = profiler | ||
.report() | ||
.with_cycle_count(aet.processor_trace.nrows()) | ||
let profile = profile | ||
.with_cycle_count(aet.height_of_table(TableId::Processor)) | ||
.with_padded_height(padded_height) | ||
.with_fri_domain_len(fri.domain.length); | ||
eprintln!("{report}"); | ||
eprintln!("{profile}"); | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = Criterion::default(); | ||
targets = prove_halt | ||
} | ||
|
||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.