-
Notifications
You must be signed in to change notification settings - Fork 37.7k
optimization: Moved repeated -printpriority
fetching out of AddToBlock
#30324
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
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
-printpriority
fetching out of AddToBlock-printpriority
fetching out of AddToBlock
-printpriority
fetching out of AddToBlock-printpriority
fetching out of AddToBlock
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.
ACK 6e519b8
Thanks for optimizing.
Saw around a 6% speedup on my machine.
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.
Not sure if this is used at all. Maybe it can be removed completely? Otherwise, see the feedback.
src/node/miner.h
Outdated
@@ -172,6 +172,7 @@ class BlockAssembler | |||
|
|||
private: | |||
const Options m_options; | |||
const bool m_fPrintPriority; |
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.
This doesn't print the priority (it no longer exists in this codebase and was removed years ago). It prints the modified fee. So the name should reflect that. Also, snake_case for new code.
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.
0649a5b
to
3c0b795
Compare
3c0b795
to
bc752ac
Compare
71753ac
to
a114ced
Compare
a114ced
to
7759cd8
Compare
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.
re ACK 7759cd8
Tested that the arg still worked properly after the change. The message was missing without -printpriority=1
. The message was present with it.
src/bitcoind -debug -regtest -loglevel=trace -printpriority=1
src/bitcoin-cli -regtest createwallet test
src/bitcoin-cli -regtest -generate 101
src/bitcoin-cli -regtest -named sendtoaddress address=bcrt1qcv96frlnhzddst4dnlaa9nvdmvc4darw335wr9 fee_rate=3 amount=2
src/bitcoin-cli -regtest -named sendtoaddress address=bcrt1qnqyyh5xr73lkhfr9tj47u8kevtnahkgrqrnd4s fee_rate=2 amount=6
src/bitcoin-cli getblocktemplate '{"rules": ["segwit"]}'
2024-06-30T19:43:14Z fee rate 0.00003000 BTC/kvB txid e4bf26ea72e8cbbef9a6e239d1e57fd141c298dbe48696421b753794e20e9922
2024-06-30T19:43:14Z fee rate 0.00002000 BTC/kvB txid 98837b4e4d02399205cbc4e1d21266229b43186fd682e9461a915bd42c1de735
Still showing a speedup. Measured about 5%.
src/node/miner.h
Outdated
@@ -171,6 +172,8 @@ class BlockAssembler | |||
|
|||
private: | |||
const Options m_options; | |||
const bool m_print_modified_fee = gArgs.GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY); |
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.
By doing this, you include common/args.h
in all files that include node/miner.h
. It is better to add the field to the BlockAssembler::Options
struct and parse it inside ApplyArgsManOptions
.
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.
Thanks a lot, it's so much better this way!
AddToBlock was called repeatedly from `addPackageTxs` where the constant value of `printpriority` is recalculated every time. Since its behavior was changed in 400b151, I've named the variable accordingly. This showed up during profiling of AssembleBlock, fetching it once in the constructor results in a measurable speed increase for many iterations. > ./src/bench/bench_bitcoin --filter='AssembleBlock' --min-time=1000 before: | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 155,558.97 | 6,428.43 | 0.1% | 1.10 | `AssembleBlock` after: | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 148,083.68 | 6,752.94 | 0.1% | 1.10 | `AssembleBlock` Co-authored-by: furszy <mfurszy@protonmail.com>
7759cd8
to
323ce30
Compare
Thanks a lot for your help @tdb3, appreciate your reviews and verifications! |
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 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.
utACK 323ce30
@@ -30,7 +30,7 @@ class ChainstateManager; | |||
namespace Consensus { struct Params; }; | |||
|
|||
namespace node { | |||
static const bool DEFAULT_PRINTPRIORITY = false; | |||
static const bool DEFAULT_PRINT_MODIFIED_FEE = false; |
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.
nano nit: would call it "DEFAULT_PRINT_FEERATE" as the "modified" word is internal and might change over time.
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 didn't change the external option, just the internal name - as requested here #30324 (comment)
ACK 323ce30 |
ACK 323ce30 |
AddToBlock was called repeatedly from `addPackageTxs` where the constant value of `printpriority` is recalculated every time. Since its behavior was changed in 400b151, I've named the variable accordingly. This showed up during profiling of AssembleBlock, fetching it once in the constructor results in a measurable speed increase for many iterations. > ./src/bench/bench_bitcoin --filter='AssembleBlock' --min-time=1000 before: | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 155,558.97 | 6,428.43 | 0.1% | 1.10 | `AssembleBlock` after: | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 148,083.68 | 6,752.94 | 0.1% | 1.10 | `AssembleBlock` Co-authored-by: furszy <mfurszy@protonmail.com> Github-Pull: bitcoin#30324 Rebased-From: 323ce30
AddToBlock
was called repeatedly fromaddPackageTxs
where the constant value ofprintpriority
is recalculated every time.This showed up during profiling of AssembleBlock, fetching it once in the constructor results in a small speed increase for many iterations.
before:
AssembleBlock
after:
AssembleBlock
The slight speedup shows up in CI as well:
