-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add benchmark for simple transaction #577
Conversation
cd6f639
to
27d78ba
Compare
Although this solution works, there are some things which I don't like. Namely:
|
27d78ba
to
0667acd
Compare
Without having looked at the code too much, a few thoughts:
I don't think that's an issue. The need for
I probably wouldn't implement them as a test (especially since tests are usually not run in release mode). One other option is to write this as a small binary program which one can run via one of the
I don't think usage of
Why aren't we using |
const END_OF_PROLOGUE: u8 = 0; | ||
const END_OF_NODE_PROCESSING: u8 = 1; | ||
const END_OF_TX_SCRIPT_PROCESSING: u8 = 2; | ||
const END_OF_EPILOGUE: u8 = 3; |
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 would use the same scheme here as we do for events and error codes - i.e., the first 16 bits are set to 2 and the remaining 16 bits is a counter that increments (0, 1, 2 etc.).
I didn't manage to create a binary program from this test. Is there a way to do that without additional libraries? |
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.
Looks good! Thank you! I added some comments inline. One thing I'm starting to think is that maybe we should move capturing of the tracing info into the main TransactionHost
and bench host would be responsible only for printing it out.
We don't need a new library, but we would need to create a new binary (a Rust project can have many binaries). Btw, what are the cycle counts look like for some simple transaction? |
Currently for the default empty transaction we have this result:
|
The benchmark could be ran with this command:
Currently the output looks like so:
|
Could we do this as a transaction which consumes a |
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.
Thank you! Looks good! Not a full review - but I left some more comments inline.
Benchmarks could be executed with these commands:
|
bcd898c
to
f26171d
Compare
aa1de52
to
b9d6473
Compare
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.
Thank you! Looks good! I left a few more comments inline.
miden-tx/src/host/mod.rs
Outdated
/// Returns the ID of the consumed note being executed. | ||
fn get_current_note_id<S: ProcessState>(process: &S) -> Result<Option<NoteId>, ExecutionError> { | ||
let note_address_felt = process | ||
.get_mem_value(process.ctx(), CURRENT_CONSUMED_NOTE_PTR) | ||
.expect("current consumed note pointer invalid")[0]; | ||
let note_address: u32 = note_address_felt | ||
.try_into() | ||
.map_err(|_| ExecutionError::MemoryAddressOutOfBounds(note_address_felt.as_int()))?; | ||
Ok(process.get_mem_value(process.ctx(), note_address).map(NoteId::from)) | ||
} |
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.
In case we haven't start executing any note,
expect
will panic.
What about after note execution is done? In general, I still think it would be better to check the value of the current note pointer.
I wanted to return an
ExecutionError
, but looks like we don't have an error for the cases when the memory segment wasn't initialized. I can implement it, but I'm not sure that it is worth it since it is used only here.
I think returning Option
(the way you have it now) is fine.
benchmarks/Cargo.toml
Outdated
required-features = ["executable"] | ||
|
||
[features] | ||
default = ["std"] | ||
std = ["miden-lib/std", "miden-objects/std", "miden-tx/std", "vm-processor/std", "mock/std", "serde_json/std"] | ||
executable = ["std"] |
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.
Hmmm - I would have thought that something like this should work:
[[bin]]
name = "bench-tx"
path = "src/main.rs"
[dependencies]
miden-lib = { package = "miden-lib", path = "../miden-lib", version = "0.3" }
miden-objects = { package = "miden-objects", path = "../objects", version = "0.3" }
miden-tx = { package = "miden-tx", path = "../miden-tx", version = "0.3" }
mock = { package = "miden-mock", path = "../mock" }
serde_json = { package = "serde_json", version = "1.0" }
vm-processor = { workspace = true, features = ["std"] }
But I didn't test it.
Either way - I think we should try to figure this out as it may mean that there is something wrong somewhere.
miden-tx/src/host/tx_progress.rs
Outdated
// DATA PRINT | ||
// -------------------------------------------------------------------------------------------- | ||
|
||
pub fn to_json_string(&self) -> String { |
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 the struct could look something like:
pub struct TransactionBenchmark {
prologue: u32,
notes_processing: u32,
note_execution: Vec<(String, u32)>,
tx_script_processing: u32,
epilogue: u32,
}
And then we can implement TryFrom<TransactionProgress> for TransactionBenchmark
. This conversion should be pretty straight-forward.
@bobbinth @hackaugusto Yesterday I spent the whole day trying to reconstruct the JSON file to be able to track the changes commit by commit and create readable plots with this data. I came to the conclusion, that it is quite difficult to create few informative plots with this large amount of data: we have So, the general question sounds like: how do we want to show the benchmarking data? Do you know any solutions being able to track and aggregate a lot of data to compare effectiveness? (github-action-benchmark is a good solution, but it doesn't really suit us: it works with the output of actual |
I would move the plotting part into a separate issue. For this PR, just committing the JSON file (as you have now), is fine. |
6c109f8
to
6c5b84b
Compare
6c5b84b
to
499ddc5
Compare
499ddc5
to
4e284aa
Compare
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.
Looks good! Thank you! I left some small nits inline - once these are addressed, we can merge.
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.
All looks good! Thank you! Let's update changelog and merge.
Also, you may want to rebase from the latest next
as the changelog was updated there.
* feat: add benchmark for default transaction * refactor: use trace instead of emit, create wrapper for host * refactor: improve cycles print * refactor: add inline comments, change trace ids * chore: ignore the test untill it become a binary * refactor: organise cycles storing, add traces for each note * feat: create a simple cli for benchmark binary package * feat: create cargo-make script for benchmarking, move benchmarks back to the miden-tx * refactor: move TransactionProgress to the TransactionHost * feat: implement bench for P2ID note, add NoteId to the output * refactor: move last note id obtaining to the separate function * refactor: fix no-std build * refactor: update comments in main.masm file to be consistent with api.masm * feat: write benchmark results to the json file * refactor: move benchmarks to their own crate * refactor: add ability to run all benches * refactor: update bin name, dependencies; remove benches except all * chore: fix no-std build * refactor: rework TransactionProgress serialization * refactor: exclude bench-tx from no-std build, update dependencies * refactor: improve imports formatting * refactor: rework writing to json * chore: change visibility of miden-tx MockDataStore * chore: update CHANGELOG, create README for bench-tx
* feat: add benchmark for default transaction * refactor: use trace instead of emit, create wrapper for host * refactor: improve cycles print * refactor: add inline comments, change trace ids * chore: ignore the test untill it become a binary * refactor: organise cycles storing, add traces for each note * feat: create a simple cli for benchmark binary package * feat: create cargo-make script for benchmarking, move benchmarks back to the miden-tx * refactor: move TransactionProgress to the TransactionHost * feat: implement bench for P2ID note, add NoteId to the output * refactor: move last note id obtaining to the separate function * refactor: fix no-std build * refactor: update comments in main.masm file to be consistent with api.masm * feat: write benchmark results to the json file * refactor: move benchmarks to their own crate * refactor: add ability to run all benches * refactor: update bin name, dependencies; remove benches except all * chore: fix no-std build * refactor: rework TransactionProgress serialization * refactor: exclude bench-tx from no-std build, update dependencies * refactor: improve imports formatting * refactor: rework writing to json * chore: change visibility of miden-tx MockDataStore * chore: update CHANGELOG, create README for bench-tx
* feat: add benchmark for default transaction * refactor: use trace instead of emit, create wrapper for host * refactor: improve cycles print * refactor: add inline comments, change trace ids * chore: ignore the test untill it become a binary * refactor: organise cycles storing, add traces for each note * feat: create a simple cli for benchmark binary package * feat: create cargo-make script for benchmarking, move benchmarks back to the miden-tx * refactor: move TransactionProgress to the TransactionHost * feat: implement bench for P2ID note, add NoteId to the output * refactor: move last note id obtaining to the separate function * refactor: fix no-std build * refactor: update comments in main.masm file to be consistent with api.masm * feat: write benchmark results to the json file * refactor: move benchmarks to their own crate * refactor: add ability to run all benches * refactor: update bin name, dependencies; remove benches except all * chore: fix no-std build * refactor: rework TransactionProgress serialization * refactor: exclude bench-tx from no-std build, update dependencies * refactor: improve imports formatting * refactor: rework writing to json * chore: change visibility of miden-tx MockDataStore * chore: update CHANGELOG, create README for bench-tx
* feat: add benchmark for default transaction * refactor: use trace instead of emit, create wrapper for host * refactor: improve cycles print * refactor: add inline comments, change trace ids * chore: ignore the test untill it become a binary * refactor: organise cycles storing, add traces for each note * feat: create a simple cli for benchmark binary package * feat: create cargo-make script for benchmarking, move benchmarks back to the miden-tx * refactor: move TransactionProgress to the TransactionHost * feat: implement bench for P2ID note, add NoteId to the output * refactor: move last note id obtaining to the separate function * refactor: fix no-std build * refactor: update comments in main.masm file to be consistent with api.masm * feat: write benchmark results to the json file * refactor: move benchmarks to their own crate * refactor: add ability to run all benches * refactor: update bin name, dependencies; remove benches except all * chore: fix no-std build * refactor: rework TransactionProgress serialization * refactor: exclude bench-tx from no-std build, update dependencies * refactor: improve imports formatting * refactor: rework writing to json * chore: change visibility of miden-tx MockDataStore * chore: update CHANGELOG, create README for bench-tx
* feat: add benchmark for default transaction * refactor: use trace instead of emit, create wrapper for host * refactor: improve cycles print * refactor: add inline comments, change trace ids * chore: ignore the test untill it become a binary * refactor: organise cycles storing, add traces for each note * feat: create a simple cli for benchmark binary package * feat: create cargo-make script for benchmarking, move benchmarks back to the miden-tx * refactor: move TransactionProgress to the TransactionHost * feat: implement bench for P2ID note, add NoteId to the output * refactor: move last note id obtaining to the separate function * refactor: fix no-std build * refactor: update comments in main.masm file to be consistent with api.masm * feat: write benchmark results to the json file * refactor: move benchmarks to their own crate * refactor: add ability to run all benches * refactor: update bin name, dependencies; remove benches except all * chore: fix no-std build * refactor: rework TransactionProgress serialization * refactor: exclude bench-tx from no-std build, update dependencies * refactor: improve imports formatting * refactor: rework writing to json * chore: change visibility of miden-tx MockDataStore * chore: update CHANGELOG, create README for bench-tx
* feat: add benchmark for default transaction * refactor: use trace instead of emit, create wrapper for host * refactor: improve cycles print * refactor: add inline comments, change trace ids * chore: ignore the test untill it become a binary * refactor: organise cycles storing, add traces for each note * feat: create a simple cli for benchmark binary package * feat: create cargo-make script for benchmarking, move benchmarks back to the miden-tx * refactor: move TransactionProgress to the TransactionHost * feat: implement bench for P2ID note, add NoteId to the output * refactor: move last note id obtaining to the separate function * refactor: fix no-std build * refactor: update comments in main.masm file to be consistent with api.masm * feat: write benchmark results to the json file * refactor: move benchmarks to their own crate * refactor: add ability to run all benches * refactor: update bin name, dependencies; remove benches except all * chore: fix no-std build * refactor: rework TransactionProgress serialization * refactor: exclude bench-tx from no-std build, update dependencies * refactor: improve imports formatting * refactor: rework writing to json * chore: change visibility of miden-tx MockDataStore * chore: update CHANGELOG, create README for bench-tx
This PR implements the benchmark of the default transaction with default (mock) notes and with P2ID note.
This benchmark prints the number of cycles required to execute each stage of the transaction.