Skip to content

perf(cmd): scale db-cache-size to available memory - #3927

Open
infrmtcs-agent[bot] wants to merge 1 commit into
mainfrom
dat/db-cache-autoscale
Open

perf(cmd): scale db-cache-size to available memory#3927
infrmtcs-agent[bot] wants to merge 1 commit into
mainfrom
dat/db-cache-autoscale

Conversation

@infrmtcs-agent

Copy link
Copy Markdown
Contributor

Summary

  • Scales the default RocksDB cache size to a fraction of available system memory instead of a fixed constant
  • Adds a memory-detection helper (utils/memory.go) with tests
  • Updates docs (tuning.md, _config-options.md) and config generation to reflect the new default

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Claude finished @infrmtcs-agent[bot]'s task in 6m 22s —— View job


Review: perf(cmd): scale db-cache-size to available memory

  • Gather context (diff vs origin/dat/fd-limit-default)
  • Review cmd/juno/juno.go default computation
  • Review node/throttled_compiler.go budget change
  • Review utils/memory.go move + tests
  • Verify type-checking (go vet clean on all touched packages)
  • Post findings (5 inline comments)

The change is well-shaped: clamping is correct, the constants match the tests, the compilerutils move removes an odd dependency, and the doc/generator updates are consistent with the code (including the versioned docs correctly left alone). No blockers found — no races, leaks, nil derefs, or swallowed errors.

Summary by severity

Blocker — none.

Important

  • cmd/juno/juno.go:725 — the 1024 MB floor isn't memory-aware. For any detected memory below 4 GB the default is pinned at 1024, so a 1 GB cgroup gets a block cache equal to 100% of its limit (2 GB → 50%). Pre-PR behaviour was identical, but this function is where it should be fixed, otherwise the flag advertises memory scaling while ignoring the range where it matters most. Fix this →

Nit

  • node/throttled_compiler.go:49cfg.RemoteDB != "" duplicates dbIsRemote from node.go:199; and the reserve now excludes the block cache but not pebble's memtables (DBMemtableSize × DBMemtableCount, 512 MB by default), which is also a long-lived allocation.
  • utils/memory.go:10AvailableMemoryMB returns total/cgroup-limited RAM, not free memory; the new user-facing docs say "a quarter of available memory", which reads as free.
  • cmd/juno/juno_test.go:76 — clamp formula re-implemented with literals; the constants now live in three places.
  • node/throttled_compiler_internal_test.go:40 — missing rows for MaxCompilationQueueExplicit: true and MaxCompilationMemory: 0.
  • Out of diff, low priority: db/pebblev2/option.go:24 computes cacheSizeMB * db.Megabyte in uint, which overflows at ≥ 4096 MB on a 32-bit build and would silently yield a tiny cache. Harmless on the 64-bit targets Juno actually ships, and this PR only makes the value large enough to matter, but an int64(cacheSizeMB) * db.Megabyte would remove the trap.

Verification notes

go vet ./cmd/... ./node/... ./utils/... ./starknet/compiler/... passes, so the AvailableMemoryMB move leaves no dangling references and the removed starknet/compiler test doesn't orphan its assert import (still used by TestConcurrencyLimit). I could not execute the test binaries in this environment: linking fails on missing Rust artifacts (-ljuno_starknet_compiler_rs, -ljuno_starknet_rs, -lbz2), which requires a make juno-style build not available here. The arithmetic in the new tables checks out by hand ((65536-4096-8192)/4096 = 13, (65536-4096)/4096 = 15, 2×conc for the queue), but please rely on CI for the actual runs.
· branch dat/db-cache-autoscale

Comment thread cmd/juno/juno.go
Comment on lines +725 to +727
func dbCacheSizeForMemoryMB(memMB uint64) uint {
return min(max(uint(memMB/cacheMemoryFraction), defaultCacheSizeMb), maxAutoCacheSizeMb)
}

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.

important — the lower clamp isn't memory-aware, which is the one case where being memory-aware matters most.

For any memMB < 4096 the result is pinned at defaultCacheSizeMb (1024), so:

container limit resulting cache share of memory
1024 MB 1024 MB 100%
2048 MB 1024 MB 50%
4096 MB 1024 MB 25%

