Skip to content

perf(esp32): non-throwing unique_lock/lock_guard drop libstdc++ locale init (#4798) - #4806

Merged
zackees merged 1 commit into
masterfrom
perf/4798-no-std-lock
Oct 9, 2026
Merged

zackees merged 1 commit into
masterfrom
perf/4798-no-std-lock

Conversation

@zackees

@zackees zackees commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Part of #4801. Fixes #4798.

Root cause (linker map)

main.o → fl.gfx+ → fl.stl+ (std::__throw_system_error, from std::unique_lock::lock/unlock)
  → libstdc++ system_error.o → lt5-sstream-inst.o → ios-inst.o → locale-inst.o / wlocale-inst.o / cxx11-wlocale-inst.o

On ESP32, fl::unique_lock aliased std::unique_lock. Its misuse checks reference __throw_system_error, and that single reference extracts the iostream/locale objects. Their static constructors (ctype_byname, plus numpunct/time_get/moneypunct guard variables) are always kept.

Fix

Move the stub platform's existing non-throwing lock_guard/unique_lock verbatim into platforms/shared/nothrow_lock.h, and use it on ESP32 as well. The std lock tag types (std::defer_lock_t etc.) stay, since they are header-only. ConditionVariableESP32 only uses mutex(), owns_lock(), lock() and unlock(); no ESP32 code passes fl::unique_lock to std::condition_variable.

Evidence (dashboard protocol, fbuild 2.5.38)

flash before → after RAM before → after
esp32dev Blink 295,896 → 294,984 (−912) 25,812 → 25,492 (−320)
esp32dev APA102 291,020 → 290,112 (−908) 25,276 → 24,956 (−320)
esp32s3 Blink 401,876 → 400,992 (−884) 77,936 → 77,616 (−320)
esp32s3 APA102 409,656 → 408,768 (−888) 77,864 → 77,544 (−320)
  • libstdc++.a(locale-inst.o) is no longer in the S3 map.
  • bash test --clean --cpp: 319/319 unit, 95/95 examples. bash lint passes. /code-review: no findings.
  • Follow-up: RP and STM32 still alias std::unique_lock (mutex_rp.h, mutex_stm32.h) and likely pay the same cost; out of scope for this ESP32 pass.

Summary by CodeRabbit

  • Improvements
    • ESP32 and stub platforms now share consistent lock wrappers with non-throwing behavior. Invalid lock operations return safely instead of throwing.

…e init (#4798)

fl::unique_lock on ESP32 aliased std::unique_lock, whose lock()/unlock()
reference std::__throw_system_error. That one reference extracted
libstdc++'s system_error.o, which pulls lt5-sstream-inst, ios-inst and the
locale objects, whose static constructors (ctype_byname, numpunct/time_get
guard variables) are always kept.

Move the stub platform's non-throwing lock_guard/unique_lock into
platforms/shared/nothrow_lock.h and use it on ESP32 too; std lock tag types
stay for source compatibility.

esp32dev Blink:  flash 295896 -> 294984 (-912), RAM 25812 -> 25492 (-320)
esp32dev APA102: flash 291020 -> 290112 (-908), RAM 25276 -> 24956 (-320)
esp32s3 Blink:   flash 401876 -> 400992 (-884), RAM 77936 -> 77616 (-320)
esp32s3 APA102:  flash 409656 -> 408768 (-888), RAM 77864 -> 77544 (-320)
locale-inst.o no longer in the map. bash test --cpp 319/319, 95/95.
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: FastLED/FastLED/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6813ba28-c113-4d53-b2f2-0e22da1a4f73
📥 Commits

Reviewing files that changed from the base of the PR and between 18669e6 and 392c162.

📒 Files selected for processing (3)
  • src/platforms/esp/32/mutex_esp32.h
  • src/platforms/shared/nothrow_lock.h
  • src/platforms/stub/mutex_stub_noop.h

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The change adds shared non-throwing lock_guard and unique_lock templates. The ESP32 and stub mutex headers now use these templates instead of their previous standard-library aliases or local implementations.

Changes

Non-throwing lock wrappers

Layer / File(s) Summary
Shared lock wrapper behavior
src/platforms/shared/nothrow_lock.h
Adds lock_guard and unique_lock templates. unique_lock supports deferred, try, and adopted locking, move operations, ownership observers, and non-throwing lock operations.
Platform mutex integration
src/platforms/esp/32/mutex_esp32.h, src/platforms/stub/mutex_stub_noop.h
The ESP32 header uses the shared wrappers and retains standard lock-constructor tags. The stub header replaces its local wrappers with the shared header and retains FASTLED_MULTITHREADED defaulting to 0.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 392c1

No merge-blocking issue is established; the change is ready to merge after normal checks.

🚥 Pre-merge checks | ✅ 3 | ❌ 1 | ❓ 1

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check Inconclusive The change directly addresses #4798. ESP32 now uses the shared non-throwing fl::platforms::unique_lock and lock_guard, which removes the std::unique_lock misuse path described in the issue. The … Provide the Blink map results for the applicable ESP32 targets. The results must show that neither locale-inst.o nor wlocale-inst.o is present.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the ESP32 non-throwing lock change and its reported performance effect on libstdc++ locale initialization.
Out of Scope Changes check Passed The changes stay within #4798. They move the existing non-throwing lock types into a shared header, reuse them for the stub platform, and select them for ESP32. These changes support the ESP32 linker-…
Full details: Linked Issues check

Explanation

The change directly addresses #4798. ESP32 now uses the shared non-throwing fl::platforms::unique_lock and lock_guard, which removes the std::unique_lock misuse path described in the issue. The PR reports that locale-inst.o is absent from an S3 map and reports size reductions. The evidence does not establish the acceptance criterion for Blink maps because it does not report wlocale-inst.o, and it does not provide reviewable Blink map results for both ESP32 targets.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit 261382a into master Oct 9, 2026
120 checks passed
@zackees
zackees deleted the perf/4798-no-std-lock branch November 5, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

perf(esp32): libstdc++ locale static init linked (~0.5 KB flash, 256 B RAM)

1 participant