Repository navigation
perf(encode): bulk RGB encode for the channel API path, plus a channel-API show() measurement (#5399) - #5417
Conversation
…l-API show() measurement (#5399) PixelIterator::writeWS2812() for plain RGB now loads, scales, dithers and advances a run of up to 32 pixels in one type-erased call (loadScaledRGBBulk) and applies the colour order over the run, instead of four type-erased calls and three capacity-checked appends per pixel. Byte-identical to the per-pixel ScaledPixelIteratorRGB path; a new host test compares the two across all six colour orders, three brightness scales, dithering on and off, and odd lengths. AutoResearch timingDriftTest takes "api": "channel" to register the same 35-LED strip with FastLED.add(), and the host driver gains --api and prints instructions per show().
|
@coderabbitai review |
|
Caution Review failedThe pull request is closed. Note
|
| Layer / File(s) | Summary |
|---|---|
Channel-API timing measurement ci/autoresearch/test_timing_drift.py, examples/AutoResearch/AutoResearchRemoteDriverMethods.cpp, examples/AutoResearch/AutoResearchTimingDrift.h |
The CLI and RPC accept legacy or channel and report the selected API. The timing runner registers a channel with FastLED.add() for channel measurements, then removes it after measurement. The CLI also reports instruction counts when available. |
Bulk RGB encoding and equivalence tests src/fl/chipsets/encoders/pixel_iterator.h, tests/unit/fl/chipsets/encoders/pixel_iterator.hpp |
The WS2812 plain RGB path loads and writes batches of up to 32 pixels, using a per-pixel fallback when no bulk loader is bound. Tests compare output length and bytes with the per-pixel encoder across color orders, brightness values, dither modes, and controller types. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Refactor
Sequence Diagram(s)
sequenceDiagram
participant TimingCLI as test_timing_drift.py
participant TimingRPC as timingDriftTest handler
participant DriftRun as timing_drift::run
participant FastLED
participant Measure as measureShows
TimingCLI->>TimingRPC: send selected api
TimingRPC->>DriftRun: call run with channel selection
DriftRun->>FastLED: register strip with FastLED.add
DriftRun->>Measure: measure registered strip
Measure-->>DriftRun: return timing results
DriftRun-->>TimingRPC: return results and selected api
TimingRPC-->>TimingCLI: report timing results
sequenceDiagram
participant WriteWS2812 as PixelIterator::writeWS2812
participant WriteRGBBulk as PixelIterator::writeRGBBulk
participant LoadBulk as PixelIterator::loadScaledRGBBulk
participant Controller as PixelControllerVtable
WriteWS2812->>WriteRGBBulk: encode plain RGB output
WriteRGBBulk->>LoadBulk: load up to 32 pixels
LoadBulk->>Controller: load, scale, dither, and advance pixels
Controller-->>LoadBulk: return processed pixel count and RGB bytes
LoadBulk-->>WriteRGBBulk: return wire-order RGB bytes
WriteRGBBulk-->>WriteWS2812: append encoded bytes
Possibly related issues
- FastLED/FastLED#5356 — This change reduces RGB encoding work on the channel path, one of the CPU cost phases described in the issue.
- FastLED/FastLED#5377 — This change adds bulk RGB conversion for the WS2812 path and byte-equivalence tests. It does not cover the issue’s RGBW or other encoder paths.
Possibly related PRs
- FastLED/FastLED#5389 — It adds the instruction-count result fields that this change reports for channel-path timing.
Merge Risk: 
Low · up to b588c
-
Bulk RGB encoding for WS2812 is verified byte-for-byte against the per-pixel path in tests. A latent hang exists if a fixed-capacity output buffer is ever used, and the channel timing benchmark uses a different colour order than the legacy one. Both are small fixes and no current caller is affected, so the merge risk is low.
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.
Memory usage (this PR vs. its merge base)Change in
|
Action not completed
|
Closes #5399. Refs #5375 / #5356.
Why
The channel API (
FastLED.add()→Channel::encodeWS2812→PixelIteratorAny→PixelIterator::writeWS2812()) still encoded plain RGB one pixel at a time. Each pixel took four type-erased calls (has, loadAndScaleRGB, stepDithering, advanceData) and three capacity-checkedback_inserterappends.What
PixelControllerVtable::loadScaledRGBBulk: one type-erased call per run of up to 32 pixels. It runs the per-pixelScaledPixelIteratorRGBsequence (has, loadAndScaleRGB, stepDithering, advanceData) inline. It is bound throughRawPremixBinder, so likeloadRawBulkfrom perf(encode): bulk RGBW/RGBWW encode, types resolved once per strip (#5377) #5403 it is bound only forPixelControllersources and not on AVR.PixelIterator::loadScaledRGBBulk(out, max): the public wrapper. It applies the iterator's colour order over the run. Sources without the thunk (colour-managed, AVR) fall back to the per-pixel sequence.writeWS2812()for RGB fills a 32-pixel stack run and appends it with one resize per run. RGBW/RGBWW (perf(encode): bulk RGBW/RGBWW encode, types resolved once per strip (#5377) #5403) are unchanged.timingDriftTestaccepts"api": "channel", which registers the same 35-LED WS2812 strip (800 kHz, GRB) withFastLED.add()instead ofaddLeds.ci/autoresearch/test_timing_drift.pygains--api {legacy,channel}and prints instructions pershow().Equivalence test (written first; it passed on master)
tests/unit/fl/chipsets/encoders/pixel_iterator.hppcompareswriteWS2812()with the per-pixelmakeScaledPixelRangeRGB+encodeWS2812_RGBpath byte for byte. It covers:DISABLE_DITHERandBINARY_DITHERacross dither frames;PixelController<RGB, 1, 0xFFFFFFFF>source (the channel API's) and aPixelController<GRB>source;A second case goes through
PixelIteratorAnyas the channel does. A deliberately broken permutation makes it fail.Measurement (ESP32-C6, 160 MHz, 35 LEDs, RMT,
fl::InstructionCounter)Each column is
timingDriftTest, run on a separate build of the same AutoResearch firmware. The only difference between the builds ispixel_iterator.h.show()show()show()(timingDrift)bash autoresearch esp32c6 --legacy --rmt)Unexplained legacy delta. The legacy
addLedspath doesn't reach any changed code:SlimBridgeControllerencodes directly and never constructs aPixelIterator. Even so, the legacy count rose by about 400–800 instructions and the wall time by about 60 µs. This reproduced across two separate flashes of this branch, and the cycles pershow()rose from 25.7k to 35.3k. It looks like a code-layout effect. One possibility is that the counter includes ISR work, such as RMT refill interrupts, that falls inside a longershow()window. I haven't verified that, so please treat it as an open question rather than a result.Validation
bash test encodersandbash test encoders --debugpass.bash test --cpp: 377/377 unit and 97/97 examples pass.bash lintpasses.bash autoresearch esp32c6 --legacy --rmtpasses, latency gate included.bash bloat esp32s3 --buildlocally. Blink takes the legacyaddLedspath, which doesn't construct aPixelIterator, so the new thunk isn't linked there. Hosted bloat CI is the check.Follow-up (not in this PR)
The other
ScaledPixelIteratorRGBencoders (APA102, SK9822, TM1908, UCS7604, HD108) still load per pixel. MakingScaledPixelIteratorRGBrefill in runs needs a run buffer inside an iterator that is copied by value as a begin/end pair, and it changes how far ahead the shared cursor moves relative to the brightness adapter. That isn't clean enough to fold in here. These encoders can callPixelIterator::loadScaledRGBBulk()directly when they are measured.Summary by CodeRabbit