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

perf: avoid unnecessary clone when building Merkle trees #872

Merged
merged 4 commits into from
Jul 22, 2024

Conversation

Oppen
Copy link
Member

@Oppen Oppen commented May 23, 2024

The function complete_until_power_of_two takes a mutable reference, modifies the Vec<_> in-place, only to clone it and return it. Instead, just take ownership of the argument and return it again, without cloning.

Note while the change is marked as an optimization the impact isn't that high (<2%), but it's almost free and "feels" a little bit more correct this way.

Type of change

Please delete options that are not relevant.

  • New feature
  • Bug fix
  • Optimization

Results

Ran on M1 MBP 2020 14" 16GiB:

Merkle Tree/build       time:   [724.84 ms 734.25 ms 748.73 ms]                                                        
                        change: [-3.1234% -1.9869% -0.6644%] (p = 0.01 < 0.05)                                         
                        Change within noise threshold.

Checklist

  • Linked to Github Issue
  • Unit tests added
  • This change requires new documentation.
    • Documentation has been added/updated.
  • This change is an Optimization
    • Benchmarks added/run

@Oppen Oppen requested a review from a team as a code owner May 23, 2024 18:23
@codecov-commenter
Copy link

codecov-commenter commented May 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.03%. Comparing base (7ffcf7c) to head (c147ffe).
Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #872   +/-   ##
=======================================
  Coverage   72.03%   72.03%           
=======================================
  Files         149      149           
  Lines       33407    33407           
=======================================
  Hits        24066    24066           
  Misses       9341     9341           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Oppen Oppen added this pull request to the merge queue Jul 22, 2024
Merged via the queue into main with commit 994ba28 Jul 22, 2024
7 checks passed
@Oppen Oppen deleted the perf/merkle_build_remove_clone branch July 22, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants