Repository navigation
perf(hd108): stop computing a constant brightness header per LED (partial #4402) - #4403
Conversation
`hd108BrightnessHeader` discards its argument -- `(void)brightness_8bit`, then three `constexpr` gains of 31 -- and returns 0xFF 0xFF for every input. Both HD108 encode paths were doing work to feed it anyway. `encodeHD108_HD` carried a per-LED cache (`lastBrightness8`, `lastF0`, `lastF1`, plus a compare/branch) guarding against recomputing a value that cannot change, and dereferenced `brightness_first` once per LED to feed it. That read was the expensive half: the sole in-tree caller passes `ScaledPixelIteratorBrightness`, whose `load()` is out of line, so it was a function call per LED to fetch a number that reached nothing. `writeHD108`'s managed path built that whole adapter -- `makeScaledBrightness` plus a `load()` -- for the single purpose of passing a value into the same discarding function. Both are gone. The header is computed once per strip. Output is unchanged by construction, not by measurement: every removed value fed only an argument that is cast to void. Why now: the esp32dev size gate has been red on master since #4387 at 340235 B against a frozen 340000 B ceiling. `ci/lint/check_size_thresholds.py` exists because "CI agents have repeatedly tried to fix red size-check workflows by raising the thresholds instead of fixing the underlying regression", so the ceiling stays and the bytes come out of the code. #4402 has the full diagnosis. A new test pins the premise: HD108 output is byte-identical across brightness 0, 255 and a 0->255 ramp, and the header really is the pinned maximum rather than merely constant. Verified load-bearing -- making `hd108BrightnessHeader` honour its argument fails it by name, along with ten siblings that assert the pinned header. The stale "brightness caching optimization" case is renamed to what it actually checks, since the cache it was named for no longer exists. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughHD108 encoding ignores per-LED brightness values and writes one fixed maximum brightness header. The managed wide path uses the same behavior. Tests verify identical output across brightness inputs. Size tracking records a 66-byte reduction. ChangesHD108 header behavior
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~15 minutes Change: Refactor Merge Risk: ⚪ Minimal · up to The encoder cleanup preserves the intended HD108 output while reducing code size, with regression tests and size validation passing. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
With the per-LED brightness read and its cache gone, `encodeHD108_HD` is `encodeHD108` with an extra argument. Both walk `makeScaledPixelRangeRGB`, both widen through `hd108GammaCorrect`, both frame with the same start and latch, and both headers come from `hd108BrightnessHeader`, which pins every gain at 31 whatever it is handed. So a build with FASTLED_HD_COLOR_MIXING was carrying a second copy of one function. `writeHD108` now calls `encodeHD108` on either branch and the `#if` around the call site goes away. `encodeHD108_HD` stays in hd108.h for source compatibility. A new test asserts the two agree byte for byte across five pixels and five brightness values, so the collapse cannot quietly stop being true -- if a real per-LED brightness ever lands, that test fails and says so. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
The gate fails on an unexplained *drop* past its 64 B tolerance, which is the ratchet asking for the win to be recorded rather than left as headroom. 342957 -> 342891. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
Partial. Recovers 52 B of the 235 B that #4402 needs. master stays red on
check_esp32_sizeafter this; I am not claiming otherwise.Why bytes and not a bigger ceiling
check_esp32_sizehas been red on master since #4387 (esp32dev size 340235 is greater than max size 340000).ci/lint/check_size_thresholds.pyis explicit about the tempting fix:So the ceiling stays untouched and the bytes come out of the code.
What was dead
hd108BrightnessHeaderdiscards its argument and pins every gain at 31:It returns 0xFF 0xFF for every input. Both encode paths did work to feed it:
encodeHD108_HDkept a per-LED cache (lastBrightness8,lastF0,lastF1, a compare/branch) guarding against recomputing a value that cannot change, and dereferencedbrightness_firstonce per LED to feed it. That read was the costly half — the only in-tree caller passesScaledPixelIteratorBrightness, whoseload()is out of line, so it was a call per LED for a number that reached nothing.writeHD108's managed path built that adapter purely to pass a value into the discarding function.Both gone; the header is computed once per strip. Then, with the cache removed,
encodeHD108_HDisencodeHD108with an extra argument, sowriteHD108now calls one encoder instead of one perFASTLED_HD_COLOR_MIXINGbranch.Output is unchanged by construction, not by measurement — every removed value fed only an argument that is cast to void.
Measured, on this PR's own esp32dev run
The second step was worth almost nothing — the compiler had already folded the duplicate. Recorded because it is the kind of change that looks like it should pay and does not.
Tests
[#4402] HD108 output does not depend on brightness at all— byte-identical across brightness 0, 255 and a 0→255 ramp, and the header is the pinned maximum, not merely constant.[#4402] encodeHD108 and encodeHD108_HD agree byte for byte— justifies the collapse.Both load-bearing: making
hd108BrightnessHeaderhonour its argument fails the first by name, along with ten siblings. The stale"brightness caching optimization"case is renamed, since the cache it named is gone.bash test --cpp304/304 unit + 84/84 examples;bash lintclean; size-thresholds lockdown passes (numbers untouched — the workflow file gains a comment only, which is also what makes the esp32dev gate run on this PR instead of only after merge).Blocker found for the remaining 183 B
The esp32dev Symbol Analysis step in this same workflow reports
Total symbols: 0. It probes.build/pio/esp32dev/.pio/build/esp32dev/firmware.elfwhile the build produces an fbuild artifact under.fbuild/, so everyreadelf/nm/objdumpcall exits 1 and the report is empty — undercontinue-on-error: true, silently. Same two-layout confusion fixed forbash bloatin #4386.That is why the rest of this has to be guesswork, and it is worth fixing before hunting further. Noted in #4402.
🤖 Generated with Claude Code
https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
Summary by CodeRabbit
Bug Fixes
Tests