Skip to content

caching: keep deeper append-only memtable lease reuse#818

Open
snissn wants to merge 2 commits intopr/appendonly-direct-arena-adaptive-retainfrom
pr/appendonly-entry-reuse-depth
Open

caching: keep deeper append-only memtable lease reuse#818
snissn wants to merge 2 commits intopr/appendonly-direct-arena-adaptive-retainfrom
pr/appendonly-entry-reuse-depth

Conversation

@snissn
Copy link
Copy Markdown
Owner

@snissn snissn commented Mar 13, 2026

Summary

  • increase maxAppendOnlyMemLeases from 8 to 32
  • this keeps more recycled append-only memtables under strong references instead of quickly falling back to sync.Pool
  • add a focused test to ensure the lease queue is still bounded by the configured cap

Why

allocs_batch_write_steady_treedb.pprof showed getAppendOnlyEntriesFromPool as a major allocator coming from memtable rotation/checkpoint paths. A shallow lease queue causes repeated entry-slice reallocation when rotate pressure is high.

Validation

  • go test ./TreeDB/caching
  • time ./bin/unified-bench -dbs treedb -profile fast -keys 500000 -progress=false -treedb-index-outer-leaves-in-vlog=true -valsize=100 -treedb-force-value-pointers=false -checkpoint-between-tests -profile-dir=/home/mikers/tmp/perf-entry-lease32b-1773434944

Comparison baseline (PR #817 head): /home/mikers/tmp/perf-direct-retainfix-1773434559

alloc_space (batch_write_steady)

  • total: 165.08MB -> 138.13MB
  • getAppendOnlyEntriesFromPool: 26.72MB -> ~0MB (drops out of top with -nodefraction=0)

ops/sec highlights

  • batch_write_steady: 1,998,857 -> 2,107,601 (+5.4%)
  • batch_random: 7,853,279 -> 8,377,934 (+6.7%)
  • dataset_write_random: 4,845,198 -> 5,072,183 (+4.7%)
  • dataset_write_sorted: 3,483,792 -> 3,656,106 (+4.9%)
  • sequential_write: 4,116,846 -> 4,085,790 (-0.8%, within noise)

Copilot AI review requested due to automatic review settings March 13, 2026 20:51
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

Adjusts append-only memtable recycling behavior in TreeDB/caching to retain more “warm” append-only memtables under strong references, reducing allocation churn during rotate/checkpoint-heavy write workloads.

Changes:

  • Increase the bounded strong-reference lease queue for recycled append-only memtables (maxAppendOnlyMemLeases) from 8 to 32.
  • Add a focused unit test to ensure putAppendOnlyMemLease respects the configured cap.

Reviewed changes

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

File Description
TreeDB/caching/db.go Raises the cap on retained append-only memtable leases to improve reuse and reduce sync.Pool fallback under pressure.
TreeDB/caching/memtable_view_refs_test.go Adds a regression test asserting the append-only memtable lease queue remains bounded by maxAppendOnlyMemLeases.

💡 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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 12a525e44e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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

Adjusts append-only memtable lease retention in the caching layer to improve entry-slice reuse under rotation/checkpoint-heavy write workloads, and adds a unit test to prevent regressions in the lease cap behavior.

Changes:

  • Increase maxAppendOnlyMemLeases from 8 to 32 with updated rationale in comments.
  • Add TestPutAppendOnlyMemLease_RespectsCap to verify the lease list never grows beyond the configured cap.

Reviewed changes

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

File Description
TreeDB/caching/db.go Raises the cap on strong references for recycled append-only memtables to reduce fallback to sync.Pool and allocation churn.
TreeDB/caching/memtable_view_refs_test.go Adds a test ensuring putAppendOnlyMemLease enforces the maximum lease count.

💡 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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7e9b61f4db

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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