Repository navigation
Description
Context
The linked ESP32-S3 Blink image from PR #4563 has six fl::printf_detail::format_arg<T> scalar/bool instantiations between 1,099 and 1,127 B each, totaling 6,646 B. All 14 format_arg/format_arg_generic entries total 7,566 B. src/fl/stl/stdio.h defines a large format-specifier switch inside the non-pointer function template, so much of the switch, width handling, and temporary string plumbing is emitted once per scalar type.
This is FastLED's own formatter size, separate from newlib's printf cluster and from the log-call-site migration tracked by #3158.
Proposal
Prototype a shared out-of-line formatter for normalized integral values and a thin type-specific adapter. Preserve supported signed, unsigned, bool, octal, hex, character, width, sign, alternate-form, type-error, and pointer behavior. Keep the public fl::printf/fl::stdio API unchanged. Use the bloat report to decide whether shared code reduces whole-firmware flash after the extra call/normalization cost.
Acceptance criteria
- RED: a focused size regression reproduces the six ~1.1 KB scalar/bool instantiations and records the current Blink total; focused formatting tests capture existing output for the supported specifier/type matrix before refactoring.
- GREEN: formatting tests pass byte-for-byte, and same-toolchain Blink before/after symbol and firmware reports show a positive net flash saving (target at least 1 KB). If the prototype fails to save flash, record that result and do not land added complexity.
- Host tests cover negative and boundary-width values, zero, bool, flags, precision, unsupported type/specifier pairs, and pointer formatting.
- No extra formatter path is pulled into sketches that do not use this API.
Decisions
- P2: 6.6 KB in six direct instantiations is material, but the recoverable share needs measurement.
- Work in
src/fl/stl/stdio.hand its implementation/tests; keep libc shrink work in fbuild because it has a different owner and compatibility surface. - Require whole-firmware savings, since shrinking named instantiations while growing a shared helper would not improve the image.
Related issues
- Meta: ESP32-S3 binary-size reduction — Batch 3 (successor to #2773) #2856 item 3.2 and perf(log): migrate fl::sstream to printf-style backend for ~5-10 KB on ESP32-S3 (split from #3122 B2 / refs #2856 item 3.2) #3158 address logging call-site/sstream overhead. This issue targets the distinct per-type formatter body in
fl/stl/stdio.h.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
perf(stdio): share scalar format_arg code across types (#4565) (#4577)