Skip to content

zipper,node: reduce wrapper churn and grow key scratch geometrically#825

Open
snissn wants to merge 3 commits intopr/zipper-scratch-reuse-tuningfrom
pr/zipper-nodeview-scratch-standalone
Open

zipper,node: reduce wrapper churn and grow key scratch geometrically#825
snissn wants to merge 3 commits intopr/zipper-scratch-reuse-tuningfrom
pr/zipper-nodeview-scratch-standalone

Conversation

@snissn
Copy link
Copy Markdown
Owner

@snissn snissn commented Mar 13, 2026

Summary

  • switch zipper loadNode to node.NewNodeView/value wrappers to avoid per-load *Node allocations
  • thread value-node wrappers through recursive/coalesce paths
  • grow node.ensureKeyScratch geometrically to avoid realloc churn on small key-length increases
  • add node unit coverage for scratch growth reuse behavior

Validation

  • go test ./TreeDB/node ./TreeDB/zipper
  • go test ./TreeDB/caching ./TreeDB/internal/memtable ./TreeDB/zipper ./TreeDB/node
  • unified bench: /home/mikers/tmp/perf-pr3only-1773439188 (base: /home/mikers/tmp/perf-base820-1773438485)
    • seq write: 4,160,181 vs 4,133,530
    • random write: 5,076,820 vs 5,105,302
    • batch_write_steady alloc_space writeRecursive: 47.69MB vs 48.69MB

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces allocations in hot read/merge paths by switching zipper node loading to use node.Node value views (via NewNodeView) and by improving Node’s internal key-scratch growth strategy to avoid repeated small allocations during leaf key reconstruction.

Changes:

  • Update Zipper.loadNode to return node.Node values and use node.NewNodeView, adjusting downstream call sites to pass *node.Node where required.
  • Change (*node.Node).ensureKeyScratch to grow geometrically (with overflow guard) instead of reallocating to the exact requested size.
  • Add a focused unit test validating key-scratch geometric reuse behavior.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
TreeDB/zipper/zipper.go Switch node loading from *node.Node to allocation-free node.Node views and update call sites accordingly.
TreeDB/node/leaf.go Make ensureKeyScratch grow geometrically (min 64 bytes) to reduce repeated allocations.
TreeDB/node/key_scratch_test.go Add test ensuring small size increases reuse capacity and larger increases trigger growth.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@snissn snissn requested a review from Copilot March 17, 2026 18:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces heap allocations and improves scratch-buffer reuse in TreeDB’s page/node handling, primarily around zipper node loading and leaf key decoding.

Changes:

  • Update Zipper.loadNode to return node.Node by value and use node.NewNodeView (no heap allocation) for loaded pages.
  • Adjust zipper merge/coalesce call sites to pass *node.Node where required after the value-return change.
  • Improve node.Node.ensureKeyScratch to grow geometrically and add a unit test validating reuse behavior.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
TreeDB/zipper/zipper.go Switch node loading to allocation-free Node values and update merge/coalesce call sites accordingly.
TreeDB/node/leaf.go Change key scratch allocation strategy to geometric growth to avoid repeated small allocations.
TreeDB/node/key_scratch_test.go Add coverage to ensure key scratch capacity is reused on small growth and increases when necessary.
TreeDB/caching/db.go Formatting/alignment-only change within arena sizing constants.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

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.

3 participants