blockchain: Use new uint256 for work sums. #2957
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This requires PR #2952.Live profiling data pulled from an instance of dcrd v1.8.0-pre on commit a4b20e9 performing an initial sync shows that roughly 36% of all in-use allocations are the result of the big integers used to store the cumulative work for each block. Further, around 12% of the entire CPU time is spent scaning the heap for garbage collection which is a direct result of the total number of inuse allocations. Therefore, a reasonable expectation is that eliminating those heap objects should produce a speedup of around 4-5%.
CPU Profiling Data:
Memory Profiling Data:
Consequently, this modifies the blockchain package to make use of the much more efficient zero-alloc uint256s and associated work calculation funcs in the new primitives package that is under development.
As can be seen in the following graphs, the result is about 100MiB less heap usage on average while the overall total number of used bytes is almost identical, which results in a reduction of about 5% to the initial sync time which is all in line with the expected results.