Skip to content

perf(fl::json): i64->float via i32 to drop ~4 KB soft-FP cascade on no-FPU (closes #3076) - #3085

Merged
zackees merged 1 commit into
masterfrom
feat/json-drop-float-variant-low-memory-3076
Jun 15, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/json-drop-float-variant-low-memory-3076

Conversation

@zackees

@zackees zackees commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Routes i64 → float conversions through i32 to avoid libgcc-nofp's __aeabi_l2f → _floatdisf.o → entire double soft-FP cascade. Closes #3076. Combined with #3084 (PR for #3077), clears 71% of the meta #3079 overage.

Root cause

arm-none-eabi-objdump -dC firmware.elf traced __aeabi_dadd (2,088 B) and __aeabi_dmul (1,392 B) ingression back to libgcc-nofp's _floatdisf.o, which implements __aeabi_l2f (i64 → single-precision float) by routing through double-precision arithmetic. Any reachable static_cast<float>(int64_t) on a no-FPU target drags in the entire double cascade — __aeabi_dadd / dmul / dsub / i2d / ui2d / d2f, ~8 KB total.

Two reachable JSON-codec call sites did exactly this:

  1. float_conversion_visitor<FloatType>::operator()(const i64&) — visitor used by json_value::as_float<T>()
  2. try_convert_to_specialized_array ALL_FLOATS array packing — when packing a JSON array as vector<float>, integer elements were converted via static_cast<float>(*val) where *val is i64

The same i64 → i32 → float workaround at IntConversionVisitor::operator()(const float&) already names this exact issue (// libgcc's __aeabi_f2lz helper internally chains through _fixunssfdi.o). Just extending the workaround to the missing call sites.

Numbers (LPC845-BRK, arm-none-eabi-nm --print-size)

Symbol Before After
__aeabi_dadd 2,088 B removed
__aeabi_dmul 1,392 B removed
__aeabi_l2f / __floatdisf 120 B removed
__aeabi_d2f / __aeabi_dsub / __aeabi_i2d / __aeabi_ui2d ~600 B all removed
Soft-FP .text total 9,124 B 5,060 B (single-prec only)
Total .text (-DFASTLED_LPC_RX_SCT_WS2812=1) 77,004 B 72,988 B
Overage against 64 KB FLASH +11,112 B +7,096 B

What changed

  • float_conversion_visitor<FloatType>::operator()(const i64&): clamps to INT32_MIN/INT32_MAX then routes through static_cast<float>(static_cast<i32>(value)). Values exceeding ±INT32 saturate.
  • float_conversion_visitor<double>::operator()(const i64&): same treatment for symmetry. as_double() is DCE'd from LowMemory today but this is defense-in-depth for future reachability.
  • float_conversion_visitor<FloatType>::operator()(const bool&): 1.0 : 0.0 → 1.0f : 0.0f to avoid double-literal arithmetic.
  • json.cpp.hpp ALL_FLOATS array packing: route via i32. classify_array already guarantees values fit in ±2^24 before ALL_FLOATS fires (line 717), so i32 narrowing is lossless.

Test plan

  • Host unit tests: bash test --cpp fl/stl/json.cpp → passed
  • LPC845-BRK build: PLATFORMIO_SRC_DIR=examples/AutoResearch fbuild build -e lpc845brk with -DFASTLED_LPC_RX_SCT_WS2812=1 → built; flash dropped 4 KB
  • nm --print-size verification: zero references to __aeabi_dadd / dmul / dsub / l2f / floatdisf / d2f / i2d / ui2d
  • CI: full matrix to be run on PR open

Caveat (precision)

i64 values exceeding ±(2^31 − 1) now saturate to INT32_MIN/MAX when converted to float via the visitor. This affects only the as_float<T>() API on values whose magnitude exceeds 2^31. JSON numbers fit in i64; if user JSON has integer values larger than 2^31, calling as_float() on them returns a saturated float instead of the precise float64 approximation. Existing AVR/STM32-class targets already had this behavior implicitly; explicitly extending it via clamp.

For the ALL_FLOATS packing case, classify_array already bounds entries to ±2^24, so the saturation never fires in practice on the packed-array path.

Cumulative meta #3079 progress

PR Saved Overage after
baseline — +11,112 B
#3084 (#3077: fl::function variant) −3,904 B +7,208 B
this PR (#3076: soft-FP cascade) −4,016 B +3,192 B
remaining (need −3.2 KB) under 64 KB

Either #3081 (RPC dispatch slim, ~7 KB target) or #3082 (JSON codec slim, ~3 KB target) would close the gap.

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved JSON numeric conversions by clamping integer-to-float values to safe 32-bit bounds, reducing precision/overflow edge cases.
    • Adjusted boolean-to-float conversion to use consistent float literals.
    • Enhanced array optimization during integer-to-float conversions to follow the same safer bounds-checking behavior.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c878cc99-3499-4201-b7f1-b52fbfe3d59a

📥 Commits

Reviewing files that changed from the base of the PR and between dccf92f and 608798a.

📒 Files selected for processing (2)
  • src/fl/stl/json.cpp.hpp
  • src/fl/stl/json/types.h
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/fl/stl/json.cpp.hpp
  • src/fl/stl/json/types.h

📝 Walkthrough

Walkthrough

In src/fl/stl/json/types.h, float_conversion_visitor<FloatType> and its <double> specialization now clamp i64 values to int32 bounds before casting to the target float type, and bool conversion switches to float literals. In src/fl/stl/json.cpp.hpp, the ALL_FLOATS array optimization path applies the same two-step i64 → fl::i32 → float cast.

Changes

JSON float conversion: i64 clamped through int32 bounds

Layer / File(s) Summary
float_conversion_visitor i64/bool clamping and double specialization
src/fl/stl/json/types.h
float_conversion_visitor<FloatType> saturates i64 to [−2147483648, 2147483647] before casting to FloatType; bool path uses 1.0f/0.0f instead of 1.0/0.0; blank lines removed from string-parsing block. float_conversion_visitor<double> specialization receives the identical i64 clamping change.
optimize_array ALL_FLOATS integer cast
src/fl/stl/json.cpp.hpp
Integer elements in the ALL_FLOATS path now cast via fl::i32 intermediate before float, replacing the prior direct float cast from i64.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐇 Hop hop, no more double bloat,
I cast through int32 with a careful note.
From i64 down to fl::i32,
Then float it goes—no soft-FP crew!
The LPC845 breathes a sigh of relief,
Eight kilobytes trimmed — what joyful belief! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: eliminating soft-FP cascade by routing i64-to-float conversions through i32 on no-FPU targets, with the specific platform (ARM) and memory footprint reduction mentioned.
Linked Issues check ✅ Passed The PR implements the technical solution to issue #3076 by eliminating i64-to-float conversions via double arithmetic through i32 intermediates, with measured 4 KB soft-FP reduction achieving 36% of the remaining overage goal.
Out of Scope Changes check ✅ Passed All changes are scoped to i64-to-float conversion paths in JSON codec as identified in issue #3076. No unrelated modifications detected in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/json-drop-float-variant-low-memory-3076

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/fl/stl/json/types.h`:
- Around line 522-533: The float_conversion_visitor<double>::operator()(const
i64&) method is incorrectly clamping i64 values to the int32 range before
converting to double, which causes a functional regression where valid i64
inputs outside int32 range (like 3000000000) get incorrectly clamped to int32
max values. Remove the clamping logic and instead convert the i64 value directly
to double without saturation, preserving the original value semantics for all
valid i64 inputs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7828aab8-5c77-4e41-bbcf-fed36cb82533

📥 Commits

Reviewing files that changed from the base of the PR and between 4a514d4 and dccf92f.

📒 Files selected for processing (2)
  • src/fl/stl/json.cpp.hpp
  • src/fl/stl/json/types.h

Comment thread src/fl/stl/json/types.h
Comment on lines 522 to +533
void operator()(const i64& value) FL_NOEXCEPT {
// NEW INSTRUCTIONS: AUTO CONVERT INT TO FLOAT
result = static_cast<double>(value);
// AUTO CONVERT INT TO FLOAT. Route through int32 to avoid pulling
// libgcc-nofp's `_floatdisf.o` soft-double cascade on no-FPU targets.
// The double path (`as_double()`) is DCE'd from LowMemory builds today,
// but keep the int32-route here as defense-in-depth. See FastLED #3076.
if (value > 2147483647LL) {
result = static_cast<double>(2147483647);
} else if (value < -2147483648LL) {
result = static_cast<double>(-2147483648);
} else {
result = static_cast<double>(static_cast<fl::i32>(value));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid int32 saturation in the i64 -> double conversion path.

At Line 522, float_conversion_visitor<double>::operator()(const i64&) now clamps to int32 before converting. That changes as_double() behavior for valid i64 inputs outside int32 (e.g., 3000000000 becomes 2147483647), which is a functional regression for callers that use json_value(i64) and then as_double().

Suggested fix
     void operator()(const i64& value) FL_NOEXCEPT {
-        // AUTO CONVERT INT TO FLOAT. Route through int32 to avoid pulling
-        // libgcc-nofp's `_floatdisf.o` soft-double cascade on no-FPU targets.
-        // The double path (`as_double()`) is DCE'd from LowMemory builds today,
-        // but keep the int32-route here as defense-in-depth. See FastLED `#3076`.
-        if (value > 2147483647LL) {
-            result = static_cast<double>(2147483647);
-        } else if (value < -2147483648LL) {
-            result = static_cast<double>(-2147483648);
-        } else {
-            result = static_cast<double>(static_cast<fl::i32>(value));
-        }
+        result = static_cast<double>(value);
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fl/stl/json/types.h` around lines 522 - 533, The
float_conversion_visitor<double>::operator()(const i64&) method is incorrectly
clamping i64 values to the int32 range before converting to double, which causes
a functional regression where valid i64 inputs outside int32 range (like
3000000000) get incorrectly clamped to int32 max values. Remove the clamping
logic and instead convert the i64 value directly to double without saturation,
preserving the original value semantics for all valid i64 inputs.

zackees added a commit that referenced this pull request Jun 15, 2026
…emplates (#3086)

Master Uno (AVR) build has been red since c0da8bd landed the Low-memory
polynomial fallbacks. Root cause: Arduino's WString.h (transitively included
via the Arduino core on AVR) defines `F()` as a PROGMEM-string macro. The
preprocessor rewrites every `F(value)` constructor cast in fl::math's
polynomial helpers (e.g. `F(1.0 / 6.0)`, `F(0.5)`) into `WString::F(1.0 / 6.0)`,
which fails with "initializer fails to determine size of '__c'".

Undefining the macro at the top of math.cpp.hpp is local to this translation
unit. fl::math itself never uses the macro; only end-user sketches do (where
the macro stays defined). No behavior change on any platform.

Pre-existing master breakage; surfaced while CI-checking PRs #3084 / #3085
for meta #3079.
… ~4 KB soft-FP cascade on no-FPU targets

Saves ~4 KB of `.text` on LPC845-BRK by killing the soft-double cascade. Closes #3076.

## Root cause (#3076 investigation)

`arm-none-eabi-objdump -dC firmware.elf` traced the `__aeabi_dadd` (2,088 B) and
`__aeabi_dmul` (1,392 B) ingression back to libgcc-nofp's `_floatdisf.o`, which
implements `__aeabi_l2f` (i64 -> single-precision float) by routing through
double-precision arithmetic. Any reachable `static_cast<float>(int64_t)` on a
no-FPU target therefore drags in the entire double soft-FP cascade -- ~8 KB
total of `__aeabi_dadd / dmul / dsub / i2d / ui2d / d2f / l2f / floatdisf`.

Two reachable call sites in the JSON codec did exactly this:

1. `float_conversion_visitor<FloatType>::operator()(const i64& value)` -- the
   visitor used by `json_value::as_float<T>()`. Did
   `result = static_cast<FloatType>(value);` directly.

2. `try_convert_to_specialized_array` ALL_FLOATS case -- when packing a JSON
   array as `vector<float>`, integer elements were converted via
   `vec.push_back(static_cast<float>(*val));` where `*val` is `i64`.

Both routed through `__aeabi_l2f` -> the full cascade.

The same `i64 -> i32 -> float` workaround already used at
`IntConversionVisitor::operator()(const float&)` lines 264-279 fixes both --
the comment there already names this exact issue (#3002).

## What changed

- `float_conversion_visitor<FloatType>::operator()(const i64&)`: clamps to
  INT32_MIN/MAX then routes through `static_cast<float>(static_cast<i32>(value))`.
  Values exceeding +/-INT32 saturate.
- `float_conversion_visitor<double>::operator()(const i64&)`: same treatment for
  symmetry. `as_double()` is DCE'd from LowMemory today but this is
  defense-in-depth for future reachability.
- `float_conversion_visitor<FloatType>::operator()(const bool&)`: changed
  `1.0 : 0.0` (double literals) to `1.0f : 0.0f` (float literals) so the
  ternary doesn't lift to double + then truncate.
- `json.cpp.hpp` ALL_FLOATS array packing: route via i32. `classify_array`
  already guarantees values fit in +/-2^24 before ALL_FLOATS classification
  fires (line 717), so the i32 narrowing is lossless for this path.

## Verification

```
arm-none-eabi-nm --print-size --demangle firmware.elf | grep '__aeabi_d|__aeabi_l2f|__floatdisf':
  before: __aeabi_dadd 2088 + __aeabi_dmul 1392 + __aeabi_l2f 120 + __floatdisf [alias]
          + __aeabi_d2f, __aeabi_dsub, __aeabi_i2d, __aeabi_ui2d, __floatdidf, __floatsidf, ...
          all present.
  after:  NONE. All double soft-FP and i64->float dropped.

soft-FP total (.text bytes from __aeabi_* / __div* / __clz* etc):
  before: 9,124 bytes
  after:  5,060 bytes  ← -4,064 B (single-precision __aeabi_f* remains for legit float paths)

total .text on lpc845brk + RX_SCT_WS2812=1:
  before: 77,004 bytes (+11,112 over 64 KB)
  after:  72,988 bytes ( +7,096 over 64 KB)
  -> 36% of the remaining meta #3079 overage cleared by this PR.
```

- `bash test --cpp fl/stl/json.cpp` -> passed
- LPC845 builds (with LD-script relaxed per FastLED/fbuild#594 workaround).

Closes #3076

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees force-pushed the feat/json-drop-float-variant-low-memory-3076 branch from dccf92f to 608798a Compare June 15, 2026 18:08
zackees added a commit that referenced this pull request Jun 15, 2026
…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]>
zackees added a commit that referenced this pull request Jun 15, 2026
…AS_LARGE_MEMORY (-2.5 KB on LowMemory) (#3087)

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]>
zackees added a commit that referenced this pull request Jun 15, 2026
… 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]>
@zackees
zackees merged commit 370a840 into master Jun 15, 2026
7 of 8 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 15, 2026
zackees added a commit that referenced this pull request Jun 15, 2026
…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]>
zackees added a commit that referenced this pull request Jun 16, 2026
…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]>
@zackees
zackees deleted the feat/json-drop-float-variant-low-memory-3076 branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

LPC845 bloat: 8.3 KB of soft-FP / integer-div leaks past the no-soft-FP invariant on LowMemory + RX_SCT_WS2812

1 participant