A 1–2 GB cgroup (small k8s pods, CI containers) gets a block cache equal to half or all of its limit, and since pebble.NewCache is the ceiling the process grows into it, this ends in an OOM kill. The pre-PR fixed default had the same flaw, but this function is exactly where it should be fixed — otherwise the flag advertises "scales to available memory" while ignoring memory below 4 GB.

Consider bounding the floor too:

func dbCacheSizeForMemoryMB(memMB uint64) uint {
	quarter := uint(memMB / cacheMemoryFraction)
	return min(max(quarter, min(defaultCacheSizeMb, uint(memMB))), maxAutoCacheSizeMb)
}

or, if the 1024 floor is deliberate, say so in the comment and log a warning when the floor exceeds a quarter of detected memory so operators of small containers see it.

Separately: defaultCacheSizeMb is no longer the default, only the floor — minAutoCacheSizeMb would pair with maxAutoCacheSizeMb and keep the doc comment on line 720 self-explanatory.

Comment thread node/throttled_compiler.go
Comment thread cmd/juno/juno_test.go
defaultRPCMaxRequestQueue := uint(256000)
defaultRPCMaxBlockScan := uint(math.MaxUint)
defaultMaxCacheSize := uint(1024)
defaultMaxCacheSize := min(max(uint(utils.AvailableMemoryMB()/4), 1024), 8192)

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.

nit — this re-implements dbCacheSizeForMemoryMB with hardcoded literals (4, 1024, 8192) in an external test package, so the clamp constants now live in three places (juno.go, here, generate-config.js). Changing cacheMemoryFraction breaks this test for the wrong reason. defaultMaxHandles on the next line has the same issue and is pre-existing, so if you'd rather not export a helper just for tests it's fine to leave — but a short comment pointing at dbCacheSizeForMemoryMB as the source of truth would help the next person.

Comment on lines +40 to +51
wantConc: 1,
},
{
name: "explicit setting bypasses derivation",
cfg: Config{
MaxConcurrentCompilations: 5, MaxConcurrentCompilationsExplicit: true,
MaxCompilationMemory: 4096, NodeMemoryReserve: 4096, DBCacheSize: 8192,
},
cores: 64,
memMB: 65536,
wantConc: 5,
},

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.

nit — good table, two gaps worth one row each:

  • MaxCompilationQueueExplicit: true — the queue branch is never exercised with an explicit value, so queueSize = cfg.MaxCompilationQueue is untested here.
  • MaxCompilationMemory: 0 — the "no memory limit" path returns max(1, cores) and the DB-cache reserve becomes irrelevant; a row asserting wantConc == cores would lock in that the cache subtraction doesn't leak into it.

