-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Optimize process_ledger() #571
Optimize process_ledger() #571
Conversation
cargo test process_ledger_around_window -- --nocapture --test solana::bank |
Toly, wanna try this on your 96-core monster? I think this is 25% faster than the WINDOW_SIZE chunking version. |
src/bank.rs
Outdated
@@ -774,8 +812,16 @@ mod tests { | |||
|
|||
#[test] | |||
fn test_process_ledger_around_window_size() { | |||
// benchmark |
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.
How long does this take to execute? I run the few test suite constantly when developing via cargo watch 'test --libs'
and want that instantaneous feedback. If this takes more than a second to execute, I'd prefer you move in to a #[bench]
.
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 don't want to land the benchmark, it takes awhile
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.
Overall developer productively is a higher priority than fullnode startup time.
src/bank.rs
Outdated
result?; | ||
} | ||
} | ||
// TODO: verify this is ok in cases like: |
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.
Is this comment relevant anymore? In no, can you delete?
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 comment is still relevant, because I don't know the answer
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.
The answer is that we don't need to register any entry IDs for security purposes. We register them for only these reasons:
- So that the server doesn't need to compare against every signature there's ever been to ensure a transaction is not a duplicate. It can look up a set of signatures by
last_id
. - So that a client knows its transaction is only valid on a ledger containing its transaction's
last_id
or later. - So that a client knows that if a transaction wasn't accepted after a certain amount of time that it'll never be accepted.
src/bank.rs
Outdated
let tail = if tail.len() == WINDOW_SIZE as usize && tail_idx != 0 { | ||
let mut shift = Vec::with_capacity(WINDOW_SIZE as usize); | ||
shift.extend_from_slice(&tail[tail_idx..]); | ||
shift.extend_from_slice(&tail[0..tail_idx]); |
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.
Any way that can be implemented with higher-level Vec
functions. Maybe something like:
let mut (left, right) = v.split_at(tail_idx);
right.extend(left);
right
Alternatively, if you move this code into a separate function and write a test that demonstrates your intent here, I don't need to grok the implementation - just the test.
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.
what you've written is equivalent, with more mallocs()
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.
Right, it's more complex than the simplest correct version, which is why you'd create a separate function and test for it
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.
which would leave someone else the opportunity to either further optimize it and see that it still meets your requirements, as well as leave space for someone to add a benchmark and possibly determine the compiler already implements your optimization.
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.
fn test_rotate_vector() {
let test = vec![4, 1, 2, 3];
let etest = vec![4, 1, 2, 3];
let (left, right) = etest.split_at(1);
let mut right = right.to_vec();
right.extend(left);
assert_eq!(rotate_vector(test, 1), right);
let now = Instant::now();
for _ in 0..100_000 {
let etest = vec![4, 1, 2, 3];
let (left, right) = etest.split_at(1);
let mut right = right.to_vec();
right.extend(left);
}
eprintln!("split_at {}", duration_as_us(&now.elapsed()));
let now = Instant::now();
for _ in 0..100_000 {
let test = vec![4, 1, 2, 3];
rotate_vector(test, 1);
}
eprintln!("rotate {}", duration_as_us(&now.elapsed()));
}
split_at 97145
rotate 70582
d56b1c8
to
9682049
Compare
src/bank.rs
Outdated
let etest = vec![4, 1, 2, 3]; | ||
|
||
let (left, right) = etest.split_at(1); | ||
let mut right = right.to_vec(); |
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.
One less malloc: right.chain(left).to_vec()
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.
will have a go
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.
ug, fighting with types in rust to get chain() to work on right...
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.
878 | let right = right.chain(left).to_vec();
| ^^^^^
|
= note: the method `chain` exists but the following trait bounds were not satisfied:
`&mut &[{integer}] : std::iter::Iterator`
`&mut [{integer}] : std::iter::Iterator`
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.
Untested, but the chain docs suggest you need an iter()
:
right.iter().chain(left).to_vec()
…labs#571) Bumps [@solana/web3.js](https://github.com/solana-labs/solana-web3.js) from 0.78.2 to 0.78.3. - [Release notes](https://github.com/solana-labs/solana-web3.js/releases) - [Commits](solana-labs/solana-web3.js@v0.78.2...v0.78.3) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
No description provided.