Skip to content
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

Merged
merged 7 commits into from
Jul 11, 2018

Conversation

rob-solana
Copy link
Contributor

No description provided.

@rob-solana rob-solana added work in progress This isn't quite right yet noCI Suppress CI on this Pull Request labels Jul 10, 2018
@rob-solana rob-solana requested a review from garious July 10, 2018 18:28
@rob-solana
Copy link
Contributor Author

cargo test process_ledger_around_window -- --nocapture --test solana::bank

@rob-solana rob-solana requested a review from aeyakovenko July 10, 2018 23:00
@rob-solana
Copy link
Contributor Author

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
Copy link
Contributor

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].

Copy link
Contributor Author

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

Copy link
Contributor

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:
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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]);
Copy link
Contributor

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.

Copy link
Contributor Author

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()

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

@garious garious changed the title optimize process_ledger() Optimize process_ledger() Jul 10, 2018
@rob-solana rob-solana removed noCI Suppress CI on this Pull Request work in progress This isn't quite right yet labels Jul 10, 2018
@rob-solana rob-solana force-pushed the optimize-process_ledger branch from d56b1c8 to 9682049 Compare July 11, 2018 16:24
src/bank.rs Outdated
let etest = vec![4, 1, 2, 3];

let (left, right) = etest.split_at(1);
let mut right = right.to_vec();
Copy link
Contributor

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()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will have a go

Copy link
Contributor Author

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...

Copy link
Contributor Author

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`

Copy link
Contributor

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()

@rob-solana rob-solana merged commit 705720f into solana-labs:master Jul 11, 2018
@rob-solana rob-solana deleted the optimize-process_ledger branch July 12, 2018 16:29
vkomenda pushed a commit to vkomenda/solana that referenced this pull request Aug 29, 2021
…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>
AshwinSekar pushed a commit to AshwinSekar/solana that referenced this pull request Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants