-
Notifications
You must be signed in to change notification settings - Fork 747
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
Optimise concurrent block production #5368
Optimise concurrent block production #5368
Conversation
Not fully satisfied with the auto-drop explanation. In isolation Rust seems to be smarter than this: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a7689777c1941e424d91b1d1e4728c12 |
I found out some interesting things about the drop ordering. If the lock guard is borrowed mutably then the compiler will drop it "late". In my first example above we don't see the late drop behaviour because the borrow is immutable. Copying the structure of Lighthouse's code more closely reproduces the issue: This prints:
Modifying the first playground to do a mutable borrow only for the first lock, forces that lock to be dropped late, while the other lock is dropped early:
I think this could be a good Clippy lint! |
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.
Nice, interesting find! Looks like a low risk change to me.
@mergify queue |
🛑 The pull request has been removed from the queue
|
@mergify requeue |
✅ This pull request will be re-embarked automaticallyThe followup |
🛑 The pull request has been removed from the queue
|
@mergify dequeue |
✅ The pull request has been removed from the queue
|
@mergify requeue |
✅ This pull request will be re-embarked automaticallyThe followup |
🛑 The pull request has been removed from the queue
|
@mergify dequeue |
✅ The pull request has been removed from the queue
|
@mergify requeue |
✅ This pull request will be re-embarked automaticallyThe followup |
✅ The pull request has been merged automaticallyThe pull request has been merged automatically at f93844e |
Issue Addressed
Closes #5365
Proposed Changes
Speed up concurrent block production by being stricter about when locks are dropped. We were getting screwed by Rust's auto-drop logic which was not releasing locks in a timely way when they were obtained in the branches of an
if
.Prior to making this change you can see how staggered the block responses end up (running
blockdreamer
with 4x copies of the same node):Whereas after making this change (mainly the
block_production_state
locking change), they execute properly in parallel:The first request is 300ms faster than the subsequent 3 because it is able to use the single-use
block_production_state
cache.