mimblewimble / grin

Minimal implementation of the Mimblewimble protocol.
https://grin.mw/
Apache License 2.0
5.04k stars 989 forks source link

[SYNC PERFORMANCE] Adjust DifficultyIterator to no longer deserialize PoW proof nonces #3671

Closed yeastplume closed 2 years ago

yeastplume commented 2 years ago

[note this PR is stacked on #3670]

Previous to this PR, a large amount of time was during validation was spent in the Difficulty Iterator, in particular deserializing and reserializing the PoW proof nonces. Since this information is not required to iterate through the difficulty of the past 60 blocks, a method of deserialization is introduced that deserialises a block header without its proof. Since the BlockHeader is unable to determine its correct hash without this info, the hash information is removed from the HeaderInfo struct. Further, the HeaderInfo Struct is renamed HeaderDifficultyInfo to reduce the potential for confusion (this struct should only be used to iterate through difficulty information)

For comparison, here is the current flamegraph of the included 100k header copy test (again on a 2.3 GHz 8-Core Intel Core i9) taking 36 Seconds (after the application of #3670) (53% of runtime spent in difficulty next iterator)

image

And with both this pr and #3670 applied - With the run taking 26 seconds (37% of time spent in same next fn)

image

Detailed Changes:

Note since this is stacked we might need to do some rebasing wizardry to make this PR easier to view once #3670 is applied

yeastplume commented 2 years ago

Thank you for reviewing! Going to merge; there shouldn't be any consensus changes here and there's plenty of test effort for the next release incoming!