btcutil: reuse serialized tx during TxHash#2023
btcutil: reuse serialized tx during TxHash#2023kcalvinalvin wants to merge 1 commit intobtcsuite:masterfrom
Conversation
Pull Request Test Coverage Report for Build 7284089562
💛 - Coveralls |
The speedup is resulted from the fact that the tx is never serialized. Since we receive it serialized in the block, we just hash those bytes, saving a lot of overhead during txhash calculation. It's a different optimization from #1978 and this speedup is specific to ibd. I tried to show it via cpu profiling but without the utxocache PR #1955, the speedup isn't observable because the utxo i/o is such a big bottleneck |
Crypt-iQ
left a comment
There was a problem hiding this comment.
Code looks good, I did a once over to see if btcutil.Tx had any cases where it was modified after using Hash but couldn't find any. I think somebody else should also double-check just to be safe
Yeah I think that's one advtange: for block validation, things come off the wire, then go into the |
|
Running a combined branch for a sync test (utxo cache, this PR, and #1978), so far on my machine it's on schedule for a 6-ish hour sync (connected to One thing that still shows up is this hotspot later into the chain with full validation: Currently of the opinion that my attempt in #1376 may not be the best way to go about it, due to unintended consequences (PSBT interactions signing the long sighash, etc). Spending more time with routines like |
btcutil.Block caches the serialized raw bytes of the block during ibd. This serialized block bytes includes the serialized tx. The current tx hash generation will re-serialized the de-serialized tx to create the raw bytes and it'll only then hash that. This commit changes the code so that the re-serialization never happens, saving tons of cpu and memory overhead.
3afc77e to
83605e4
Compare
|
Rebased and addressed the review comments. |
|
Did the final nits in #2081 |


btcutil.Block caches the serialized raw bytes of the block during ibd. This serialized block bytes includes the serialized tx. The current tx hash generation will re-serialized the de-serialized tx to create the raw bytes and it'll only then hash that.
This commit changes the code so that the re-serialization never happens, saving tons of cpu and memory overhead.