Skip to content

perf: WS2812 encode in SlimBridgeController costs ~115 µs for 35 LEDs (type-erased PixelIterator path) #5357

Closed

Description

@zackees

Sub-issue of #5356 (largest remaining show() cost after #5350).

Measured on an ESP32-C6 on the RMT5 legacy path (bash autoresearch esp32c6 --legacy --rmt), replaying the #2994 workload (35 WS2812 LEDs, show() every 5 ms). Numbers come from temporary per-phase timers, averaged over 864 frames:

phase µs/frame
SlimBridgeController::showPixels → PixelIterator::writeWS2812 (encode) ~115
RMT driver.show() ~156
onBeginFrame wait ~73
the rest of showLedsInternal (adjustment, gates, reserve, enqueue) ~49

The timers add some overhead of their own.

Cause. writeWS2812 encodes through the type-erased PixelIterator. For every pixel, ScaledPixelIteratorRGB::advance() makes four calls through function pointers (has, loadAndScaleRGB, stepDithering, advanceData), and each of the three output bytes then goes through back_inserter, which checks capacity on every byte. That works out to about 3.3 µs (~500 cycles) per pixel for what is three scale-and-store operations.

Fix. SlimBridgeController already holds the concrete PixelController<RGB_ORDER>. For plain RGB (the WS2812 case), encode straight from it into a buffer sized up front, with every call inlined. RGBW and RGBWW keep the PixelIterator path. The output is byte-identical: the same loadAndScaleRGB → stepDithering → advanceData sequence.

Metadata

Metadata

Assignees

No one assigned

    Labels

    sanitizedtype: bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions