You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(encode): resolve colour order once per strip (experiment; punt if it adds complexity) (#5375) #5378
The colour order (EOrder) is applied per pixel as a runtime permutation. PixelIterator caches mWireOrder[3] and indexes through it for every byte (refreshWireOrder() in src/fl/chipsets/encoders/pixel_iterator.h). The channel API's ReorderingPixelIteratorAny does the same on top of the source's order.
That is three indexed loads per pixel, and it prevents the encoder from treating the three bytes as fixed lanes.
Experiment
Resolve the colour order once per strip as well:
select a kernel specialised on the order (only 6 RGB orders exist); or
encode in source order and fold the wire permutation into the per-byte encode step, so no per-pixel reorder is left.
This builds on the bulk pixel conversion sub-issue and should land after it.
Punt rule
This is worth doing only if it stays simple. Close as not planned, and note the result here, if any of these happens:
it needs more than one new dispatch point in the pipeline;
it multiplies the instantiated kernels in a way that grows bash bloat esp32s3 or any small-tier build;
the instruction-count saving on the C6 is under ~2% of show().
Rules for this sub-issue (from the meta issue)
Keep the layered architecture. Fix this inside its layer. Don't bypass ChannelManager or the channel engine.
Accept on instructions, not wall time. Measure instructions per show() on the ESP32-C6 before and after. Use bash autoresearch esp32c6 --legacy --rmt with the counter from the measurement sub-issue. Put both numbers in the PR. Code layout alone moves wall time by 10–20 µs between builds, so a wall-time number on its own can't show a 5–10% cut.
Usual gates:
bash test --cpp;
bash lint;
a passing AutoResearch run with the show() latency gate on;
bash bloat esp32s3 --build, with no growth past the ratchet.
Keep it small. Don't grow the binary on small-memory tiers (AVR, ATtiny). If a new bulk kernel doesn't pay for itself on FL_PLATFORM_HAS_TINY_MEMORY builds, compile it out of them.
Closing as not planned under this issue's punt rule: the saving on the C6 is under ~2% of show(). The per-pixel runtime permutation this issue describes is gone. Code evidence at master 2f24908a56:
Legacy addLeds path (the C6 latency gate): no runtime reorder.
src/pixel_controller.h:49: #define RO(X) RGB_BYTE(RGB_ORDER, X). loadAndScaleRGB() (:493-497) reads loadAndScale0/1/2(), which index through RO(SLOT) (:330, :357), so PixelController<ORDER> fixes the order at compile time.
src/fl/channels/slim_bridge_controller.h:88: encode_ws2812_rgb_direct calls pixels.loadAndScaleRGB() on the concrete controller. Since perf(encode): bulk RGBW/RGBWW encode, types resolved once per strip (#5377) #5403 the bridge builds no PixelIterator, so PixelIterator::mOrder (src/fl/chipsets/encoders/pixel_iterator.h:997) never leaves its identity default on this path.
Channel API / PixelIterator: the order is hoisted out of the per-pixel loop.
pixel_iterator.h:371-376: refreshWireOrder() composes the iterator order with the source order once, when the order is set (:359-364, called from src/fl/gfx/pixel_iterator_any.h:117), not per pixel.
Size of what's left. The only remaining reorder is that channel-API RGB pass. It is about 3 loads, 3 stores and loop overhead per pixel: roughly 300 instructions for 35 LEDs, against about 15,950 instructions per channel-API show() (#5417). That's about 1.9% of channel-API show(), and 0% of the legacy path. This is an estimate from the loop shape, not a measurement. Removing it would need a kernel specialised per order, or the order folded into the encoder. Either one adds a dispatch point or extra instantiations, which this issue's punt rule also excludes.
A measured channel-API GRB vs RGB (identity) instruction count will follow in the #5422 measurement comment once the ESP32-C6 is free. The AutoResearch cold/warm mode gains order: "rgb"|"grb" to isolate exactly this pass. If that number comes out above 2%, this issue can be reopened.
Correction: the measured number is above the punt threshold, so I'm reopening this.
My closing comment estimated the remaining channel-API reorder pass at about 1.9% of show(). Measured on the ESP32-C6, it is higher. The run used timingDriftTest cold/warm mode (#5426): channel API, 35 LEDs, warm show(), alternated GRB/RGB/GRB/RGB. RGB is the identity order, so loadScaledRGBBulk() skips the pass at src/fl/chipsets/encoders/pixel_iterator.h:478.
Order
Instructions per show()
Cycles
Mean µs
GRB
12,067 / 12,050
36,646 / 36,664
227.9 / 228.0
RGB
11,477 / 11,477
35,926 / 35,932
223.4 / 223.4
The pass costs about 581 instructions, 4.8% of channel-API show() (about 16.6 per pixel; about 730 cycles, 2.0%). The punt clause (under ~2% of instructions) does not apply to the channel API.
The legacy addLeds path is unchanged: its order is fixed at compile time, so the result there is 0%. The code evidence in the previous comment stands.
A fix may be small. The order could be applied while the bulk thunk writes the run, or the pass could be specialised for the 5 non-identity orders, rather than run as a second pass at 16.6 instructions per pixel. It still has to satisfy this issue's other two punt conditions: no more than one new dispatch point, and no growth in bloat on small tiers. Full data is on #5422.
Activity
zackees commentedon Nov 22, 2026
Closing as not planned under this issue's punt rule: the saving on the C6 is under ~2% of
show(). The per-pixel runtime permutation this issue describes is gone. Code evidence at master2f24908a56:Legacy
addLedspath (the C6 latency gate): no runtime reorder.src/pixel_controller.h:49:#define RO(X) RGB_BYTE(RGB_ORDER, X).loadAndScaleRGB()(:493-497) readsloadAndScale0/1/2(), which index throughRO(SLOT)(:330,:357), soPixelController<ORDER>fixes the order at compile time.src/fl/channels/slim_bridge_controller.h:88:encode_ws2812_rgb_directcallspixels.loadAndScaleRGB()on the concrete controller. Since perf(encode): bulk RGBW/RGBWW encode, types resolved once per strip (#5377) #5403 the bridge builds noPixelIterator, soPixelIterator::mOrder(src/fl/chipsets/encoders/pixel_iterator.h:997) never leaves its identity default on this path.slim_bridge_controller.h:121takes the order from the constantPixelControllerT::kColorOrder, resolved once per strip before the run loop.Channel API /
PixelIterator: the order is hoisted out of the per-pixel loop.pixel_iterator.h:371-376:refreshWireOrder()composes the iterator order with the source order once, when the order is set (:359-364, called fromsrc/fl/gfx/pixel_iterator_any.h:117), not per pixel.mWireOrderonce per run (pixel_iterator.h:573,:582).loadScaledRGBBulk()(pixel_iterator.h:467-491) loads a run of up to 32 pixels in one call, then applies the order in one tight pass over the run. That pass is skipped entirely for the identity order (:478).Size of what's left. The only remaining reorder is that channel-API RGB pass. It is about 3 loads, 3 stores and loop overhead per pixel: roughly 300 instructions for 35 LEDs, against about 15,950 instructions per channel-API
show()(#5417). That's about 1.9% of channel-APIshow(), and 0% of the legacy path. This is an estimate from the loop shape, not a measurement. Removing it would need a kernel specialised per order, or the order folded into the encoder. Either one adds a dispatch point or extra instantiations, which this issue's punt rule also excludes.A measured channel-API GRB vs RGB (identity) instruction count will follow in the #5422 measurement comment once the ESP32-C6 is free. The AutoResearch cold/warm mode gains
order: "rgb"|"grb"to isolate exactly this pass. If that number comes out above 2%, this issue can be reopened.zackees commentedon Nov 22, 2026
Correction: the measured number is above the punt threshold, so I'm reopening this.
My closing comment estimated the remaining channel-API reorder pass at about 1.9% of
show(). Measured on the ESP32-C6, it is higher. The run usedtimingDriftTestcold/warm mode (#5426): channel API, 35 LEDs, warmshow(), alternated GRB/RGB/GRB/RGB. RGB is the identity order, soloadScaledRGBBulk()skips the pass atsrc/fl/chipsets/encoders/pixel_iterator.h:478.show()The pass costs about 581 instructions, 4.8% of channel-API
show()(about 16.6 per pixel; about 730 cycles, 2.0%). The punt clause (under ~2% of instructions) does not apply to the channel API.The legacy
addLedspath is unchanged: its order is fixed at compile time, so the result there is 0%. The code evidence in the previous comment stands.A fix may be small. The order could be applied while the bulk thunk writes the run, or the pass could be specialised for the 5 non-identity orders, rather than run as a second pass at 16.6 instructions per pixel. It still has to satisfy this issue's other two punt conditions: no more than one new dispatch point, and no growth in bloat on small tiers. Full data is on #5422.
zackees commentedon Nov 22, 2026
Taking this; branch perf/5378-channel-order-once
test(autoresearch): cold-vs-warm flash-cache show() mode in timingDri…
perf(encode): store channel-API RGB bytes at their wire slot in the b…