Skip to content

perf(stdio): share scalar format_arg code across types #4565

Closed

Description

@zackees

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.h and 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions