Skip to content

refactor: move big-target scratch users (blur, channel, FFT, stb_vorbis) onto fl::scratch #5331

Closed as not planned

Description

@zackees

These scratch users run only on large boards and could be moved onto fl::scratch for consistency:

  • the SingletonThreadLocal<fl::vector> grow-only scratch in src/fl/gfx/blur.cpp.hpp, src/fl/channels/channel.cpp.hpp and src/fl/audio/fft/fft_impl.cpp.hpp
  • StbvTempBuffer in src/third_party/stb/stb_vorbis.cpp.hpp

It's low priority. Evaluate whether it saves RAM or code on ESP32; skip any where it doesn't.

Activity

  1. added
    sanitized
    on Nov 21, 2026
  2. zackees commented on Nov 21, 2026

    @zackees
    MemberAuthor

    Evaluation (automated worker): no change. Moving these four users onto fl::scratch saves no RAM or code on ESP32, and it would make things worse.

    • ESP32 builds always use the inline path. ESP32 sets FASTLED_MULTITHREADED=1 (src/fl/stl/thread_config.h), and fl/stl/scratch.h refuses (#error) a non-zero FL_SCRATCH_STACK_BYTES on multithreaded builds unless FL_SCRATCH_ALLOW_MULTITHREADED=1 is set. So on ESP32, fl::scratch<T> is just a local T on the task stack. These buffers were put in SingletonThreadLocal to keep them off the 4-8 KB FreeRTOS task stacks (see the comment on FftScratch), so switching them would bring back the stack-overflow risk.

    • The types don't fit. fl::scratch<T> needs a fixed-size, trivially destructible T. All four users are runtime-sized, grow-only heap buffers:

      • blur pad buffer: sized from the image width and radius
      • channel reorder buffer: one CRGB per LED
      • FftScratch: eight fl::vectors sized by FFT size and band count
      • StbvTempBuffer: a bump allocator of 64 KB or more that grows and needs stable pointers within a save/restore scope

      None of them can be expressed as a fixed T. Even when an arena is on, its fixed, never-growing capacity can't hold them.

    • They're also thread-safe today. Each thread has its own SingletonThreadLocal. The fl::scratch arena is one shared, unlocked, not-thread-safe area.

    fl::scratch is meant for fixed multi-hundred-byte working sets on single-threaded small-stack targets (for example ESP8266 and drawPolygon). The current SingletonThreadLocal<fl::vector> approach is the right fit for these users. Suggest closing as won't-do. (Since nothing changes, this does not conflict with #5163.)

  3. zackees commented on Nov 21, 2026

    @zackees
    MemberAuthor

    Closing as won't-do, following the evaluation above. On ESP32, fl::scratch<T> is a local on the task stack (multithreaded builds require FL_SCRATCH_STACK_BYTES=0). All four users are runtime-sized, grow-only buffers, which a fixed T can't hold. The current SingletonThreadLocal<fl::vector> keeps them per-thread and off the 4–8 KB FreeRTOS stacks. Moving them would save no RAM or code and would bring back the stack-overflow risk.

  4. moved this from Triage to Done in FastLED Trackeron Nov 21, 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