-
Notifications
You must be signed in to change notification settings - Fork 296
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/standalone: Add merkle root calc funcs. #1809
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
davecgh
commented
Aug 1, 2019
This was referenced Aug 5, 2019
dajohi
approved these changes
Aug 6, 2019
dnldd
approved these changes
Aug 6, 2019
matheusd
approved these changes
Aug 6, 2019
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.
Verified the testdata comes from the commented source blocks.
jrick
approved these changes
Aug 6, 2019
This adds functions to calculate a merkle root to the blockchain/standalone module. Rather than copying the existing functions from blockchain, it introduces new optimized functions that have simpler code and are also generally easier to use. The new functions simply return the calculated root instead of all of the intermediate hashes which no known callers were actually using anyway. It also adds a basic usage example, benchmarks, updates the documentation and includes comprehensive tests. As can be seen by the benchmarks below, the new code isn't significantly faster in terms of execution speed since it is still dominated by the actual hashing, however, it does significantly reduce the number of allocations which reduces pressure on the GC, particularly during bursty situations such as IBD. It also scales much better to larger numbers of transactions. The following is a before and after comparison of calculating merkle roots for various numbers of leaves: benchmark old ns/op new ns/op delta --------------------------------------------------------------- BenchmarkCalcMerkleRoot/20 25637 24287 -5.27% BenchmarkCalcMerkleRoot/1000 1252749 1209130 -3.48% BenchmarkCalcMerkleRoot/2000 2601754 2343198 -9.94% BenchmarkCalcMerkleRoot/4000 4873969 4629169 -5.02% BenchmarkCalcMerkleRoot/8000 9831116 9270095 -5.71% BenchmarkCalcMerkleRoot/16000 19172545 19067585 -0.55% BenchmarkCalcMerkleRoot/32000 37980323 35746500 -5.88% benchmark old allocs new allocs delta ---------------------------------------------------------------- BenchmarkCalcMerkleRoot/20 106 64 -39.62% BenchmarkCalcMerkleRoot/1000 5006 3004 -39.99% BenchmarkCalcMerkleRoot/2000 10006 6004 -40.00% BenchmarkCalcMerkleRoot/4000 20006 12004 -40.00% BenchmarkCalcMerkleRoot/8000 40006 24004 -40.00% BenchmarkCalcMerkleRoot/16000 80006 48004 -40.00% BenchmarkCalcMerkleRoot/32000 160006 96004 -40.00% benchmark old bytes new bytes delta ---------------------------------------------------------------- BenchmarkCalcMerkleRoot/20 6896 4432 -35.73% BenchmarkCalcMerkleRoot/1000 320688 208272 -35.05% BenchmarkCalcMerkleRoot/2000 641072 416272 -35.07% BenchmarkCalcMerkleRoot/4000 1281840 832272 -35.07% BenchmarkCalcMerkleRoot/8000 2563376 1664272 -35.07% BenchmarkCalcMerkleRoot/16000 5126448 3328272 -35.08% BenchmarkCalcMerkleRoot/32000 10252592 6656273 -35.08%
davecgh
force-pushed
the
standalone_add_merkle_funcs
branch
from
August 6, 2019 15:41
4b847ad
to
bd4e5c2
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #1808.
This adds functions to calculate a merkle root to the
blockchain/standalone
module. Rather than copying the existing functions fromblockchain
, it introduces new optimized functions that have simpler code and are also generally easier to use.The new functions simply return the calculated root instead of all of the intermediate hashes which no known callers were actually using anyway.
It also adds a basic usage example, benchmarks, updates the documentation and includes comprehensive tests.
As can be seen by the benchmarks below, the new code isn't significantly faster in terms of execution speed since it is still dominated by the actual hashing, however, it does significantly reduce the number of allocations which reduces pressure on the GC, particularly during bursty situations such as IBD. It also scales much better to larger numbers of transactions.
The following is a before and after comparison of calculating merkle roots for various numbers of leaves: