Repository navigation
Description
Status
Parked. Prototyped in PR #2357 (closed unmerged). The design is viable and compile-verified across ESP32-dev / S3 / C3 and host, but we lack the hardware measurement and the user-facing threading contract to justify shipping it. Re-open once option (A) of #2308 (ESP-DSP FFT backend) lands and we have a measured FPS gap that this work would specifically close.
This issue is the canonical record of what we tried, what worked, and what remains uncertain.
What was attempted
Two layers introduced in PR #2357:
1. fl::task::Worker — one-shot functor worker, core-pinnable
A blocking run(fn) primitive. Internally on dual-core ESP32 it spawned a persistent FreeRTOS task pinned to the requested core and handed fn across via two binary semaphores (one to signal work pending, one to signal completion). On single-core ESP32 and non-ESP32 platforms it fell through to synchronous in-thread execution with the same API.
Key property we settled on: the audio pump remains a one-shot functor — no long-running coroutine loop. The scheduler's every_ms(1) tick keeps ownership of the cadence; only the body of work hops cores.
2. Processor::setCoreAffinity(int core) — portable opt-in
Accepts -1 / 0 / 1. On dual-core ESP32 it created a pinned Worker; the per-tick pump closure was routed through worker->run(pump_fn). Everywhere else it was a silent no-op. The scheduler still drove every_ms(1).
3. AutoResearch validation hooks
Three RPC handlers registered against testCoroutineAll:
testCoroutineCoreAffinity— confirmsCoroutineConfig::core_idpins viaxPortGetCoreID()read inside the lambda.testWorkerAffinity— end-to-end Worker check per core.testFftBackendTiming— times the currently-compiled FFT backend against a single-tone sine for head-to-head comparison across builds.
What worked
- Core-id plumbing (
CoroutineConfig::core_id) — phase 1 from feat(esp32): honor CoroutineConfig::core_id for task affinity #2337 is clean and functional.xPortGetCoreID()inside a coroutine consistently matches the requested core on ESP32-S3 per the host-compile harness. This stays in master and is the correct foundation. - One-shot functor model — avoided the long-running-loop pitfall (cache-cache contention for the detector state, wake-up timing). The pump closure is invoked once per every_ms(1) tick and returns.
- Fallback-to-synchronous on single-core — the same user code (
proc->setCoreAffinity(0)) compiles and runs on ESP32-C3 without special-casing, because Worker's factory selects the null impl. - Compile matrix green across ESP32-dev, S3, C3 plus host unit tests. The prototype was compile-correct.
What did NOT work / unresolved
-
Platform-neutrality was broken in the prototype. The
fl::task::WorkerandProcessor::setCoreAffinitybodies includedplatforms/esp/32/feature_flags/enabled.hand contained#ifdef FL_IS_ESP32gates inline. This violates FastLED's trampoline architecture (code infl/**must not deep-include platform headers). A refactor intosrc/platforms/worker.h+ per-platform.impl.hppfiles would fix this cleanly (the coroutine subsystem already has the exact pattern inplatforms/coroutine.impl.cpp.hpp), but the refactor was not completed before parking. -
User callback threading contract is unresolved. When
setCoreAffinity(0)offloads the pump to core 0, the user callbacks registered viaprocessor->onBass(...),onBeat(...),onVibeLevels(...), etc. fire on core 0 — not the main loop thread. If the user touchesFastLED.show()or mutates LED arrays from inside those callbacks, they hit a cross-core race. The library cannot detect this at compile time and can only warn via docstring. Whether this is an acceptable UX was never resolved. -
No hardware measurement of the actual FPS win. The issue perf(audio): optimize audio processing pipeline to restore LED FPS #2308 posits that audio detectors eat 40 FPS on ESP32-S3 under a WS2812B-heavy workload and that offloading to core 0 would recover most of it. That claim is plausible (audio cost ~165 µs/sample, LED show depends on strip length) but it was never measured end-to-end with the Worker in place. Without a number, we can't justify the API-surface cost.
-
Semaphore round-trip cost vs. workload. A FreeRTOS binary semaphore handshake is on the order of 2–5 µs round-trip on ESP32. Audio work per tick is ~165 µs when all detectors are active, so the semaphore overhead is ~2–3 % of pump cost — acceptable. But on very small audio configs (only
BeatDetector+TempoAnalyzer, ~50 µs total) the overhead climbs to 5–10 %, which erodes the win. -
Option (A) of perf(audio): optimize audio processing pipeline to restore LED FPS #2308 covers much of the same gap at lower complexity. Swapping the FFT backend from
kiss_fftrto ESP-DSP is an API-surface-zero change that recovers an expected ~35 µs per frame for every FFT-consuming detector. It was already in progress in master (refactor(audio/fft): dispatcher for ESP-DSP FFT backend #2310, feat(audio/fft): ESP-DSP backend + AudioFftParity hardware validation harness #2315) at the time this branch was written. Ship option (A) first, re-measure, then decide if option (B) is still needed.
Decision: park, pursue option (A) first
Why park:
- Unmeasured performance claim → can't justify the API-surface cost.
- Unresolved threading contract for user callbacks → UX question without a principled answer.
- Option (A) is lower-risk and covers the likely cause of FPS loss cheaply.
- Trampoline-architecture refactor needed on top of the existing prototype before merge.
Unparking criteria (when to revive):
- Option (A) lands, is bit-for-bit validated, and ships enabled by default on ESP32.
- A hardware benchmark on ESP32-S3 with a representative audio + LED workload still shows FPS < target.
- A decision is made (and documented) on the cross-core callback contract — e.g., "onBass fires on the main loop thread always; cross-core work is serialised through a bounded queue the main thread drains."
When all three are true, bring back the prototype from the closed PR, apply the trampoline refactor, add the threading contract, and land.
Artifacts preserved
- PR feat(audio,task): Worker primitive + Processor::setCoreAffinity offload #2357 — full prototype, closed unmerged. Diff is still browsable.
- feat(esp32): honor CoroutineConfig::core_id for task affinity #2337 — phase 1 (
CoroutineConfig::core_idplumbing) is in master and stays. - perf(audio): optimize audio processing pipeline to restore LED FPS #2308 — parent issue, remains open.
References
- perf(audio): optimize audio processing pipeline to restore LED FPS #2308 — parent performance tracker
- feat(esp32): honor CoroutineConfig::core_id for task affinity #2337 — phase 1 (core_id plumbing, landed)
- refactor(audio/fft): dispatcher for ESP-DSP FFT backend #2310, feat(audio/fft): ESP-DSP backend + AudioFftParity hardware validation harness #2315 — ESP-DSP FFT backend work (option A)
- feat(audio,task): Worker primitive + Processor::setCoreAffinity offload #2357 — parked prototype (to be closed with link here)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
zackees commentedon Aug 20, 2026
Marking this research tracker
deferredto match its explicit parked status and keep it out of the active burn-down. The lower-risk ESP-DSP optimization shipped and auto-detects on ESP32; the cross-core prototype remains intentionally unmerged until the issue's own reactivation criteria are met: a measured residual FPS gap, a settled callback-threading contract, and the platform-trampoline refactor.