Skip to content

perf(hd108): stop computing a constant brightness header per LED (partial #4402) - #4403

Merged
zackees merged 3 commits into
masterfrom
perf/4402-hd108-drop-dead-brightness
Sep 12, 2026
Merged

zackees merged 3 commits into
masterfrom
perf/4402-hd108-drop-dead-brightness

Conversation

@zackees

@zackees zackees commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

Partial. Recovers 52 B of the 235 B that #4402 needs. master stays red on check_esp32_size after this; I am not claiming otherwise.

Why bytes and not a bigger ceiling

check_esp32_size has been red on master since #4387 (esp32dev size 340235 is greater than max size 340000). ci/lint/check_size_thresholds.py is explicit about the tempting fix:

CI agents have repeatedly tried to "fix" red size-check workflows by raising the max_size thresholds instead of fixing the underlying regression.

So the ceiling stays untouched and the bytes come out of the code.

What was dead

hd108BrightnessHeader discards its argument and pins every gain at 31:

inline void hd108BrightnessHeader(u8 brightness_8bit, u8* f0_out, u8* f1_out) {
    (void)brightness_8bit;  // Unused
    constexpr u8 r_gain = 31; /* g_gain, b_gain likewise */

It returns 0xFF 0xFF for every input. Both encode paths did work to feed it:

  • encodeHD108_HD kept a per-LED cache (lastBrightness8, lastF0, lastF1, 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 costly half — the only in-tree caller passes ScaledPixelIteratorBrightness, whose load() 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_HD is encodeHD108 with an extra argument, so writeHD108 now calls one encoder instead of one per FASTLED_HD_COLOR_MIXING branch.

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

esp32dev Blink
master 340,235 B
drop the per-LED brightness work 340,187 B (−48)
collapse the duplicate encoder 340,183 B (−4)
ceiling 340,000 B

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 hd108BrightnessHeader honour 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 --cpp 304/304 unit + 84/84 examples; bash lint clean; 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.elf while the build produces an fbuild artifact under .fbuild/, so every readelf/nm/objdump call exits 1 and the report is empty — under continue-on-error: true, silently. Same two-layout confusion fixed for bash bloat in #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

    • HD108 LED output now uses a consistent brightness header across the strip.
    • Per-LED brightness values no longer affect HD108 output, preventing inconsistent color data.
    • Standard and high-definition HD108 encoding paths now produce matching output bytes.
  • Tests

    • Added regression coverage verifying brightness independence and identical encoder output.

`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
@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: f88ee02a-3b09-4eac-b3fb-5689c0f18a93

📥 Commits

Reviewing files that changed from the base of the PR and between c57ad28 and 80e3b7e.

📒 Files selected for processing (1)
  • tests/data/esp32s3_bloat_baseline.txt

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

HD108 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.

Changes

HD108 header behavior

Layer / File(s) Summary
Fixed HD108 header encoding
src/fl/chipsets/encoders/hd108.h, src/fl/chipsets/encoders/pixel_iterator.h
The encoder no longer reads or advances the brightness iterator. It computes the header once with pinned maximum gains. The managed wide path uses fixed brightness values for HD108 output.
Regression coverage and size tracking
tests/fl/chipsets/encoders/hd108.hpp, tests/data/esp32s3_bloat_baseline.txt, .github/workflows/check_esp32_size.yml
Tests verify identical output for different brightness inputs and confirm 0xFF/0xFF header bytes. The baseline records a reduction from 342957 to 342891 bytes. The workflow comment records the frozen threshold regression check.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to 80e3b

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the HD108 performance change: it removes redundant per-LED computation of a constant brightness header. The scope marker is consistent with the documented partial implemen…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

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.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/4402-hd108-drop-dead-brightness

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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
@zackees zackees changed the title perf(hd108): stop computing a constant brightness header per LED (#4402) perf(hd108): stop computing a constant brightness header per LED (partial #4402) Sep 12, 2026
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
@zackees
zackees merged commit e8ef4a5 into master Sep 12, 2026
25 of 26 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 12, 2026
@zackees
zackees deleted the perf/4402-hd108-drop-dead-brightness branch November 5, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant