-
Notifications
You must be signed in to change notification settings - Fork 38
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
trace_decoder
: Tweak batch size for small blocks
#576
Conversation
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.
There's a bunch of documentation in these issues. Could the knowledge there be transferred to the code?
It would be great to embed what motivates particular operations
How urgent is this change? I'd lean to an approach like this (though I haven't worked out the right approach for padding): /// Break `txns` into batches of length `hint`, prioritising creating at least two batches.
fn batch(mut txns: Vec<TxnInfo>, hint: NonZero<usize>) -> Vec<Vec<TxnInfo>> {
let n_batches = txns.iter().chunks(hint.get()).into_iter().count();
match (txns.len(), n_batches) {
// enough
(_, 2..) => txns
.into_iter()
.chunks(hint.get())
.into_iter()
.map(FromIterator::from_iter)
.collect(),
// not enough batches at `hint`, but enough real transactions
(2.., ..2) => {
let second = txns.split_off(txns.len() / 2);
vec![txns, second]
}
(0 | 1, _) => todo!("not enough real transactions - pad"),
}
} This would slot in well with my planned refactoring of the backend (and simple heuristics that might be forthcoming in #518): zk_evm/trace_decoder/src/lib.rs Lines 462 to 472 in e03997d
I'm happy to merge this as an interim measure if required - that refactoring is blocked on testing :^) |
It's not urgent, though it affects IMX benchmarks, as both their test load chain and real chain is having a relatively low number of txn / block, often inducing dummy proofs with the current approach.
Ideally this approach would be replaced by a dynamic batching based on txn state access count and state trie growth, though this requires additional measurements before assigning proper weights to determine the optimal batch sizes, hence this standalone PR. |
Simply halves the block in two chunks in case the initial batch size is too large, to prevent wasting ressources on dummy payloads.
closes #457
Follow-up work mentioned #518 will improve on this but this requires additional benchmarkings / analysis of how much our instances can optimally handle.