Skip to content

perf(channels): skip poll()/show() for drivers with no queued or in-flight work (#5375) #5379

Closed as not planned

Description

@zackees

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

Problem

ChannelManager::onEndFrame() calls show() on every enabled registered driver. Both onBeginFrame() and onEndFrame() then wait by calling poll() on every registered driver through a virtual call (src/fl/channels/manager.cpp.hpp).

On the ESP32-C6 five drivers are registered: RMT, PARLIO, SPI, UART and BIT_BANG. A legacy single-strip RMT frame uses only RMT. Polling and showing the other four costs about 1.2k instructions per show(), about 10% of the total.

Fix

Let the manager skip drivers that have no work:

  • Track per driver whether it has had anything enqueued since its last idle state, or is mid-transmission.
  • Skip show() and poll() for drivers that have nothing pending and nothing in flight.

Constraints

  • Some drivers start transmitting early from enqueue(), and some paths call driver.show() directly. The "has work" signal must be set by the manager on enqueue (or reported by the driver) so those cases are never skipped while busy.
  • A driver that is still draining a previous frame must keep being polled until it reports READY.
  • Add host tests with the mock drivers:
    • an idle driver is not polled;
    • a driver that has had work enqueued is polled until READY;
    • a driver that starts transmitting from enqueue() is waited on.

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

    Triage note (#5375 loop): the original plan here isn't safe as written. Investigation found:

    • IChannelDriver::enqueue() is called directly, bypassing ChannelManager, from SlimBridgeController, SlimSpiBridgeController, Channel::showPixels and rmt5_controller_lowlevel, and from driver-internal delegates (PARLIO → clockless, I2S → SPI). So the manager can't tell on its own that a driver has work. Skipping a driver's poll on a manager-side flag could skip a busy driver and let the next frame overwrite one still in flight.
    • A safe version needs an enqueue generation counter in the IChannelDriver base: a non-virtual enqueue() wrapper that bumps it, calling a protected virtual enqueueImpl(). That means a mechanical rename in about 48 files that override enqueue.
    • Part of each idle poll's cost is the fl::string carried by every DriverState, which is perf(channels): keep fl::string off the IChannelDriver::poll() hot path (#5375) #5380.

    Plan: land #5380 first, then measure the remaining cost of polling idle drivers with fl::InstructionCounter. If it is still about 1k instructions per show(), do the base-class wrapper. Otherwise close this with the measurement.

  3. zackees commented on Nov 22, 2026

    @zackees
    MemberAuthor

    Closing after re-measuring once #5380 landed (PR #5416). Drivers register only when used (#2428; initChannelDrivers() is empty on ESP32), so a default program has exactly one driver in ChannelManager and there are no idle drivers to skip. The legacy RMT gate polls only RMT. After #5380, an idle driver's poll is one virtual call returning a trivially copyable DriverState with no fl::string. Skipping idle drivers would help only programs that call FastLED.enableAllDrivers()/enableDrivers<...>() with drivers that never run, and safely tracking "has work" requires a 48-file enqueue wrapper (see the triage above). That cost isn't justified for an opt-in case. Reopen if a multi-driver profile shows a real poll cost.

  4. 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