-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: optimize brillig ToRadix
for common radices
#7365
Draft
TomAFrench
wants to merge
17
commits into
master
Choose a base branch
from
tf/optimize-brillig-radix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0d258b1
feat: optimize brillig `ToRadix` for common radices
TomAFrench abaca14
chore: cursed iterators
TomAFrench dc79f46
.
TomAFrench 6ca45a6
Merge branch 'master' into tf/optimize-brillig-radix
TomAFrench a899689
Merge branch 'master' into tf/optimize-brillig-radix
TomAFrench 02dcc1a
chore: add some basic brillig VM criterion benchmarks
TomAFrench ffb3786
chore: add benchmark for field byte decomposition
TomAFrench f318fa0
Merge branch 'master' into tf/optimize-brillig-radix
TomAFrench 7e2888c
.
TomAFrench cc7079a
Merge branch 'master' into tf/optimize-brillig-radix
TomAFrench 527d39b
Update acvm-repo/brillig_vm/benches/criterion.rs
TomAFrench 692d232
.
TomAFrench 2a901a9
chore: break up iterator chains
TomAFrench cf571bd
chore: refactor for better testing
TomAFrench a18667a
.
TomAFrench f8e3bff
.
TomAFrench 80f6a01
Merge branch 'master' into tf/optimize-brillig-radix
TomAFrench File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Benchmarks | ||
|
||
To generate flamegraphs for the execution of a specific benchmark, execute the following commands: | ||
|
||
```shell | ||
./scripts/benchmark_start.sh | ||
cargo bench -p brillig_vm --bench criterion -- --profile-time=30 | ||
./scripts/benchmark_stop.sh | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use acir::{ | ||
brillig::{self, MemoryAddress}, | ||
AcirField, FieldElement, | ||
}; | ||
use brillig_vm::VMStatus; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
use pprof::criterion::{Output, PProfProfiler}; | ||
use rand::Rng; | ||
|
||
use std::time::Duration; | ||
|
||
fn byte_decomposition(c: &mut Criterion) { | ||
let mut bytecode = vec![ | ||
// Radix | ||
brillig::Opcode::Const { | ||
destination: MemoryAddress::Direct(2), | ||
bit_size: brillig::BitSize::Integer(brillig::IntegerBitSize::U32), | ||
value: FieldElement::from(2u128), | ||
}, | ||
// Output pointer | ||
brillig::Opcode::Const { | ||
destination: MemoryAddress::Direct(3), | ||
bit_size: brillig::BitSize::Integer(brillig::IntegerBitSize::U32), | ||
value: FieldElement::from(5u128), | ||
}, | ||
// num_limbs | ||
brillig::Opcode::Const { | ||
destination: MemoryAddress::Direct(4), | ||
bit_size: brillig::BitSize::Integer(brillig::IntegerBitSize::U32), | ||
value: FieldElement::from(32u128), | ||
}, | ||
// output_bits | ||
brillig::Opcode::Const { | ||
destination: MemoryAddress::Direct(5), | ||
bit_size: brillig::BitSize::Integer(brillig::IntegerBitSize::U1), | ||
value: FieldElement::from(false), | ||
}, | ||
// calldata offset | ||
brillig::Opcode::Const { | ||
destination: MemoryAddress::Direct(0), | ||
bit_size: brillig::BitSize::Integer(brillig::IntegerBitSize::U32), | ||
value: FieldElement::from(0u128), | ||
}, | ||
// calldata size | ||
brillig::Opcode::Const { | ||
destination: MemoryAddress::Direct(1), | ||
bit_size: brillig::BitSize::Integer(brillig::IntegerBitSize::U32), | ||
value: FieldElement::from(1u128), | ||
}, | ||
brillig::Opcode::CalldataCopy { | ||
destination_address: MemoryAddress::Direct(0), | ||
size_address: MemoryAddress::Direct(1), | ||
offset_address: MemoryAddress::Direct(0), | ||
}, | ||
]; | ||
|
||
for _ in 0..1 { | ||
bytecode.push(brillig::Opcode::BlackBox(brillig::BlackBoxOp::ToRadix { | ||
input: MemoryAddress::Direct(0), | ||
radix: MemoryAddress::Direct(2), | ||
output_pointer: MemoryAddress::Direct(3), | ||
num_limbs: MemoryAddress::Direct(4), | ||
output_bits: MemoryAddress::Direct(5), | ||
})); | ||
} | ||
TomAFrench marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
bench_bytecode(c, "byte_decomposition", &bytecode); | ||
} | ||
|
||
fn bench_bytecode<F: AcirField>( | ||
c: &mut Criterion, | ||
benchmark_name: &str, | ||
bytecode: &[brillig::Opcode<F>], | ||
) { | ||
c.bench_function(benchmark_name, |b| { | ||
b.iter_batched( | ||
|| { | ||
let input = rand::thread_rng().gen::<u128>(); | ||
let input_field = F::from(input); | ||
let mut vm = brillig_vm::VM::new( | ||
vec![input_field], | ||
bytecode, | ||
&acvm_blackbox_solver::StubbedBlackBoxSolver(false), | ||
false, | ||
); | ||
|
||
// Process up to the last opcode which we want to benchmark | ||
for _ in 0..bytecode.len() - 1 { | ||
vm.process_opcode(); | ||
} | ||
vm | ||
}, | ||
|mut vm| { | ||
let status = vm.process_opcodes(); | ||
assert!(matches!(status, VMStatus::Finished { .. })) | ||
}, | ||
criterion::BatchSize::SmallInput, | ||
); | ||
}); | ||
} | ||
|
||
criterion_group! { | ||
name = execution_benches; | ||
config = Criterion::default().sample_size(20).measurement_time(Duration::from_secs(20)).with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); | ||
targets = byte_decomposition | ||
} | ||
criterion_main!(execution_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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these benchmarks meant to be temporary or permanent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can have them be permanent.