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

Remove memory allocations from merkledb iteration #2925

Merged
merged 24 commits into from Apr 8, 2024

Conversation

StephenButtolph
Copy link
Contributor

Why this should be merged

Improves the performance of Next() by ~70%. After this change, the only memory allocations in the iterate benchmark are performed in NewIterator or in memdb.iterator#Key(). So, Next() doesn't perform any memory allocations anymore.

Before:

BenchmarkIteration/create_iterator-12         	    4704	    257583 ns/op	   43179 B/op	       4 allocs/op
BenchmarkIteration/iterate-12                 	    1023	   1142045 ns/op	  267401 B/op	    6004 allocs/op

After:

BenchmarkIteration/create_iterator-12         	    5005	    239408 ns/op	   43228 B/op	       4 allocs/op
BenchmarkIteration/iterate-12                 	    3685	    331174 ns/op	   51229 B/op	    1004 allocs/op

How this works

We don't need to allocate the full dbNode for iteration. This pulls the Value out of the node without performing memory allocations.

How this was tested

  • Added a new benchmark.
  • CI

@StephenButtolph StephenButtolph added this to the v1.11.4 milestone Apr 8, 2024
@StephenButtolph StephenButtolph self-assigned this Apr 8, 2024
@StephenButtolph StephenButtolph added the cleanup Code quality improvement label Apr 8, 2024
Base automatically changed from optimize-commit-view to master April 8, 2024 21:05
@StephenButtolph StephenButtolph added this pull request to the merge queue Apr 8, 2024
Merged via the queue into master with commit 1040ceb Apr 8, 2024
17 checks passed
@StephenButtolph StephenButtolph deleted the optimize-iterator-parsing branch April 8, 2024 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement merkledb
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants