Skip to content

Generate apps with a 16 MiB starting GC heap - #56

Merged
crimson-knight merged 1 commit into
mainfrom
feat/tuned-gc-starting-heap
Nov 20, 2026
Merged

crimson-knight merged 1 commit into
mainfrom
feat/tuned-gc-starting-heap

Conversation

@crimson-knight

@crimson-knight crimson-knight commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

What

amber new writes server.gc_initial_heap_mib: 16 into development.yml, test.yml and production.yml, and the generated README's "What is on by default" section says where to change it (the YAML key or AMBER_SERVER_GC_INITIAL_HEAP_MIB). The value lives in one constant, NewCommand::GC_INITIAL_HEAP_MIB.

Amber reads the key from amberframework/amber#1452 (a typed ServerConfig setting that grows Boehm GC's heap at server start). Until the template pins an Amber release with that PR, Amber ignores the key (server settings are not strict), so this is safe to land in either order.

Why 16 MiB

Starting-heap sweep on a generated amber new -d sqlite app (Amber CLI 2.0.10 scaffold, 50 seeded posts), beta.11 PR set (amber #1451, grant #73, asset_pipeline #25) against beta.10 at its default heap. Settings: oha, 32 connections, 30 s per run, 10 interleaved pairs, default log level, production mode, one process. POST /posts (form + CSRF):

Starting heap p50 before -> after p50 ratio [95% CI] req/s before -> after peak RSS before -> after
default 2.194 -> 2.298 ms (+0.103 ms) 1.029 [1.007, 1.057] 12,708 -> 13,243 232.6 -> 25.4 MiB
4 MiB 2.106 -> 2.366 ms (+0.260 ms) 1.105 [1.086, 1.116] 13,472 -> 12,689 227.7 -> 24.2 MiB
8 MiB 2.106 -> 2.231 ms (+0.125 ms) 1.054 [1.042, 1.064] 13,472 -> 13,204 227.7 -> 24.7 MiB
16 MiB 2.194 -> 2.108 ms (-0.086 ms) 0.954 [0.945, 0.973] 12,708 -> 14,257 (+1,548) 232.6 -> 33.9 MiB (-198.7 MiB)
16 MiB, set only in production.yml through amber#1452 2.106 -> 2.082 ms (-0.024 ms) 0.983 [0.970, 0.994] 13,472 -> 14,333 (+860) 227.7 -> 33.8 MiB
32 MiB 2.194 -> 2.073 ms 0.954 [0.921, 0.960] 12,708 -> 14,376 232.6 -> 51.4 MiB

The 4 MiB, 8 MiB and production.yml rows come from a second interleaved run with its own A. 16 MiB is the smallest value whose POST p50 interval is at or below 1.0. Every GET row at 16 MiB is neutral or better except peak RSS on the small JSON route (GET /api/posts: 17.7 -> 25.6 MiB, +7.9 MiB), the memory the starting heap itself takes. 32 MiB and up add a GET /posts p99 regression and more memory. Full tables: heap-tuning.md in the perf-regression report folder.

Specs

spec/commands/new_command_spec.cr ("tuned defaults"): every generated environment file carries server.gc_initial_heap_mib equal to the constant, the constant is above 0, and the README names the key. Local run with crystal-alpha: 174 examples, 0 failures; crystal tool format --check src spec clean; scripts/check_beta_contract.sh passes.

Every generated environment file sets server.gc_initial_heap_mib: 16,
and the generated README says where to change it. 16 MiB is the
smallest starting heap that kept POST /posts p50 at or below beta.10 in
a generated app with the beta.11 changes; 4 and 8 MiB did not. Amber
reads the key once amberframework/amber#1452 is in the pinned release;
earlier Amber ignores it.
@crimson-knight
crimson-knight merged commit 7a54195 into main Nov 20, 2026
11 checks passed
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