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
Use lazy initialization for scripts in HdPubKey #11848
Conversation
@lontivero We talked about this change with @turbolay and I proposed to test this Given our talk about a previous PR of mine, I believe you are not a fan of -public Script P2pkhScript { get; }
+public Script P2pkhScript => PubKey.GetScriptPubKey(ScriptPubKeyType.Legacy); instead of -public Script P2pkhScript { get; }
+public Lazy<Script> P2pkhScript { get; } This is just an example, Clement says that That would be less invasive change, that would still speed up startup but we would avoid |
ffb2c01
to
983dc3f
Compare
I'm happy we came back to this old code that I always wanted to change but was too However, the PR is incredibly intrusive, a local change like this one cannot, and should not, require to change 12 files so, please make locals changes local. @kiminuo's proposal goes in the right direction but you can have the best of this PR and Kimi's idea by simply having lazy fields. For example: // a field for backing the property getter
private Lazy<Script> _p2pkScript ;
// here in the constructor we can initialize it
_p2pkScript = new Lazy<Script>(() => PubKey.ScriptPubKey);
// and then the property doesn't need to change and no changes in other files are needed.
public Script P2pkScript => _P2pkScript.Value; |
983dc3f
to
1cfe620
Compare
I'm open to suggestions. This PR was a base to highlight the problem, solution doesn't have to be implemented like this.
To be honest, I thought I only had to change 3 fields then I remembered.... The tests 😆 |
1cfe620
to
52850aa
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.
Yes, this is much better and I think the diff in performance is significant.
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.
LGTM
I think "Affiliate" label might be needed here. Even though the PR does not change API for 3rd parties, it still changes behavior if, eg, this line
throws an exception.
One additional improvement would be to specify explicitly Personally, I would go with |
I think this PR is okay because it gives us an important improvement at a very low cost. About the solution, I think this a hack because we create properties in advanced which are initialized when necessary instead of creating the thing when necessary. In this case all these properties are used by the But as I said, I would go with this PR because it brings something good at low cost. |
40343c3
to
6a30042
Compare
I agree. Refactorings are pretty slow but ongoing. So hopefully, one day in medium near future.
I agree. |
Review with this view: https://github.com/zkSNACKs/WalletWasabi/pull/11848/files/f523cb26d875c6666754674c318c0cc6feacbc82
Rest are tests or debug logs
This PR is great for 2 reasons:
GetScriptPubKey
is a time-consuming operation (25s for all my keys). But we only really need all of them to start coinjoin. So with the Lazy, the place where it's computed is much better, as it's when the client is "idle", starting coinjoining. not during a blocking operation (startup) as it's the case on master. We also access to the value during the Send Workflow: for keys involved in the payment while building and for all keys when broadcasting.If you have 2 wallets: One really big (let's say the one of your business) and one relatively small (let's say your personal one), you will not need to compute these values for the big wallet at all.
On my laptop with my big wallet, it makes Wasabi GUI to show up in 10s rather than 30s
Note that what takes time is
NBitcoin.TaprootFullPubKey.Create(TaprootInternalPubKey, uint256)
, so the more taproot keys you have the longer it takes. If you prefer, I can change this PR so only taproot is lazy, but I see no harm in having all lazy.This PR might have consequences I didn't account about