Skip to content
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

blockchain: Use new uint256 for work sums. #2957

Merged

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented May 28, 2022

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:

      flat  flat%   sum%        cum   cum%
  1456.78s 25.97% 25.97%   1459.30s 26.01%  runtime.cgocall
      668s 11.91% 37.87%   2176.40s 38.79%  runtime.scanobject
   609.77s 10.87% 48.74%    668.60s 11.92%  runtime.findObject
   231.85s  4.13% 52.88%    231.85s  4.13%  runtime.heapBits.bits
   226.34s  4.03% 56.91%    226.34s  4.03%  runtime.markBits.isMarked
   178.15s  3.18% 60.09%    178.15s  3.18%  cmpbody
   176.58s  3.15% 63.23%    510.10s  9.09%  runtime.greyobject

Memory Profiling Data:

      flat  flat%   sum%        cum   cum%
    720918 20.08% 20.08%    1308043 36.44%  github.com/decred/dcrd/blockchain/standalone/v2.CalcWork
    587125 16.36% 73.81%     587125 16.36%  math/big.nat.make (inline)

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.

dcrd_initial_sync_total_bytes_used_comparison_uint256_work_sums_vs_1_8_0_a4b20e9d

dcrd_initial_sync_mem_usage_comparison_uint256_work_sums_vs_1_8_0_a4b20e9d

@davecgh davecgh added this to the 1.8.0 milestone May 28, 2022
@davecgh davecgh force-pushed the blockchain_internal_use_uint256_work_sums branch from e01f68a to 7fc95ce Compare May 30, 2022 17:02
@davecgh davecgh force-pushed the blockchain_internal_use_uint256_work_sums branch 2 times, most recently from eed1490 to 8b364cd Compare May 31, 2022 21:52
internal/blockchain/chain.go Show resolved Hide resolved
internal/blockchain/chain.go Outdated Show resolved Hide resolved
Live profiling data of 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%.

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.

Profiling shows the result is about 100MiB less heap usage on average
and a reduction of about 5% to the initial sync time which is in line
with the expected result.
@davecgh davecgh force-pushed the blockchain_internal_use_uint256_work_sums branch from 8b364cd to 891fc80 Compare June 7, 2022 20:21
@davecgh davecgh merged commit 891fc80 into decred:master Jun 7, 2022
@davecgh davecgh deleted the blockchain_internal_use_uint256_work_sums branch June 7, 2022 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants