Skip to content

perf(encode): bulk RGB encode for the channel API (FastLED.add) path, plus a channel-API latency measurement (#5375) #5399

Closed

Description

@zackees

Sub-issue of #5375 (meta), part of #5356. Found while doing #5377.

Problem

#5358 (RGB) and #5377 (RGBW/RGBWW) moved the legacy addLeds encode off the per-pixel type-erased PixelIterator. The channel API (FastLED.add(ChannelConfig), Channel::encodeWS2812 in src/fl/channels/channel.cpp.hpp) still encodes plain RGB one pixel at a time:

  • ReorderingPixelIteratorAny → PixelIterator::writeWS2812() → makeScaledPixelRangeRGB → ScaledPixelIteratorRGB::advance();
  • per pixel, that is four type-erased calls (has, loadAndScaleRGB, stepDithering, advanceData) plus three capacity-checked back_inserter appends.

The other ScaledPixelIteratorRGB encoders (APA102, SK9822, TM1908, UCS7604, ...) share the same per-pixel cost. On the legacy path, the same change took show() from 357 to ~219 µs (#5357).

AutoResearch has no channel-API latency measurement, so the cost isn't measured yet.

Fix

  1. Measurement first: a channel-API mode for timingDriftTest ("api": "channel") that adds the same 35-LED strip with FastLED.add() instead of addLeds, so fl::InstructionCounter reports instructions per show() for that path.
  2. Bulk RGB load in PixelIterator: a loadScaledRGBBulk thunk (load + scale + dither step + advance for a run of pixels, one type-erased call per run), with the iterator's colour order applied over the run.
  3. Encoders: writeWS2812() for RGB uses it directly. If it pays for itself, ScaledPixelIteratorRGB refills from it in runs, so APA102/SK9822/TM1908/UCS7604 benefit without changes.

Constraints

  • Byte-identical output for every encoder, colour order and dither mode, with host tests that compare against the per-pixel path.
  • The ESP32-S3 Blink image must not grow (the bloat ratchet). The new thunk is linked only where PixelIterator is constructed.

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 22, 2026
  2. zackees commented on Nov 22, 2026

    @zackees
    MemberAuthor

    Picking this up; branch perf/5399-channel-bulk-rgb

  3. moved this from Triage to Done in FastLED Trackeron Nov 22, 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