Skip to content

perf(encode): resolve colour order once per strip (experiment; punt if it adds complexity) (#5375) #5378

Done

Description

@zackees

Sub-issue of #5375 (meta), part of #5356.

Problem

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.

Activity

  1. added
    sanitized
    on Nov 21, 2026
  2. zackees commented on Nov 22, 2026

    @zackees
    MemberAuthor

    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.
    • RGBW/RGBWW there (perf(encode): bulk RGBW/RGBWW encode, types resolved once per strip (#5377) #5403): slim_bridge_controller.h:121 takes the order from the constant PixelControllerT::kColorOrder, resolved once per strip before the run loop.

    Channel API / PixelIterator: the order is hoisted out of the per-pixel loop.

    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.

  3. moved this from Triage to Done in FastLED Trackeron Nov 22, 2026
  4. zackees commented on Nov 22, 2026

    @zackees
    MemberAuthor

    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.

  5. moved this from Done to Triage in FastLED Trackeron Nov 22, 2026
  6. zackees commented on Nov 22, 2026

    @zackees
    MemberAuthor

    Taking this; branch perf/5378-channel-order-once

  7. moved this from Triage to Done in FastLED Trackeron Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    sanitized

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions