Skip to content

go: derive internal cache sizes from GOMEMLIMIT - #10820

Merged
reltuk merged 2 commits into
dolthub:mainfrom
skullbloc:stebbins/memlimit-budget-clean
Apr 15, 2026
Merged

reltuk merged 2 commits into
dolthub:mainfrom
skullbloc:stebbins/memlimit-budget-clean

Conversation

@stebbins

@stebbins stebbins commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Usage

GOMEMLIMIT=512MiB dolt sql-server

Design

Cache Default At GOMEMLIMIT=512MiB
Prolly node cache 256 MiB ~120 MiB
Memtable write buffer 256 MiB ~120 MiB
Decoded chunks cache 32 MiB ~15 MiB

Budget partitioning: 50% usable (50% GC reserve), then 47/47/6 across caches — matching the ratio of the original hardcoded defaults (256:256:32 MiB). Minimums prevent pathologically small caches. Maximum caps ensure caches never exceed current defaults, even with high GOMEMLIMIT — we can loosen these later if needed.

Changes

  • New: go/libraries/doltcore/memlimit/ — budget calculator with 8 unit tests
  • Modified: go/store/prolly/tree/node_store.go — lazy sync.Once init via memlimit
  • Modified: go/store/types/value_store.go — decoded chunks from memlimit
  • Modified: go/libraries/doltcore/dbfactory/ — all 8 factory impls call memlimit.MemtableSize() directly
  • Modified: go/cmd/dolt/dolt.go — memlimit.Init() in runMain()

What this doesn't do

  • No custom DOLT_* env vars
  • No YAML config additions
  • No automemlimit dep yet (follow-up for container cgroup auto-detection)
  • Doesn't touch commit cache (already has DOLT_COMMIT_CACHE_SIZE)

Test plan

  • 8 unit tests: defaults, zero, 512 MiB, 128 MiB, 32 MiB (minimums), 4 GiB (capped at defaults), accessors
  • store/prolly/tree, store/types, libraries/doltcore/dbfactory, store/prolly test suites pass
  • Full binary build + live RSS measurement (needs CI with ICU headers)

🤖 Generated with Claude Code

Dolt hardcodes ~544 MiB of caches (node cache 256 MiB, memtable 256 MiB,
decoded chunks 32 MiB) that cannot be tuned without code changes. For
local development and memory-constrained deployments, this makes Dolt's
RSS floor unnecessarily high.

This adds a memlimit package that reads the standard Go GOMEMLIMIT
(Go 1.19+) and proportionally sizes internal caches. When GOMEMLIMIT is
unset, all defaults are preserved exactly — zero behavior change.

Usage:
  GOMEMLIMIT=512MiB dolt sql-server

Changes:
- New memlimit package with budget partitioning and min/max clamping
- Prolly node cache: const+global init -> lazy sync.Once via memlimit
- ValueStore decoded chunks: constant -> memlimit.DecodedChunksSize()
- dbfactory memtable: constant -> lazy sync.Once via memlimit
- All factory implementations updated to use getMemTableSize()
- dolt.go: call memlimit.Init() early in runMain()

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

@reltuk reltuk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great. One requested change :).

Reduce usable factor from 75% to 50% and cap each cache at its
current default size so GOMEMLIMIT never makes caches larger than
they are today. We can loosen these limits later if needed.

Addresses review feedback from reltuk on #10820.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@stebbins
stebbins requested a review from reltuk April 15, 2026 02:51
@reltuk
reltuk merged commit a02a89d into dolthub:main Apr 15, 2026
24 of 31 checks passed
@reltuk

reltuk commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Awesome! Thank you for the update. Everything looked good. I've merged this to main :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants