Skip to content

perf: hoist runtime SPI channel configuration and GPIO dispatch #5050

Closed

Description

@zackees

Context

Two source investigation rounds at 94dab9c for #5024; no builds/tests. src/platforms/shared/bitbang/bus_traits.h:35-56 registers BitBangChannelDriver for Bus::BIT_BANG and SpiChipsetConfig on supported platforms (LPC845 PWM_DMA and RP custom fallback excluded). show() routes SPI channels into transmitSpi (bitbang_channel_driver.cpp.hpp:324-346). Its inner bit loop (:269-301) re-fetches each channel's SpiChipsetConfig, data pin, slot lookup, data buffer and bounds for every bit of every byte, then builds dataMask with a data branch. It calls DigitalMultiWrite8::writeByte and runtime digitalWrite/delayNanoseconds for each clock edge.

src/fl/system/pins.h:46-51 uses two nibble LUT lookups, but src/fl/system/pins.cpp.hpp:254-260 still walks per-pin lists and calls runtime digitalWrite. This is a separate runtime SPI implementation, not the generic compile-time template. Only its SPI path belongs here; clockless timing is excluded.

Proposal

Pre-resolve per-group lane pointers, sizes, slots and clock operation/timing once before the bit loop; construct data masks without repeated configuration lookup or per-data-bit branches. Where platform evidence supports it, batch resolved GPIO operations using atomic/masked register semantics. Retain a portable fallback and preserve mixed-bank/pin constraints.

Acceptance criteria

  • First show a focused RED production Bus::BIT_BANG SPI path trace/code-generation/counter signal, then GREEN using actual ChannelData/enqueue/show. Include all byte values, unequal lane lengths/zero padding, 1-8 lanes, invalid/skipped/duplicate pin mappings, multiple clock groups, different rates, empty transfers and repeated shows/reconfiguration.
  • Prove invariant configuration/slot resolution occurs outside per-bit loops; do not replace behavior with a copied test writer. Trace MSB-first data stability, rising/falling clock order and minimum half periods; preserve unrelated GPIO under interrupts and test same/different GPIO banks.
  • Compile representative real ESP32, ESP8266 and CI13XX configurations plus conservative fallback. Host capture tests cannot establish vendor register capability or device timing. Any physical throughput claim requires actual AutoResearch/fbuild evidence. Explicitly preserve clockless behavior and custom LPC/RP driver exclusions.
  • Restore old per-bit config resolution and GPIO dispatch as mutations: focused assertions must fail and become GREEN after restoration. Changing coverage flags, LUT metadata or dead code cannot satisfy shared gate test: gate software SPI changes on exhaustive production-path and mutation evidence #5031.

Decisions

  • One child covers this independent runtime channel loop and the DigitalMultiWrite8 operation cost it actually invokes; avoid speculative global GPIO redesign.
  • Exact screened duplicate query BitBangChannelDriver SPI label:sanitized returned none; no unscreened text read.

Open questions

Quantify target compiler hoisting before deciding which changes deliver instruction reduction. Next step is a production-path RED repro and preserved channel semantics, not an invented physical speedup.

Activity

  1. added
    sanitized
    on Nov 5, 2026
  2. zackees commented on Nov 7, 2026

    @zackees
    MemberAuthor

    #5128 hoists lane, mask and frequency lookups out of the bit loop, so this stays open. Still unmet: a RED signal and restore-old-resolution mutation for the hoist, saved code generation, GPIO batching, a CI13XX build, tests for different rates, GPIO banks and half-period minimums, reconfiguration, unrelated GPIO under interrupts, and gate #5031. Rate and setup-time issues are in #5127.

  3. zackees commented on Nov 22, 2026

    @zackees
    MemberAuthor

    Closing with an accepted limitation.

    Fix: #5128 (607d909). The bitbang SPI channel driver resolves each lane's data, size and pin mask once per transfer, before the bit loop (src/platforms/shared/bitbang/bitbang_channel_driver.cpp.hpp:273-293). Lane, mask and frequency lookups are no longer repeated per bit.

    Proven by: tests/platforms/shared/bitbang/bitbang_channel_driver.cpp.

    Accepted limitations:

    • No failing-first test or restore-old-resolution mutation for the hoist, and no saved codegen.
    • GPIO batching is not delivered.
    • No tests for different rates, GPIO banks, half-period minimums, reconfiguration, or unrelated GPIO under interrupts.
    • No CI13XX build: there is no CI13XX board entry in ci/boards.py.
    • Rate and setup-time issues are tracked separately in BitBangChannelDriver SPI: first channel's rate wins, and data setup time is minimal #5127.

    The #5031 binding is replaced by a rescoped host-side gate, tracked in #5031.

  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