-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Reduce cs_main lock accumulation during GUI startup #19011
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
Conversation
Concept ACK and approach half-ACK. This seems like a good change to make with the caveat that it shouldn't be necessary to add new global Instead of having This would mean instead of having a new [1] Suggesting |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
I thought about this and agree that this PRs solution might not be very elegant. The approach you described should work,.. the main difference is that the networking is running then already which might lead to additional cs_main locking (within this PR, we fetch the information before we start the networking). Your approach would also require at least another locking of cs_main (right?). What I was looking for was using an existing cs_main lock to gather the information required for the GUI (avoid collecting the same information into concurrency-safe primitives over and over). |
Oh, I thought I might have been missing something. Now I understand why this is saving tip information inside AppInitMain. I think you're right that there is a possibility of cs_main blocking if information is retrieved after the AppInitMain call instead of during it (though in this case it still wouldn't be happening on the qt event loop thread, so might not be an actual problem). If this is a problem, it could be solved most directly by having AppInitMain just return tip information, instead of stashing it into a global struct to be retrieved later. Using something like |
2cf87fe
to
4ef682a
Compare
Thanks for the feedback @ryanofsky. |
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.
Code review ACK 4ef682a. Works exactly as discussed, no issues at all that I could see
4ef682a
to
ded3edd
Compare
Force pushed a fix for the qt test apptests (missed the new |
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.
Code review ACK ded3edd. Just apptests type registration added since last review
@@ -66,6 +66,7 @@ void AppTests::appTests() | |||
ECC_Stop(); // Already started by the common test setup, so stop it to avoid interference | |||
LogInstance().DisconnectTestLogger(); | |||
|
|||
qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>("interfaces::BlockAndHeaderTipInfo"); |
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 commit "Reduce cs_main lock accumulation during GUI startup" (ded3edd)
I guess it'd be nice to register types in a common location in the future to avoid the need to do this twice
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.
Agree, suggestion GUIUtils::registerMetaTypes
or something like that.
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.
Yes. Lets do this later when more registration are required/appear.
ded3edd
to
bf788c7
Compare
Rebased (due to #18740). |
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.
Concept ACK.
src/init.cpp
Outdated
tip_info->verification_progress = GuessVerificationProgress(Params().TxData(), ::ChainActive().Tip()); | ||
} | ||
if (tip_info && ::pindexBestHeader) { | ||
tip_info->header_height = ::pindexBestHeader->nHeight;; |
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.
nit double ;
@@ -66,6 +66,7 @@ void AppTests::appTests() | |||
ECC_Stop(); // Already started by the common test setup, so stop it to avoid interference | |||
LogInstance().DisconnectTestLogger(); | |||
|
|||
qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>("interfaces::BlockAndHeaderTipInfo"); |
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.
Agree, suggestion GUIUtils::registerMetaTypes
or something like that.
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.
Code review ACK bf788c7. No changes since last review other than rebase
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.
Rebased here aa70cc8, also dropped extra ;
.
bf788c7
to
43ef1f3
Compare
Rebased and removed the extra |
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.
Code review ACK 43ef1f3. No changes since last review other than rebase (qmetatype conflict) and removing double semicolon
43ef1f3
to
386ec19
Compare
Rebased. |
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.
Code review ACK 386ec19. Just rebased since last review due to conflicts
Code review ACK 386ec19. |
Concept ACK |
Summary: PR description: Reduce cs_main lock accumulation during GUI startup > During the GUI startup, there is currently an accumulation of cs_main locks due to setting initial chain state values at multiple locations (in the GUI main thread). > > This PR tries to cache the initial chain state (tip height, tip time, best header, etc.) short after loading the blockindex. > > The cached values are then used instead of fetching them again (and thus locking cs_main) during setting the client model. > > This should fix the initial GUI blocking often experienced during or short after the splashscreen. This is a backport of [[bitcoin/bitcoin#19011 | core#19011]] [1/4] bitcoin/bitcoin@25e1d0b Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D9734
Summary: PR description: > During the GUI startup, there is currently an accumulation of cs_main locks due to setting initial chain state values at multiple locations (in the GUI main thread). > > This PR tries to cache the initial chain state (tip height, tip time, best header, etc.) short after loading the blockindex. > > The cached values are then used instead of fetching them again (and thus locking cs_main) during setting the client model. > > This should fix the initial GUI blocking often experienced during or short after the splashscreen. bitcoin/bitcoin@b354a14 > Add BlockAndHeaderTipInfo to the node interface/appInit bitcoin/bitcoin@d42cb79 > Optionally populate BlockAndHeaderTipInfo during AppInitMain This is a backport of [[bitcoin/bitcoin#19011 | core#19011]] [2&3/4] The commits needed squashing because the first one alone breaks the build. Depends on D9734 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D9735
Summary: PR description: > During the GUI startup, there is currently an accumulation of cs_main locks due to setting initial chain state values at multiple locations (in the GUI main thread). > > This PR tries to cache the initial chain state (tip height, tip time, best header, etc.) short after loading the blockindex. > > The cached values are then used instead of fetching them again (and thus locking cs_main) during setting the client model. > > This should fix the initial GUI blocking often experienced during or short after the splashscreen. This concludes backport of [[bitcoin/bitcoin#19011 | core#19011]] [4/4] bitcoin/bitcoin@386ec19 Depends on D9735 Depends on D9737 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D9736
During the GUI startup, there is currently an accumulation of cs_main locks due to setting initial chain state values at multiple locations (in the GUI main thread).
This PR tries to cache the initial chain state (tip height, tip time, best header, etc.) short after loading the blockindex.
The cached values are then used instead of fetching them again (and thus locking
cs_main
) during setting the client model.This should fix the initial GUI blocking often experienced during or short after the splashscreen.
On mac, best tested together with #19007.