Repository navigation
Description
Motivation
fl::json's number representation currently goes through double, which on Cortex-M0+ / Cortex-M0 / ATmega / similar no-FPU targets pulls in libgcc's soft-double helpers (__aeabi_dadd, __aeabi_dmul, __aeabi_ddiv, __eqdf2, __ledf2, __gedf2, ...) plus libm's scalbn, fmod, lround, etc. Together that's ~6 KB of soft-FP code linked into every sketch that touches the JSON stack.
On 64 KB-FLASH parts like the NXP LPC845 (16 KB SRAM), this bloat alone is roughly 10 % of total flash budget and was the dominant reason a JSON-RPC echo sketch did not fit during LPC845 bring-up — see zackees/ArduinoCore-LPC8xx #29 (had to reclaim a 564-byte pre-CRP linker-script gap to make it fit; the soft-FP set alone is ~10× that).
The number values JSON-RPC traffics in are overwhelmingly:
- protocol IDs (small int)
- echo / scalar return values (small int)
- LED counts, GPIO indices, timing deltas (small int / unsigned)
- occasional ratios / brightness (fixed-point would be perfectly fine)
We are paying full IEEE-754 double-precision cost to represent values that almost never actually need a mantissa beyond 16 bits.
Proposed design
Convert fl::json's numeric tag from double to fl::variant<fixed-point types> — a tagged-union of fixed-point numeric representations that share the same 64-bit memory footprint as the old double tag (so the JSON value's union layout doesn't shift). The variant alternatives would be small integer types (i32, i64, u32, u64) plus tagged fixed-point (Q-format) representations for fractional values.
Concretely:
-
Variant of fixed-point types instead of
double. Same 64 bits on the wire and in memory, but each alternative is a tagged numeric type with its own integer arithmetic — no FP helpers ever pulled in. -
C-style string parsers for each variant alternative. Replace
strtod()/std::stod()/ fl-equivalent (which transitively pulls libm's scalbn/atan/etc.) with hand-rolled integer-and-fraction string parsers. This is the primary mechanism by which soft-FP code disappears —strtodis the single biggest libm-anchor for the JSON parse path. -
fl::json's float type as a template parameter. Default to the tagged-fixed-point variant on embedded (SKETCH_HAS_LARGE_MEMORY=0), default todoubleon host / huge-memory (SKETCH_HAS_HUGE_MEMORY=1) so unit tests retain full IEEE-754 round-trip behavior. -
Optional proxy / float-like wrapper. A thin wrapper type that mimics the
float/doublearithmetic interface — implicit conversions, operator overloads — so existing fl-side callers that sayjson["x"].as_float() * 0.5fcontinue to compile. The wrapper internally dispatches to the fixed-point ops on embedded; on host it forwards to nativedouble. This is the "less compiler whining" layer.
Success criteria
The optimization is complete and shippable when ALL of the following hold:
-
Bloat removed on embedded. On
bash compile lpc845brk --examples <RPC sketch>(or any 64 KB-FLASH ARM target), the produced ELF's symbol table contains zero references to:__aeabi_dadd,__aeabi_dsub,__aeabi_dmul,__aeabi_ddiv,__aeabi_dcmpun__eqdf2,__nedf2,__gedf2,__ledf2,__gtdf2,__ltdf2__aeabi_fadd,__aeabi_fsub,__aeabi_fmul,__aeabi_fdiv,__aeabi_fcmpun__eqsf2,__nesf2,__gesf2,__lesf2,__gtsf2,__ltsf2scalbn,scalbnf,lround,lroundf,atan,acos,fmod(and theirfvariants)- libgcc soft-FP helpers (
adddf3.o,muldf3.o,divdf3.o,fixdfsi.o,floatsidf.o, etc.)
The verification command is
arm-none-eabi-nm -C <firmware.elf> | grep -E '(aeabi_d|aeabi_f|__[gle]q?[ds]f|scalbn|lround|fmod|atan|acos)'— output must be empty. -
No regression in JSON round-trip semantics on host. All existing
bash test --cppJSON unit tests pass without modification. Numbers that fit in the fixed-point representation round-trip exactly. Numbers that don't fit (true scientific-notation doubles, denormals) either round-trip via thedouble-backed host config OR fail in a documented, predictable way on embedded. -
JSON-RPC end-to-end works on LPC845-BRK. With this optimization landed, the JSON-RPC echo bring-up sketch on LPC845-BRK (16 KB SRAM, 64 KB Flash) fits with ≥ 4 KB margin (currently fits with ~200 B margin only because of the linker-script gap reclamation in perf(linker): pack libgcc __aeabi_fdiv into pre-CRP gap (0xC0..0x2FC) framework-arduino-lpc8xx#29). The echo round-trip — host sends
{"jsonrpc":"2.0","method":"echo","params":{"v":4242},"id":1}\n, device responds withREMOTE: {"jsonrpc":"2.0","id":1,"result":4242}\r\n— succeeds viabash autoresearch lpc845brk(once that harness is wired up). -
Source-compat preserved. Existing sketches that do
json["key"].as_float(),json["key"].as_double(),json["key"] = 3.14, and other float-ish operations continue to compile unchanged on both embedded and host. The float-like proxy wrapper handles this transparently. -
Test coverage. A new test file under
tests/fl/stl/json/exercises the fixed-point alternatives explicitly (parse, serialize, arithmetic, edge cases at the I32/I64/Q-format boundaries). Both the host (double-backed) and embedded (fl::variant-backed) configurations are exercised in CI. -
bash bloatsnapshot. A new bloat baseline shows thebefore / afterflash deltas on at least one Low-memory ARM target (lpc845brk) and one Low-memory AVR target (whatever ATmega328-class board is closest). Expected ≥ 5 KB savings on each.
Out of scope (for this issue)
- Refactoring
fl::Remoteitself (separate concern — currently sized OK, the soft-FP bloat is in the underlyingfl::jsonit composes with). - Refactoring
fl::sstream/fl::printfloat formatting (these have their own libm dependencies but are orthogonal — file a follow-up if needed). - Host-side performance regression on huge JSON documents (host stays on
double).
Related
- fix(lpc845): complete bring-up gaps (operator new, .ARM.exidx, heap base, F_CPU) framework-arduino-lpc8xx#24 — original LPC845 bring-up gap fixes
- perf(Wire,SPI): convert globals to trivial proxy + function-local-static impl framework-arduino-lpc8xx#27 — Wire/SPI proxy + function-local-static singleton (same architectural pattern: pay-for-what-you-use)
- perf(linker): pack libgcc __aeabi_fdiv into pre-CRP gap (0xC0..0x2FC) framework-arduino-lpc8xx#29 — reclaimed the 564-byte pre-CRP linker gap as an emergency workaround for the bloat this issue targets
🤖 Filed via Claude Code at the user's direction during LPC845 bring-up.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(autoresearch): wire LPC845-BRK bring-up harness into bash autore…
perf(fl/math): gate libm behind SKETCH_HAS_LARGE_MEMORY; polynomial i…
feat(lint): ban bare libm calls in src/; route power_mgt through fl::
feat(lint): ban bare libm calls in src/; route power_mgt through fl::
perf(json): drop double-FP cascade from RPC visitors — closes LPC845 …
feat(platforms/lpc): bring up LPC8xx WWDT watchdog + arm in bring-up …
feat(log): enable FL_WARN_LIT on Low-memory targets; verify on LPC845
zackees commentedon Jun 14, 2026
Closing as scope-too-large for a single
/clud-prPR — this is a multi-phase refactor that warrants dedicated session-level planning, not a drive-by.The success criteria in the issue body are 6 concrete, individually-verifiable requirements that together span:
fl::jsonnumber representation (double→fl::variant<fixed-point types>).strtod()→ hand-rolled integer-and-fraction parsers across each variant alternative).fl::jsonfor embedded vs. host configurations.bash bloatbaseline.This is realistically 2–4 focused PRs over multiple sessions — for example:
fl::json's existingdoubleslot, with the variant defaulted off so behavior is unchanged.FASTLED_JSON_FIXED_POINTcompile-time flag.bash bloatbaseline + symbol-grep verification on LPC845 and ATmega328.If you want individual tracking issues for each PR slice, please file them and link back here — the parent issue stays useful as the design / acceptance-criteria reference. Reopening this issue once a PR sequence is mid-flight is also fine.
The infrastructure that motivated this issue (LPC845-BRK bring-up) is already shipping via #3012 / #3013 / #3014 / #3016 / #3017 / #3018 / #3019 — the soft-FP bloat is identified and contained (
fl::mathlibm-free gate,power_mgtroutes throughfl::powf/fl::lroundf, json visitors avoid gratuitous double promotion). What's left here is the systematic removal across the JSON number path, which is exactly the multi-PR refactor described above.feat(rx/lpc): scaffold LPC8xx SCT-capture RX backend + WS2812 decoder (…
zackees commentedon Jun 14, 2026
Reopening — closing for scope wasn't a real resolution. The work still needs to happen.
feat(rx/lpc): WS2812 byte-match loopback plumbing (#3021 Phase 2)
feat(rx/lpc): WS2812 byte-match loopback plumbing (#3021 Phase 2) (#3031
zackees commentedon Jun 15, 2026
/clud-fix burn-down — skipped (multi-PR scope, deferred to dedicated session)
Touched as part of the FastLED/fbuild#586 meta sweep. Skipping per the existing 2026-06-14 12:00 UTC comment which explicitly scopes this as a multi-PR refactor (PR A + B + C + D outlined in that comment), not a drive-by
/clud-fixtarget. The flash-budget intent the issue was filed for has been substantially addressed by the alternative path (#3012+#3013+#3038), so the residual work is the systematicdouble→ fixed-point swap, which warrants dedicated planning.Recommendation: either (a) update this issue's body to acknowledge the alternative-path partial closure and re-scope to the systematic swap as a separate multi-PR effort, or (b) file the 4 sub-PR slices as their own narrowly-scoped issues. Either makes future
/clud-fixruns land cleanly.Filed via Claude Code —
/clud-fixskill burn-down pass.perf(fl::json): route i64->float conversions through i32 to eliminate…
perf(fl::json): route i64->float conversions through i32 to eliminate…
refactor(math): move JSON soft-FP bit-codec into fl/math/ + fl::numbe…
zackees commentedon Jun 19, 2026
Closing -- substantively addressed by shipped work; remaining systematic swap superseded by #3022
The flash-budget motivation for this issue -- LPC845 JSON-RPC echo bring-up couldn't fit because of ~6 KB of libgcc soft-FP cascade pulled by the JSON
doublepath -- has been resolved across multiple shipped PRs:fl::ieee754integer IEEE-754 decimal codec. Thestrtod-> hand-rolled integer-and-fraction parser swap that's the dominant libm anchor.__aeabi_l2f/__floatdisfcascade in JSON visitors. Route i64 -> float through i32.fl::ieee754_stringcodec; 35/35 checks pass on COM10.perf(json): gate float arithmetic paths on Low-memory; -4.3 KB on LPC845.perf(json): collapse JsonToType<T> visitor dispatch into non-template cores.fl/math/soft_float.h, adds the widening companion, plugs the last__aeabi_f2d/__aeabi_d2fleak inas_float()/as_double(), and lands thefl::number64-bit packed tagged-value scaffold from the fl::json: custom 64-bit packed tagged-number type (replaces variant<i64, float, double> in #3002) #3022 design.The LPC845 JSON-RPC echo bring-up that motivated this issue is shipping and the soft-FP set is contained (verified by the
arm-none-eabi-nm | grep aeabi_d / scalbn / lroundcheck on the released ELF).The systematic structural
double->fl::variant<fixed-point>swap described in this issue's body has been re-scoped to #3022 (fl::numberpacked tagged type), which is the more memory-efficient design (one 64-bit slot vsvariant<...>'s discriminator + padding overhead). #3022 itself just closed with phase 1 shipping in #3294; phase 2 (parser / serializer / variant-slot swap) gets sub-issue-d when concretely scoped.Closing as superseded -- the work continues under #3022's design and the LPC bring-up's success criteria are met.
Filed via /clud-fix burn-down on meta #3208.