Repository navigation
Add a RAM-estimate calibration harness - #159
Merged
Merged
Conversation
estimateFirmwareRam predicts a sketch's RAM from the graph alone, with no compile — that is what lets it run in the browser while the user edits, so this does not replace it with measurement. It checks the prediction against a real build so the two cannot drift apart silently. Palette globals went uncounted for exactly that reason: nothing compared the estimate to reality. Per case it generates the sketch with the real generateCpp, builds it with fbuild for an Uno, reads per-symbol sizes from `fbuild symbols --json`, and buckets those symbols into the categories the estimate models: `leds`, the `buf_*` frame buffers, the `field_*` field buffers, the `paldef_*`/`pal_*` palette tables, and per-node simulation state, which cppGenerator emits as a static inside loop() and the linker keeps as `loop::<name>`. Comparison is against named symbols rather than total RAM, so assertions are exact rather than tolerance-based — a measured total would always sit above the estimate by the Arduino core and FastLED's own statics, which it never claimed to model. That baseline is a constant 373 bytes per Uno build across all five cases, so a future change could predict the total directly by adding a per-board constant. Five cases cover every modelled category and all 25 comparisons are exact. The stateful one is the reason it exists: STATEFUL_EXTRA_BYTES_PER_LED is a hand-maintained table where each entry restates by hand what an emit case allocates, which makes it the likeliest to drift. Fire2012's heat map lands at 64 bytes against a predicted 64. LTO is disabled in the generated project: with it on, AVR merges everything into a single `startup` symbol and per-symbol attribution is impossible. The sketch is written as main.cpp rather than main.ino to avoid fbuild's prototype insertion (FastLED/fbuild#1275), and it builds against the FastLED the upload helper already vendors rather than cloning its own. Gated behind RAM_CALIBRATION=1 since each case is a real compile; it skips in the normal suite. Co-Authored-By: Claude Opus 5 <[email protected]>
stevenmunn312-tech
marked this pull request as ready for review
August 7, 2026 11:07
This was referenced Aug 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the loop opened by #157. That PR fixed
estimateFirmwareRam's palette blind spot; this makes the class of gap detectable instead of relying on someone noticing.Why not just measure
estimateFirmwareRampredicts RAM from the graph alone — no compile, no toolchain, no board selected. That's what lets it run in the browser while you edit, and the live capacity meter already provides measured ground truth via/api/compile-check. Replacing the heuristic with symbol data would duplicate the meter and break the offline path.So this doesn't replace it. It checks the prediction against a real build so the two can't drift apart silently — which is exactly how palette globals went uncounted: nothing compared the estimate to reality.
How it works
Per case: generate the sketch with the real
generateCpp→ build with fbuild for an Uno → read per-symbol sizes fromfbuild symbols --json→ bucket those symbols into the categories the estimate models → compare.ledsbuf_*field_*paldef_*,pal_*loop::*— cppGenerator emits it as astaticinsideloop()Comparing named symbols rather than totals is what makes the assertions exact rather than tolerance-based. A measured total always sits above the estimate by the Arduino core plus FastLED's own statics, which the estimate never claimed to model.
Results — 5 cases, 25 comparisons, all exact
The
fire2012case is the reason this exists.STATEFUL_EXTRA_BYTES_PER_LEDis a hand-maintained table where each entry restates by hand what an emit case allocates, making it the likeliest thing to drift. Its heat map lands at 64 bytes against a predicted 64 (loop::_heat_f).A finding worth following up
The unmodelled baseline is exactly 373 bytes on every Uno build — 757−384, 805−432, 1237−864, 1061−688, 871−496. It's deterministic, so a future change could report predicted total RAM by adding a per-board constant, making the pre-upload readout directly comparable to the linker's figure. Not done here; it needs a measured constant per board.
Constraints baked in, and why
startupblob and per-symbol attribution is impossible — the first version of this returnedtotal_ram=0and zero matches.main.cpp, notmain.ino— avoids fbuild's prototype insertion (ino prototypes are still emitted above the sketch's #includes on 2.5.15 (#1196 still reproduces) FastLED/fbuild#1275).backend/.fbuild-project/lib/FastLED) rather than cloning its own, since registrylib_depsdon't resolve (lib_deps registry entries are never fetched: fbuild sync writes status "unresolved" and the build fails on a missing header FastLED/fbuild#1276). A guard test reports clearly if it's absent.Gated behind
RAM_CALIBRATION=1since each case is a real compile:Skips in the normal suite — 1724 passed, 11 skipped, lint and
tsc -bclean.Known limits
usePsram) changes which bucket a buffer lands in. That path is entirely untested here.Groupnodes still aren't flattened byestimateFirmwareRam, so palettes and buffers inside a group subgraph remain uncounted. Pre-existing, carried over from Count palette tables in the pre-upload RAM estimate #157, and no case here covers it — adding one would fail, which is the honest way to surface it when someone wants it fixed.🤖 Generated with Claude Code