Repository navigation
Count palette tables in the pre-upload RAM estimate - #157
Merged
Merged
Conversation
estimateFirmwareRam ignored CRGBPalette16 globals entirely, under-reporting by up to ~1.4KB — the gap that let the unused-palette bloat sit unnoticed until a real build measured it. Resolves them the way cppGenerator's paletteExpr does, reading palette-typed input ports from NODE_LIBRARY rather than restating which nodes consume one: one shared paldef_ table per distinct named palette, plus one pal_<id> per palette-building node (CustomPalette, PaletteFromImage, PaletteBlend, Poline). Only nodes reachable from MatrixOutput count, matching how the rest of the estimate already works. Palettes are always internal RAM — codegen never PSRAM-allocates them — so they land in internalBytes regardless of the usePsram toggle. Errs toward over-counting if an emit case declares a palette port it never samples, which is the safe direction for a pre-upload budget. Verified against a real Uno build: the estimate's 48 bytes for a single-palette Plasma sketch matches the paldef_ symbols fbuild reports in .bss. Co-Authored-By: Claude Opus 5 <[email protected]>
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.
Follow-up to #156. That PR removed ~1.4 KB of unused palette globals from generated sketches; this fixes the estimator that should have flagged them and didn't.
The gap
estimateFirmwareRamignoredCRGBPalette16globals entirely. It counted theledsarray, per-nodebuf_/field_render buffers, and known simulation state — but not palette tables, which are non-const globals at 48 bytes each. On a pre-#156 sketch that was ~1.4 KB invisible to the one thing meant to warn you before an upload.That blind spot is why the bloat survived: nothing that looked at RAM could see the largest single contributor.
How it resolves them
The same way
cppGenerator'spaletteExprdoes, rather than restating which nodes consume a palette:NODE_LIBRARY, so the estimator and codegen follow one source. Adding a palette input to a node keeps both in step with no second list to maintain.paldef_<name>per distinct named palette — two nodes onoceancost 48 bytes, not 96.pal_<id>per palette-building node (CustomPalette,PaletteFromImage,PaletteBlend,Poline); a consumer wired to one resolves to that table instead of also pulling in a shared one.MatrixOutputcount, matching how the rest of the estimate already works.Palettes land in
internalBytesregardless of theusePsramtoggle, because codegen never PSRAM-allocates them.Where the two could disagree, it over-counts — if an emit case declares a palette port it never samples. That's the safe direction for a pre-upload budget.
Verification
Checked against a real Arduino Uno build, not just unit tests: the estimate's 48 bytes for a single-palette Plasma sketch matches the
paldef_symbolsfbuild symbolsreports in.bssfor the same graph.Gates green — lint,
tsc -b, 1724 tests passed.Three new tests cover distinct-palette deduplication, builder nodes resolving to their own table, and unreachable nodes being ignored. One existing
ColorTrailsexpectation moved 144 → 192 bytes: it has apaletteInport, so the sketch genuinely does declare a table for it — the old number was the bug.Also in here
CHANGELOG.mdentries from #156 corrected with the measured figures. They shipped quoting my arithmetic (~1.1 KB) rather than the real Uno numbers — 1,056 B of RAM and 7,960 B of flash. The flash half was unaccounted for entirely: these globals carry dynamic initialisers, so each also emits startup constructor code at roughly 360 B apiece. An unused palette cost ~408 B total, not 48.Not in here
-fltodisabled, or AVR collapses every symbol into onestartupblob with nothing to compare per-node.estimateFirmwareRamdoesn't flattenGroupnodes, so palettes used only inside a group subgraph still aren't counted. Pre-existing and unchanged here.🤖 Generated with Claude Code