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

Puzzle hash optimizations #17995

Merged
merged 4 commits into from May 10, 2024
Merged

Puzzle hash optimizations #17995

merged 4 commits into from May 10, 2024

Conversation

arvidn
Copy link
Contributor

@arvidn arvidn commented May 9, 2024

This PR is best reviewed one commit at a time.

Purpose:

This PR aims to improve the performance of computing puzzle hashes. This is achieved in 3 commits:

  1. rather than computing the hash of [] on the fly, use the constant NULL_TREEHASH.
  2. rather than constructing Program objects from values, just to compute the tree hash. Compute the tree hash directly from the values using the existing shatree_atom(), shatree_pair(), as well as introducing shatree_int() and shatree_byte_list()
  3. Avoid computing the public key given a derived private key (get_g1()) multiple times, by wrapping calculate_synthetic_public_key and calculate_synthetic_secret_key in LRU caches.

Current Behavior:

We waste time in get_inner_puzhash_by_p2()

New Behavior:

We waste less time in get_inner_puzhash_by_p2()

profile

function before after after / before
get_inner_puzhash_by_p2() 25.32% 5.16% 0.20
puzzle_hash_for_public_key_and_hidden_puzzle_hash 17% 2.12% 0.12

before

chia-hotspot-200-204

after

chia-hotspot-93

@arvidn arvidn added the Changed Required label for PR that categorizes merge commit message as "Changed" for changelog label May 9, 2024
@arvidn arvidn marked this pull request as ready for review May 9, 2024 07:16
@arvidn arvidn requested a review from a team as a code owner May 9, 2024 07:16
@arvidn arvidn requested a review from richardkiss May 9, 2024 07:16
Copy link
Contributor

@richardkiss richardkiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Some minor nits.

@arvidn arvidn force-pushed the puzzle-hash-optimizations branch from baa9ba8 to 463f12f Compare May 9, 2024 20:28
@arvidn arvidn requested a review from richardkiss May 9, 2024 21:58
Copy link
Contributor

File Coverage Missing Lines
chia/wallet/did_wallet/did_wallet.py 60.0% lines 534-535
Total Missing Coverage
51 lines 2 lines 96%

Copy link

Pull Request Test Coverage Report for Build 9023140534

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 49 of 51 (96.08%) changed or added relevant lines in 8 files are covered.
  • 20 unchanged lines in 8 files lost coverage.
  • Overall coverage increased (+0.04%) to 90.848%

Changes Missing Coverage Covered Lines Changed/Added Lines %
chia/wallet/did_wallet/did_wallet.py 3 5 60.0%
Files with Coverage Reduction New Missed Lines %
chia/_tests/simulation/test_simulation.py 1 96.5%
chia/daemon/server.py 1 83.21%
chia/introducer/introducer.py 1 78.26%
chia/timelord/timelord.py 2 73.67%
chia/full_node/full_node.py 2 85.25%
chia/rpc/rpc_server.py 3 87.67%
chia/server/node_discovery.py 3 81.03%
chia/wallet/wallet_node.py 7 88.51%
Totals Coverage Status
Change from base Build 9018383795: 0.04%
Covered Lines: 99018
Relevant Lines: 108945

💛 - Coveralls

@arvidn arvidn requested a review from emlowe May 10, 2024 07:30
@cmmarslender cmmarslender merged commit aa57676 into main May 10, 2024
355 of 356 checks passed
@cmmarslender cmmarslender deleted the puzzle-hash-optimizations branch May 10, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changed Required label for PR that categorizes merge commit message as "Changed" for changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants