Skip to content

perf(esp32): run the linker under the C locale (-30% link time) - #1555

Merged
zackees merged 2 commits into
mainfrom
perf/esp32-link-c-locale
Sep 28, 2026
Merged

zackees merged 2 commits into
mainfrom
perf/esp32-link-c-locale

Conversation

@zackees

@zackees zackees commented Sep 28, 2026

Copy link
Copy Markdown
Member

Part of #1537. With the compile phase shrunk, the link had become about a third of a cold ESP32-S3 build.

Finding

perf record of the ESP32-S3 link command:

12.17%  libc  __gconv_transform_utf8_internal
 5.25%  libc  internal_fnmatch
 3.84%  libc  internal_fnwmatch
 3.70%  libc  __mbsrtowcs_l
 2.91%  libc  fnmatch_convert_to_wide
 2.15%  libc  fnmatch

GNU ld matches the SDK linker scripts' section wildcards (*(.iram1 .iram1.*), *libfoo.a:*.o(...), …) with glibc fnmatch. Under a UTF-8 locale (LANG=en_US.UTF-8 here, and the default almost everywhere), fnmatch converts every pattern and every name to wide characters before matching.

Fix

The ESP32 link runs with LC_ALL=C overlaid on its environment. The patterns and section/file names are ASCII, so the C-locale byte matcher selects exactly the same sections.

Numbers (bench/blink -e esp32s3)

UTF-8 locale LC_ALL=C
link command alone (3 runs) 1074–1098 ms 733–774 ms
link-convert-size phase, 4 pinned cores 1.16–1.47 s 0.85–0.95 s
firmware.elf / firmware.bin — byte-identical to the pre-change build

Cold builds on 4 pinned cores, on a box at load 42, are 3.25–3.38 s; warm builds are 53–55 ms. PlatformIO runs ld under the user's locale, so this is a pure fbuild advantage.

Compiling under LC_ALL=C made no measurable difference, so only the link is changed.

Test

link_runs_the_linker_under_the_c_locale uses a fake linker that records $LC_ALL. It fails without the overlay (red check done) and passes with it.

GNU ld matches the SDK linker scripts' section wildcards with glibc
fnmatch. Under a UTF-8 locale fnmatch converts every pattern and name to
wide characters; perf puts that path (gconv/mbsrtowcs/fnwmatch) at a
third of an ESP32-S3 link. LC_ALL=C matches the same ASCII names and the
ELF is byte-identical: 1.09 s -> 0.75 s for bench/blink esp32s3.

Part of #1537.
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: FastLED/fbuild/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 491c8571-ca42-48a6-a0a7-350617fe4080

📥 Commits

Reviewing files that changed from the base of the PR and between 10d2a5e and 84217f8.

📒 Files selected for processing (2)
  • crates/fbuild-build-esp/src/esp32/esp32_linker.rs
  • crates/fbuild-build-esp/src/esp32/esp32_linker_tests.rs

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 83dc147 into main Sep 28, 2026
17 checks passed
@zackees
zackees deleted the perf/esp32-link-c-locale branch September 28, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant