Repository navigation
Description
Symptom
The JSON tokenizer + builder + ieee754 number formatter pipeline accounts for ~5.4 KB of .text on the LPC845 LowMemory + FASTLED_LPC_RX_SCT_WS2812=1 build. Real arm-none-eabi-nm --print-size figures:
| Symbol | Bytes |
|---|---|
fl::(anonymous namespace)::JsonBuilder::on_token |
2,340 |
fl::(anonymous namespace)::JsonTokenizer::parse |
1,350 |
fl::(anonymous namespace)::JsonTokenizer::parse (specialization) |
1,350 (overlap — same fn or constprop clone) |
fl::ieee754_format_decimal |
594 |
fl::json_value::parse2 |
522 |
fl::ieee754_parse_decimal |
482 |
fl::(anonymous namespace)::kPow10Mant LUT |
824 (rodata) |
| Total active .text + rodata | ~5,400 bytes (~7% of .text) |
JsonBuilder::on_token at 2,340 bytes is the 4th-largest single function in the entire binary. It's the SAX-style visitor that converts the tokenizer's token stream into the fl::json_value AST.
Hypothesis
JsonBuilder::on_token is a switch over ~10 token types, each branch doing a different fl::json_value construction (string, number, array-open, object-open, etc.). With current inlining the switch unrolls into a long sequence of variant<...>::emplace<T> instantiations, each pulling in the variant's per-alternative copy_fn / destroy_fn. The 2.3 KB single-function size suggests heavy template duplication of the variant write paths.
JsonTokenizer::parse at 1.35 KB is a state-machine over characters. That's defensible — a well-tested JSON tokenizer of that size is not unreasonable — but the 824-byte kPow10Mant LUT only makes sense if ieee754_parse_decimal is reachable (it is, for parsing JSON numbers). If LowMemory + RX-only builds never see a float JSON number, the LUT + parse routine should drop.
Possible directions
- Outline the variant-emplace paths in
JsonBuilder::on_token. The branch bodies are small per se; the multiplier is the per-alternative codegen tax insidevariant<>::emplace. Replace with a singlevoid emit_value(json_value& dst, TokenType tag, span<char> raw)non-template function that dispatches internally. Estimated save: 1-1.5 KB. - Gate
ieee754_*behind a "JSON has floats" build flag. The LPC8xx RPC contract is integer-only (echo: int → int, pinToggleRx: 4× int, ws2812SctTest: 4× int). If we tell the codec at compile time that no float values are expected,kPow10Mant(824 B),ieee754_format_decimal(594 B), andieee754_parse_decimal(482 B) all drop. Saves ~1.9 KB. - Hand-write a smaller tokenizer for the LowMemory codec. The full RFC-compliant tokenizer is overkill for a 3-method RPC surface. A 200-300 byte hand-coded parser that accepts only
{"jsonrpc":"2.0","id":N,"method":"foo","params":[1,2,3,4]}would beat the 1,350-byte general tokenizer by 1 KB.
Note on safety
This is the JSON path used by fl::Remote for RPC dispatch. Any change must keep the parser strictly safe against malformed input — buffer overruns from a malformed RPC request would be a remote-code-execution class bug. Tests must cover fuzz-shaped inputs.
Repro
Same as meta #3079.
Acceptance
-
fl::JsonBuilder::on_tokendrops below 1 KB on LPC845 LowMemory build -
fl::ieee754_format_decimal+fl::ieee754_parse_decimal+kPow10MantLUT either all drop entirely (if the int-only-codec flag is implemented) or stay sized as today (if not) - Total JSON-codec
.textmass on LPC845 LowMemory + RX_SCT_WS2812 build drops below 2 KB - Fuzz test added that exercises malformed RPC input against the new parser path
Related
- bash bloat / fbuild symbols: no arm-none-eabi path; can't measure LPC845 bloat from FastLED's wrapper fbuild#594 — tooling gap
- fl::json: custom 64-bit packed tagged-number type (replaces variant<i64, float, double> in #3002) #3022 — fl::json packed tagged-number (touches the same area)
- Meta META: LPC845 64 KB flash bloat hunt -- clear 11 KB overage to unblock FASTLED_LPC_RX_SCT_WS2812=1 #3079
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Jun 15, 2026
Tracked under meta #3079 alongside #3076 (soft-FP), #3077 (fl::function variant), #3081 (RPC dispatch). Depends on FastLED/fbuild#594 for proper bloat iteration.
zackees commentedon Jun 15, 2026
Investigation findings (2026-06-15)
Active call graph from nm output
The reachable JSON codec on the LPC845 LowMemory + RX_SCT_WS2812 build is:
fl::SerializerVisitoris what couples the JSON codec to the soft-FP cascade (#3076) — for thefloatalternative ofjson_value::variant_tit callsfl::ieee754_format_decimalwhich links the entire float path.Specific symbols and call graph
Easy wins (and a hard one)
Easy:
ieee754_format_decimalandieee754_parse_decimalare only reachable through thefloatalternative ofjson_value::variant_t. If LPC845 bloat: 8.3 KB of soft-FP / integer-div leaks past the no-soft-FP invariant on LowMemory + RX_SCT_WS2812 #3076 lands path support TLS3001 #1 (drop thefloatalternative on Low-memory), these and thekPow10MantLUT drop together — ~1.9 KB free with no JSON codec changes needed.JsonTokenizer::parseat 1.35 KB is small enough to consider hand-replacing on Low-memory builds. A minimal RFC-7159 subset tokenizer that accepts only{"id":N,"method":"foo","params":[1,2,3,4]}would fit in ~300 bytes.Hard:
3.
JsonBuilder::on_tokenat 2,340 bytes — this is the one that needs the SAX visitor outlining or a hand-rewritten minimal builder. The branch bodies are inlinedvariant<>::emplace<T>paths, each instantiating the variant's per-alternativecopy_fn/destroy_fn. Refactoring touches the variant API.Dependency on #3076
If #3076 is fixed via "drop the
floatalternative" (path #1 in that issue), this issue'sieee754_format_decimal+ieee754_parse_decimal+kPow10MantLUT problem goes away automatically. The remaining bloat would just beJsonBuilder::on_tokenat 2.3 KB andJsonTokenizer::parseat 1.35 KB.If #3076 is fixed differently, this issue's full scope (~5.4 KB) remains.
Recommendation
Work #3076 first. Re-measure this issue after. The target may shrink from ~3 KB to ~1 KB worth of remaining fixable scope.
perf(fl::json): gate ieee754 float decimal codec behind FL_PLATFORM_H…
perf(fl::json): gate ieee754 float decimal codec behind FL_PLATFORM_H…
perf(rpc/lpc): gate schema generator + enable RX_SCT_WS2812 default o…
perf(json): gate packed-array tokens + float-number store in JsonBuil…
perf(json): gate packed-array tokens + float-number store in JsonBuil…
perf(lpc): close meta #3224 -- Tier 1B/2D/2E/3G + RAM gate (-10.3 KB …