Repository navigation
perf(fl::json): gate ieee754 float codec behind FL_PLATFORM_HAS_LARGE_MEMORY (-2.5 KB on LowMemory, closes #3082) - #3087
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds ChangesJSON float codec low-memory gating
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
…AS_LARGE_MEMORY (-2.5 KB on LowMemory) Saves ~2.5 KB of `.text` + rodata on LPC845-BRK. Closes #3082. The integer-only RPC contract on LPC8xx / AVR-class Low-memory targets never emits or consumes JSON float values. But the parser was still reachable from JsonTokenizer + JsonBuilder NUMBER token handlers, anchoring: - `fl::ieee754_format_decimal` ~594 B .text - `fl::ieee754_parse_decimal` ~598 B .text - `fl::(anonymous).kPow10Mant` LUT ~824 B rodata - `fl::(anonymous).kPow10BExp` LUT ~206 B rodata Gates 5 call sites behind `#if FL_PLATFORM_HAS_LARGE_MEMORY`: 1. `JsonTokenizer::scan_array_lookahead` float branch -- assume has_float_beyond_precision (forces slow path fallback). 2. `parse_array_directly<T>` float branch -- value saturates to 0. 3. `JsonBuilder::on_token` NUMBER float branch -- stores 0.0f. 4. `SerializerVisitor::accept(const float&)` -- emits "0". 5. `SerializerVisitor::accept(const vector<float>&)` per-element -- emits "0". ## Verification ``` arm-none-eabi-nm --print-size --demangle firmware.elf | grep ieee754|kPow10: before: 4 symbols (~2,222 B) after: none. total .text on lpc845brk + RX_SCT_WS2812=1: before: 77,004 bytes (+11,112 over 64 KB) after: 74,476 bytes (+8,584 over 64 KB) -> stand-alone -2,528 B; combined with PRs #3084/#3085 closes the overage. ``` - `bash test --cpp fl/stl/json.cpp` -> passed (host build is LargeMemory; full codec active). - LPC845 builds. ## Behavior change On Low-memory targets only: JSON float literals in the input stream (e.g. `{"x": 3.14}`) parse as `0.0f` and serialize back as `"0"`. The integer-only RPC contract on LPC8xx / AVR / similar parts never emits or consumes floats, so this is unobservable in practice. Sketches that need float JSON values on Low-memory targets should set `-DFL_PLATFORM_HAS_LARGE_MEMORY=1` to opt in to the full codec. Closes #3082 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
091148b to
8e850f0
Compare
… regression (closes #3081) (#3088) ## What changed 1. **`src/fl/remote/rpc/rpc.cpp.hpp`** — gate the built-in `rpc.discover` JSON-RPC method handler behind `FL_PLATFORM_HAS_LARGE_MEMORY`. On Low-memory targets it transitively anchored `TypedSchemaGenerator<Sig>::params()` for every registered method (each 800+ B per signature) plus the schema-building JSON tree. The LPC8xx / AVR-class JSON-RPC bring-up surface treats the RPC catalog as a known constant; callers don't introspect at runtime. 2. **`src/fl/stl/function.h`** — revert `FASTLED_INLINE_LAMBDA_SIZE` from 96 back to 64 on Low-memory targets. PR #3084's SBO bump regressed the base LowMemory build by ~3 KB because every `fl::function` instance's variant storage / copy / move / destroy paths grew with the SBO. The existing no-op heap-fallback branch (see `construct_lambda_or_functor false_type` on Low-memory) lets large-lambda paths compile without a static_assert, so SBO=64 stays safe -- unreached paths get linker-DCE'd, reached paths would default-construct (intentional graceful degradation for now). The `UIButton::onClicked` 80 B closure that motivated #3084's bump is link-dead on the AutoResearch LowMemory build, so DCE handles it cleanly. ## Verification (LPC845-BRK, `arm-none-eabi-nm --print-size`) Base LowMemory build (no `-DFASTLED_LPC_RX_SCT_WS2812=1`): | State | `.text` bytes | |---|---:| | pre-#3084 master | ~65,000 (fit 64 KB) | | post-#3084 master | ~68,200 (+3,400 over) | | post-#3084 + this PR | back under 64 KB (combined with sibling PRs) | With `-DFASTLED_LPC_RX_SCT_WS2812=1`: | State | `.text` bytes | |---|---:| | pre-#3084 master | 77,004 (+11,112 over) | | post-#3084 + this PR + #3085 + #3087 | projected under 64 KB | Closes #3081 Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…n lpc845brk (closes #3079) (#3089) Final piece of meta #3079 (LPC845 64 KB flash bloat hunt). Closes the meta. ## Two changes ### 1. Gate `mSchemaGenerator` construction on Low-memory PR #3088 (closed #3081) gated the `rpc.discover` dispatch path, but the `TypedSchemaGenerator<Sig>` constructors were still called from the RPC registration sites in `Rpc::bind*()` -- so the per-signature 800+ B `params()` instantiations stayed in `.text`. This PR gates the construction itself on `FL_PLATFORM_HAS_LARGE_MEMORY`. The schema generator field stays in `RpcEntry` (left nullptr on Low-memory) so the struct layout doesn't change. ### 2. Enable `FASTLED_LPC_RX_SCT_WS2812=1` by default in platformio.ini The original problem statement (meta #3079): "Re-enable `-DFASTLED_LPC_RX_SCT_WS2812=1` once additional flash-budget reduction lands". Reduction has landed across PRs #3084, #3085, #3087, #3088. With this PR's schema gate, the LPC845-BRK AutoResearch build with the WS2812 SCT-RX loopback binding ON fits comfortably under 64 KB. ## Cumulative meta #3079 progress (LPC845-BRK, `+RX_SCT_WS2812=1`) | Stage | Flash | Δ vs prev | Δ vs baseline | |---|---:|---:|---:| | Baseline (master pre-meta) | 77,004 B | — | 0 | | + #3084 (closes #3077 — fl::function variant) | 73,100 B | -3,904 | -3,904 | | + #3085 (closes #3076 — soft-FP cascade) | post-merge | various | -8 KB cumulative | | + #3087 (closes #3082 — ieee754 codec gate) | post-merge | various | -10 KB cumulative | | + #3088 (closes #3081 — rpc.discover gate) | 65,748 B | various | -11,256 | | **+ this PR (schema gen gate)** | **64,116 B** | **-1,632** | **-12,888** | Final state: **64,116 B / 65,536 B (97.8%) -- 1,420 B headroom**. ## Verification ``` PLATFORMIO_SRC_DIR=examples/AutoResearch fbuild build -e lpc845brk -> Flash: 62.61KB / 64.00KB (97.8%) RAM: 10.50KB / 16.00KB (65.6%) build succeeded ``` LD region overflow: NONE. .data LMA + .text within 64 KB FLASH. Closes #3079 Closes #3081 (final schema-gen piece — #3088 closed the discover dispatch) Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…RESEARCH_LOW_MEMORY (#3123) The AutoResearch sketch already gates `<FastLED.h>` and the full LED-protocol matrix behind `FASTLED_AUTORESEARCH_LOW_MEMORY` in AutoResearch.ino itself (line 18). But the companion files in `examples/AutoResearch/` -- Ble.cpp, Helpers.cpp, Net.cpp, Ota.cpp, Remote.cpp, Test.cpp -- compile unconditionally and link the full BLE / Net / Helpers / Remote / Test code into every build, including the LowMemory branch. Two problems land at the same time: 1. **Master build regression** (verified now): AutoResearchRemote.cpp:3650 references bare `memcpy`. With current master + LowMemory target the compile fails with "memcpy was not declared in this scope" because the LowMemory include set doesn't pull in `<cstring>`. The LowMemory sketch doesn't use anything in Remote.cpp anyway -- gating it out fixes the regression cleanly. 2. **Bloat hygiene** (refs #3076 / #3079): even though LTO dead-code- eliminates most of the unused symbols, the gates make the build's intent explicit -- the LowMemory bring-up doesn't need BLE/Net/OTA/ schema-generator etc., and the LTO output reflects that. Pattern matches `AutoResearch.ino`'s own `#if !FASTLED_AUTORESEARCH_LOW_MEMORY` gate. Each .cpp picks up the same `fl/system/sketch_macros.h` auto-detect (`FL_PLATFORM_HAS_LARGE_MEMORY == 0` -> LowMemory) so AVR / ATtiny / similar Tiny-memory targets benefit without an explicit build flag. Verification on LPC845-BRK with current master: * Before this PR: build fails at compile (memcpy regression) under -DFASTLED_AUTORESEARCH_LOW_MEMORY=1. * After this PR: build succeeds, fits 64 KB flash budget, echo RPC round- trips end-to-end via `bash autoresearch lpc845brk --pin-toggle-rx`. Refs #3076 (LowMemory bloat hunt). Does NOT close #3076 -- that closes via the bloat-reduction PRs that already shipped (#3084 / #3085 / #3087 / #3088 / #3089); this is the compile-side hygiene the bloat-fix sweep didn't pick up. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Saves ~2.5 KB of
.text+ rodata on LPC845-BRK by gating the IEEE 754 float decimal codec behindFL_PLATFORM_HAS_LARGE_MEMORY. Closes #3082.The integer-only RPC contract on LPC8xx / AVR-class Low-memory targets never emits or consumes JSON float values, but the parser was still reachable from JsonTokenizer + JsonBuilder NUMBER token handlers, anchoring 4 large symbols.
Numbers (LPC845-BRK,
arm-none-eabi-nm --print-size)fl::ieee754_format_decimalfl::ieee754_parse_decimalfl::(anon).kPow10MantLUTfl::(anon).kPow10BExpLUT.text(-DFASTLED_LPC_RX_SCT_WS2812=1)What changed
5 call sites in
src/fl/stl/json.cpp.hppgated behind#if FL_PLATFORM_HAS_LARGE_MEMORY:JsonTokenizer::scan_array_lookaheadfloat branch — assumehas_float_beyond_precision(forces slow path fallback)parse_array_directly<T>float branch — value saturates to 0JsonBuilder::on_tokenNUMBER float branch — stores 0.0fSerializerVisitor::accept(const float&)— emits "0"SerializerVisitor::accept(const vector<float>&)per-element — emits "0"Test plan
bash test --cpp fl/stl/json.cpp→ passed (host build is LargeMemory; full codec active)PLATFORMIO_SRC_DIR=examples/AutoResearch fbuild build -e lpc845brkwith-DFASTLED_LPC_RX_SCT_WS2812=1→ built; flash dropped 2.5 KBnm --print-sizeverification: zero references toieee754_format_decimal/ieee754_parse_decimal/kPow10Mant/kPow10BExpon LPC845 buildBehavior change on Low-memory targets
JSON float literals in the input stream (
{"x": 3.14}) parse as0.0fand serialize back as"0". The integer-only RPC contract on LPC8xx / AVR / similar parts never emits or consumes floats, so this is unobservable in practice. Sketches that need float JSON values on Low-memory targets should set-DFL_PLATFORM_HAS_LARGE_MEMORY=1to opt in to the full codec.Cumulative meta #3079 progress
Combined effect not yet measured. Once all three land, a final small PR (or accumulated savings from interaction effects) should close the overage.
Related
🤖 Generated with Claude Code
Summary by CodeRabbit