Skip to content

perf: replace Apollo3 software SPI half-period countdown overhead #5030

Closed

Description

@zackees

Context

Two source investigation rounds at 94dab9c for #5024; no builds or physical timing measurements. Despite its name, src/platforms/apollo3/fastspi_apollo3.h:5-7,106-117 implements software SPI through fastgpio. Every bit branches for data and runs two countdown loops containing __NOP(), so delay work includes loop overhead rather than only the requested NOP count. The dedicated implementation is included by fastled_apollo3.h:8, defines FASTLED_ALL_PINS_HARDWARE_SPI itself at line 21, and is selected by src/platforms/spi_output_template.h:35-36 through apollo3/spi_output_template.h:15.

Proposal

Replace the compile-time half-period countdown with an inline cycle-delay implementation that accounts for GPIO and loop overhead, with a bounded strategy for long delays. Audit HAL data-write code generation before selecting a branchless data operation; the FastPin port/mask/hival/loval methods return null/zero (fastpin_apollo3.h:46-49), so whole-port streaming and ESP-style register assumptions are not applicable.

Acceptance criteria

  • Capture a focused RED production APOLLO3HardwareSPIOutput repro showing delay-loop branch/instruction overhead at small dividers; implement and show GREEN code-generation and edge-timing evidence. Use the real writeByte/writeBytesValueRaw/writeBytes/writePixels paths, all byte patterns, back-to-back bytes, start bits and delay boundary values, including zero/odd dividers.
  • Compile actual apollo3_red and apollo3_thing_explorable configurations from ci/boards.py:770-780 using the pinned Arduino Apollo3 2.2.0 core. Check HAL fastgpio definitions/assembly and output-capable PAD mappings before using any atomic optimization. Preserve unrelated pin behavior, interrupt assumptions and long-delay behavior.
  • Document requested vs achieved minimum high/low periods from generated instructions and vendor timing. Validate physical waveform with existing AutoResearch/fbuild paths before asserting measured throughput improvements. No host-derived physical-speed claims.
  • Restore the old runtime countdown loop as a mutation; the focused delay/code-generation gate must fail and become GREEN after restoration. Trait/coverage metadata edits alone must not pass.

Decisions

  • One child covers the independent Apollo3 software SPI implementation, not each board wrapper.
  • Delay-loop removal is verified source opportunity; branchless HAL write feasibility remains an investigation step, not an established register capability.
  • Metadata duplicate searches: Apollo3 SPI and exact APOLLO3HardwareSPIOutput; exact search returned none, screened Apollo3 SPI label:sanitized returned none. Unscreened titles/bodies were not read.

Open questions

Verify whether the selected compiler already unrolls particular small dividers; retain only optimizations with actual target instruction evidence. Next step is the focused RED generated-code repro, before changing implementation.

Activity

  1. added
    sanitized
    on Nov 5, 2026
  2. moved this from Triage to Done in FastLED Trackeron Nov 6, 2026
  3. added a commit that references this issue on Nov 8, 2026
    c2fd3de
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