Comment thread utils/memory.go
Comment on lines +10 to +18
// AvailableMemoryMB returns the RAM this process can use, in MB.
// It checks if the memory is limited by the cgroup limit, otherwise it uses the host RAM.
func AvailableMemoryMB() uint64 {
hostMemory := memory.TotalMemory()
cgroupLimit, err := memlimit.FromCgroup()
if err == nil && cgroupLimit > 0 && cgroupLimit < hostMemory {
return cgroupLimit / megabyte
}
return hostMemory / megabyte

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.

nit — the move to utils is clean (and dropping compiler's dependency on it is the right call), but note this returns total RAM (memory.TotalMemory()) or the cgroup limit, not free memory. That was fine when only the compiler budget used it; now it also sizes a real allocation that the process grows into, and the user-facing docs say "a quarter of available memory", which reads as free memory. Worth either a one-line comment here clarifying total-vs-free, or wording the docs as "a quarter of total/cgroup-limited memory".

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.63%. Comparing base (f238536) to head (213ab9b).

Files with missing lines Patch % Lines
utils/memory.go 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3927      +/-   ##
==========================================
- Coverage   77.44%   74.63%   -2.82%     
==========================================
  Files         163      462     +299     
  Lines       19703    40871   +21168     
==========================================
+ Hits        15259    30504   +15245     
- Misses       3436     8266    +4830     
- Partials     1008     2101    +1093     
Flag Coverage Δ
jsonv2 77.36% <ø> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@EgeCaner
EgeCaner self-requested a review August 11, 2026 16:59
@infrmtcs
infrmtcs force-pushed the dat/db-cache-autoscale branch from 0745361 to 0823d18 Compare August 13, 2026 04:13
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Claude finished @infrmtcs's task in 5m 21s —— View job


Review: perf(cmd): scale db-cache-size to available memory

  • Diff the amended commit against the previously reviewed revision
  • Re-check cmd/juno/juno.go clamp logic
  • Re-check node/throttled_compiler.go budget
  • Re-check utils/memory.go + tests
  • Verify build / vet
  • Post findings

This push was a rebase, not a code change. The base branch dat/fd-limit-default was recreated (9bc43ae61967c3), so cmd/juno/juno.go, cmd/juno/juno_test.go, node/node.go, node/node_test.go and docs/docs/_config-options.md got new blob SHAs from re-application, while node/throttled_compiler.go, node/throttled_compiler_internal_test.go, utils/memory.go, cmd/juno/juno_internal_test.go, docs/docs/tuning.md and docs/generate-config.js are byte-identical to what I reviewed at 0745361. The PR's own diff is unchanged (196/-45, same as before), so none of the earlier feedback has been applied yet. Nothing new was introduced either — no blockers.

I re-anchored one inline comment on cmd/juno/juno.go because the force-push marked the original as outdated. The comments on node/throttled_compiler.go:51 and utils/memory.go are still live on unchanged blobs, so I did not repost them.

Standing items

Important

  • cmd/juno/juno.go:727 — the 1024 MB floor isn't memory-aware. Below 4 GB of detected memory the default is pinned at 1024, so a 1 GB cgroup gets a block cache equal to 100% of its limit and a 2 GB cgroup 50%. Identical to pre-PR behaviour, so not a regression, but this function is where the flag now advertises memory scaling — it should hold at the low end too. Fix this →

Nit (unchanged, comments still live)

  • node/throttled_compiler.go:51cfg.RemoteDB != "" duplicates dbIsRemote from node/node.go:199; and the reserve excludes the block cache but not pebble's memtables (DBMemtableSize × DBMemtableCount, 512 MB by default), which is equally long-lived.
  • utils/memory.goAvailableMemoryMB returns total/cgroup-limited RAM, not free memory, while the new user-facing text says "a quarter of available memory". Worth one clarifying line either in the doc comment or the docs.
  • cmd/juno/juno_test.go:76 — the clamp is re-implemented with literals (4, 1024, 8192), so the constants now live in three places (juno.go, here, generate-config.js). Pre-existing pattern for defaultMaxHandles on the next line; a comment pointing at dbCacheSizeForMemoryMB as the source of truth would be enough.
  • Out of diff: db/pebblev2/option.go:24 computes cacheSizeMB * db.Megabyte in uint, which overflows at ≥ 4096 MB on a 32-bit build. Harmless on Juno's 64-bit targets, but this PR is what makes the value large enough to reach it; int64(cacheSizeMB) * db.Megabyte removes the trap.

Correction to my earlier review

My previous comment on node/throttled_compiler_internal_test.go claimed rows for MaxCompilationQueueExplicit: true and MaxCompilationMemory: 0 were missing. Both are present ("explicit queue bypasses derivation" and "no compilation memory limit uses core count") and the blob is unchanged — that nit was wrong, please disregard it.

Verification

go vet ./cmd/... ./node/... ./utils/... ./starknet/compiler/... is clean, so the compilerutils move leaves no dangling references. I could not execute the test binaries here (go test is outside my allowed tools in this run, and linking also needs the Rust artifacts -ljuno_starknet_compiler_rs / -ljuno_starknet_rs). Table arithmetic checks out by hand: (65536-4096-8192)/4096 = 13, (65536-4096)/4096 = 15, 12288 ≤ 4096+8192 → 1, max(1, 64) = 64, queue = 2 × conc in each derived row. Please rely on CI for the runs.
· branch dat/db-cache-autoscale

@infrmtcs
infrmtcs deployed to Development August 13, 2026 04:19 — with GitHub Actions Active
Comment thread cmd/juno/juno.go
}

func dbCacheSizeForMemoryMB(memMB uint64) uint {
return min(max(uint(memMB/cacheMemoryFraction), defaultCacheSizeMb), maxAutoCacheSizeMb)

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.

important (re-anchored after the rebase — the original comment was marked outdated) — the lower clamp isn't memory-aware, which is the one range where being memory-aware matters most.

For any memMB < 4096 the result is pinned at defaultCacheSizeMb (1024):

detected memory resulting cache share
1024 MB 1024 MB 100%
2048 MB 1024 MB 50%
4096 MB 1024 MB 25%

pebble.NewCache is a ceiling the process grows into, so a 1–2 GB cgroup (small k8s pods, CI containers) ends up with a block cache at half or all of its limit. This is not a regression — the fixed 1024 default had the same property — but this function is now the thing that claims to scale with memory, so it's the right place to close the gap:

Suggested change
return min(max(uint(memMB/cacheMemoryFraction), defaultCacheSizeMb), maxAutoCacheSizeMb)
quarter := uint(memMB / cacheMemoryFraction)
return min(max(quarter, min(defaultCacheSizeMb, uint(memMB))), maxAutoCacheSizeMb)

If the flat 1024 floor is deliberate, saying so in the doc comment above (and logging a warning when the floor exceeds a quarter of detected memory) would at least make it visible to operators of small containers.

Separately: defaultCacheSizeMb is no longer the default, only the floor — minAutoCacheSizeMb would pair with maxAutoCacheSizeMb and keep the doc comment on line 721 self-explanatory.

@infrmtcs
infrmtcs force-pushed the dat/db-cache-autoscale branch from 0823d18 to 386db67 Compare August 13, 2026 05:45
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Claude finished @infrmtcs's task in 5m 19s —— View job


Review: perf(cmd): scale db-cache-size to available memory

  • Diff the new push against the previously reviewed revision
  • Re-check cmd/juno/juno.go clamp logic
  • Re-check node/throttled_compiler.go budget
  • Re-check utils/memory.go + tests
  • Verify vet / gofmt
  • Post findings (1 inline comment)

This push is another rebase, not a code change. HEAD is now 386db67 with parent 20cd3ca — the base branch dat/fd-limit-default was recreated again (61967c320cd3ca). The PR's own diff is byte-for-byte what I reviewed before (196/-45, same hunks: the clamp is still min(max(uint(memMB/cacheMemoryFraction), defaultCacheSizeMb), maxAutoCacheSizeMb), cfg.RemoteDB != "" is still inlined in the budget, utils/memory.go is unchanged). So no earlier feedback has been applied, and nothing new was introduced. No blockers.

I re-anchored the one important item on cmd/juno/juno.go, because the force-push marks the previous anchor outdated — and because the fix I suggested in it was wrong, which is the one piece of new content in this review.

Correction to my previous suggestion

My earlier snippet for the memory-aware floor —

return min(max(quarter, min(defaultCacheSizeMb, uint(memMB))), maxAutoCacheSizeMb)

— does not fix the case I raised. min(defaultCacheSizeMb, memMB) only bites below 1024 MB of total memory, so the two rows in my own table (memMB=1024 → 1024 MB cache, memMB=2048 → 1024 MB cache) come out identical to today's code. The floor has to be bounded by a fraction of memory, not by memory. Details and a working alternative are in the inline comment. Sorry for the noise — please use the new version.

Standing items (unchanged, earlier comments still apply)

Important

  • cmd/juno/juno.go:730 — the 1024 MB floor isn't memory-aware; below 4 GB of detected memory the block cache is 50–100% of the limit, and pebble.NewCache is a ceiling the process grows into. Fix it, or make the flat floor explicit in the doc comment plus a warning log. Either way add memMB = 512 / 2048 rows to cmd/juno/juno_internal_test.go. Fix this →

Nit

  • node/throttled_compiler.go:51cfg.RemoteDB != "" duplicates dbIsRemote (node/node.go:199), the single place that decides whether a local pebble instance is opened; and the reserve excludes the block cache but not pebble's memtables (DBMemtableSize × DBMemtableCount, 512 MB by default), which is equally long-lived. Also, the new maxCompilationReserveMemory help text states the DB cache is excluded unconditionally — it isn't, with --remote-db it's zero.
  • utils/memory.goAvailableMemoryMB returns total/cgroup-limited RAM, not free memory, while the new user-facing text says "a quarter of available memory". One clarifying line in the doc comment or the docs would settle it. (The compilerutils move itself is the right call.)
  • cmd/juno/juno_test.go:76 — the clamp is re-implemented with literals (4, 1024, 8192), so the constants now live in three places (juno.go, here, generate-config.js); same pre-existing pattern as defaultMaxHandles on the next line, so a comment naming dbCacheSizeForMemoryMB as the source of truth is enough.
  • Out of diff: db/pebblev2/option.go:25 computes cacheSizeMB * db.Megabyte in uint, which overflows at ≥ 4096 MB on a 32-bit build and would silently yield a tiny cache. Harmless on Juno's 64-bit targets, but this PR is what makes the value large enough to reach it; int64(cacheSizeMB) * db.Megabyte removes the trap.

Verification

gofmt -l cmd/juno node utils starknet/compiler is empty and go vet ./cmd/juno/... ./node/... ./utils/... ./starknet/compiler/... is clean, so the compilerutils move leaves no dangling references, utils.megabyte doesn't collide with anything in the package, and defaultMaxCacheSize in cmd/juno/juno_test.go is still referenced (9 sites). ConcurrencyLimit guards availableMemory <= nodeMemoryReserve, so the larger reserve can't underflow. I still could not execute tests here (go test is outside my allowed tools in this run, and linking also needs the Rust artifacts -ljuno_starknet_compiler_rs / -ljuno_starknet_rs); table arithmetic checks out by hand — (65536-4096-8192)/4096 = 13, (65536-4096)/4096 = 15, 12288 ≤ 4096+8192 → 1, max(1, 64) = 64, queue = 2 × conc. Please rely on CI for the runs.
· branch dat/db-cache-autoscale

@infrmtcs
infrmtcs deployed to Development August 13, 2026 05:50 — with GitHub Actions Active
Comment thread cmd/juno/juno.go
Comment on lines +730 to +732
func dbCacheSizeForMemoryMB(memMB uint64) uint {
return min(max(uint(memMB/cacheMemoryFraction), defaultCacheSizeMb), maxAutoCacheSizeMb)
}

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.

important (standing item, re-anchored after this rebase) — and a correction to the fix I suggested earlier: the snippet I proposed in my previous review does not actually fix the case it describes. Please ignore it.

The problem stands: for any memMB < 4096 the result is pinned at defaultCacheSizeMb (1024), so a 1 GB cgroup gets a block cache equal to 100% of its limit and a 2 GB cgroup 50%. pebble.NewCache is a ceiling the process grows into, so small k8s pods / CI containers are the ones most likely to OOM. Not a regression (the fixed 1024 default had the same property), but this function is now what claims to scale with memory.

Why my earlier suggestion was wrong — min(max(quarter, min(defaultCacheSizeMb, uint(memMB))), maxAutoCacheSizeMb):

memMB quarter min(1024, memMB) result share
1024 256 1024 1024 100%
2048 512 1024 1024 50%

min(defaultCacheSizeMb, memMB) only bites below 1024 MB of total memory, so both rows in my own table come out unchanged. Bounding the floor by memory isn't enough — it has to be bounded by a fraction of memory, i.e. the floor must not be allowed to exceed what the quarter rule would grant. Concretely, either drop the floor when memory can't afford it:

// dbCacheSizeForMemoryMB gives the cache a quarter of memMB, capped at
// maxAutoCacheSizeMb. The minAutoCacheSizeMb floor only applies when memory is
// large enough for it to stay within the quarter budget, so a small container
// does not get a cache the size of its whole limit.
func dbCacheSizeForMemoryMB(memMB uint64) uint {
	quarter := uint(memMB / cacheMemoryFraction)
	if quarter < minAutoCacheSizeMb {
		return max(quarter, minCacheSizeMb) // e.g. 64; pebble's own floor is 8 MB
	}
	return min(quarter, maxAutoCacheSizeMb)
}

…or keep the flat floor deliberately (defensible — a 1–2 GB host can't sync Juno anyway), and in that case say so in the doc comment on line 724 and log a warning when the floor exceeds a quarter of detected memory, so operators of memory-capped containers can see why the process is being killed. Either way, cmd/juno/juno_internal_test.go should get rows for memMB = 512 and memMB = 2048 to pin the chosen behaviour down.

Separately (unchanged): defaultCacheSizeMb is no longer the default, only the floor — minAutoCacheSizeMb would pair with maxAutoCacheSizeMb and keep the doc comment above self-explanatory.

Base automatically changed from dat/fd-limit-default to main August 14, 2026 04:15
@infrmtcs
infrmtcs force-pushed the dat/db-cache-autoscale branch from 386db67 to 213ab9b Compare August 14, 2026 04:16
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Claude finished @infrmtcs's task in 3m 36s —— View job


Review: perf(cmd): scale db-cache-size to available memory

  • Diff this push against the previously reviewed revision
  • Re-check cmd/juno/juno.go clamp logic
  • Re-check node/throttled_compiler.go budget
  • Re-check utils/memory.go + tests
  • Verify vet / gofmt
  • Post findings

This push is a rebase onto main, not a code change. HEAD is now 213ab9b with parent f238536 — the fd-limit work (#3919) landed in main, so the PR base moved from dat/fd-limit-default to main and this is now a clean single commit on top of main. git diff origin/main...HEAD is 196/-45, byte-for-byte the same hunks I reviewed before: the clamp is still min(max(uint(memMB/cacheMemoryFraction), defaultCacheSizeMb), maxAutoCacheSizeMb) (cmd/juno/juno.go:731), cfg.RemoteDB != "" is still inlined in the budget, utils/memory.go is unchanged. Nothing new introduced. No blockers.

I did not repost the standing inline comments — the earlier threads are still open on the Conversation tab, and a fourth re-anchor would just be noise. Their current state:

Standing items

Importantcmd/juno/juno.go:731 (thread open, unanswered)
The 1024 MB floor isn't memory-aware. For any memMB < 4096 the result is pinned at 1024, so a 1 GB cgroup gets a block cache equal to 100% of its limit and a 2 GB cgroup 50%; pebble.NewCache is a ceiling the process grows into. Not a regression — the fixed 1024 default had the same property — but this function is now the thing that claims to scale with memory. Either bound the floor by a fraction of memory, or keep the flat floor deliberately and say so in the doc comment (+ a warning log when the floor exceeds a quarter of detected memory). Either way cmd/juno/juno_internal_test.go would benefit from memMB = 512 / 2048 rows to pin the chosen behaviour down. Full reasoning, including the correction to my first (wrong) suggested fix, is in the linked thread. Fix this →

Withdrawnnode/throttled_compiler.go:51, point 1. @infrmtcs answered that the function already takes cfg, and that a separate helper is the right move if the condition ever grows. Agreed — dropping it.

Nit (still open)

  • node/throttled_compiler.go:51, point 2 — the reserve now excludes the block cache but not pebble's memtables (DBMemtableSize × DBMemtableCount, 512 MB by default), which is an equally long-lived allocation. Also, the maxCompilationReserveMemory help text says the DB cache is excluded unconditionally; with --remote-db it's zero.
  • utils/memory.goAvailableMemoryMB returns total/cgroup-limited RAM, not free memory, while the new user-facing text says "a quarter of available memory". One clarifying line in the doc comment or the docs settles it. (The compilerutils move itself is the right call.)
  • cmd/juno/juno_test.go:76 — the clamp is re-implemented with literals (4, 1024, 8192), so the constants live in three places (juno.go, here, generate-config.js); same pre-existing pattern as defaultMaxHandles on the next line, so a comment naming dbCacheSizeForMemoryMB as the source of truth is enough.
  • Out of diff: db/pebblev2/option.go:25 computes cacheSizeMB * db.Megabyte in uint, which overflows at ≥ 4096 MB on a 32-bit build and would silently yield a tiny cache. Harmless on Juno's 64-bit targets, but this PR is what makes the value large enough to reach it; int64(cacheSizeMB) * db.Megabyte removes the trap.

Verification

gofmt -l cmd/juno node utils starknet/compiler is empty and go vet ./cmd/juno/... ./node/... ./utils/... ./starknet/compiler/... is clean on the rebased tree, so the compilerutils move leaves no dangling references after the base change and utils is imported where the tests now need it (cmd/juno/juno_test.go, node/node_test.go). defaultCacheSizeMb / maxAutoCacheSizeMb / cacheMemoryFraction are referenced only from juno.go and juno_internal_test.go. ConcurrencyLimit guards availableMemory <= nodeMemoryReserve, so the larger reserve can't underflow.

I could not execute tests in this run — go test is outside my allowed tools here, and linking would also need the Rust artifacts (-ljuno_starknet_compiler_rs / -ljuno_starknet_rs). Table arithmetic checks out by hand: (65536-4096-8192)/4096 = 13, (65536-4096)/4096 = 15, 12288 ≤ 4096+8192 → 1, max(1, 64) = 64, queue = 2 × conc in each derived row. Please rely on CI for the runs.
· branch dat/db-cache-autoscale

@infrmtcs
infrmtcs deployed to Development August 14, 2026 04:32 — with GitHub Actions Active
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.

1 participant