E0021: budget_exceeded
E0021 budget_exceeded — a declared memory budget is lower than the proven peak.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0021).
The rule
A memory: "64Mi" line in a cell's scale section is a budget that soma check compares with the peak memory it computes for the cell (slots, the largest handler, state machines, runtime). Building a list of nine million Ints in one handler gives a peak of about 161 MiB, so the 64 MiB budget is refused. Raise the budget above the reported peak, or change the handler so it does not build the large value (here len(range(0, n)) is just n).
A program that triggers it
wrong.cell
cell ReportBuilder {
scale {
replicas: 1
memory: "64Mi"
}
on daily_ids() {
let ids = range(0, 9000000)
return len(ids)
}
}What soma check prints:
$ soma check wrong.cell
error: budget exceeded in cell 'ReportBuilder': proven peak 161.33 MiB > declared budget 64.00 MiB
--> wrong.cell:2:5
|
2 | scale {
| ^
= code: E0021
✗ 1 error(s), 0 warning(s).The fix field of soma check --json: budget exceeded in cell 'ReportBuilder': proven peak 161.33 MiB > declared budget 64.00 MiB
The fix
On line 4, memory: "64Mi" becomes memory: "1Gi".
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -2,5 +2,5 @@
scale {
replicas: 1
- memory: "64Mi"
+ memory: "1Gi"
}
on daily_ids() {With the fix, soma check accepts the program:
$ soma check right.cell
✓ budget holds for cell 'ReportBuilder' while its slots stay within their assumed sizes: peak ≤ 161.33 MiB ≤ declared 1.00 GiB
breakdown: slots 0 B + max-handler 145.33 MiB + state 0 B + runtime 16.00 MiB
assumed: each slot within [capacity(N)] / [max_key_bytes(N)] / [max_value_bytes(N)] (else 10 000 entries of 256-byte keys and 4 KiB values) — not enforced at run time
✓ All checks passed (1 note above).