Skip to content

perf(rpc): gate rpc.discover + revert SBO bump to fix LowMemory regression (closes #3081) - #3088

Merged
zackees merged 1 commit into
masterfrom
feat/rpc-gate-discover-3081
Jun 15, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/rpc-gate-discover-3081

Conversation

@zackees

@zackees zackees commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #3081 and fixes a base LowMemory regression introduced by #3084 (variant collapse merged earlier today).

Two changes

1. Gate `rpc.discover` behind `FL_PLATFORM_HAS_LARGE_MEMORY`

On Low-memory targets the JSON-RPC `rpc.discover` introspection handler anchored `TypedSchemaGenerator::params()` for every registered method (~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 do not introspect at runtime.

2. Revert `FASTLED_INLINE_LAMBDA_SIZE` 96 → 64 on Low-memory

PR #3084 bumped the SBO from 64 to 96 B on Low-memory targets to absorb `UIButton::onClicked`'s 80 B wrapping closure (which captures a 72 B `fl::function<void()>`). That bump regressed the base LPC845 LowMemory build by ~3 KB because every `fl::function` instance's variant storage / copy / move / destroy paths grew.

The existing no-op heap-fallback branch (`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. `UIButton::onClicked` is link-dead on the AutoResearch LowMemory build, so DCE handles it cleanly.

Verification

Base LowMemory build (no `-DFASTLED_LPC_RX_SCT_WS2812=1`):

State Result
pre-#3084 master fit 64 KB
post-#3084 master +3,480 B over (regression)
post-#3084 + this PR +2,728 B over (improved by 720 B from #3081 gate)

Combined with sibling PRs #3085 (#3076 soft-FP) and #3087 (#3082 ieee754 gate) both already open, the full LowMemory + RX_SCT_WS2812 build should fit within 64 KB and the regression on the base build is overshot.

Test plan

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Optimized RPC discovery method availability based on platform memory constraints
    • Standardized lambda storage size configuration across all targets

… regression (closes #3081)

## 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]>
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Rpc::handle() in rpc.cpp.hpp wraps the rpc.discover method implementation behind #if FL_PLATFORM_HAS_LARGE_MEMORY, adding an include of fl/system/sketch_macros.h to enable that guard. In function.h, FASTLED_INLINE_LAMBDA_SIZE is simplified from a conditional (64 or 96 based on FL_FUNCTION_FULL_VARIANT) to a single fixed value of 64.

Changes

Low-memory flash footprint reductions

Layer / File(s) Summary
Gate rpc.discover behind FL_PLATFORM_HAS_LARGE_MEMORY
src/fl/remote/rpc/rpc.cpp.hpp
Adds fl/system/sketch_macros.h include and wraps the rpc.discover branch in #if FL_PLATFORM_HAS_LARGE_MEMORY / #endif, omitting the schema generator and JSON catalog code on low-memory targets.
Unify FASTLED_INLINE_LAMBDA_SIZE to 64 bytes
src/fl/stl/function.h
Replaces the #if FL_FUNCTION_FULL_VARIANT conditional (64 vs 96) with an unconditional 64, removing the separate low-memory SBO sizing path.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3055: Fixes the computation of FL_PLATFORM_HAS_LARGE_MEMORY via include ordering, which this PR's rpc.discover guard depends on for correctness.
  • FastLED/FastLED#3084: Directly modifies the same FASTLED_INLINE_LAMBDA_SIZE macro in src/fl/stl/function.h, making it a close sibling change at the same code location.

Poem

🐇 Hop hop, the schema's away,
On tiny chips it mustn't stay!
Sixty-four bytes, no more, no less,
SBO unified — what happiness.
Low-memory flash: a tighter nest,
The rabbit tucks the bloat to rest! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 accurately summarizes the main changes: gating rpc.discover and reverting SBO, both addressing the LowMemory regression from #3084 as stated in PR objectives.
Linked Issues check ✅ Passed The PR gates rpc.discover behind FL_PLATFORM_HAS_LARGE_MEMORY and reverts FASTLED_INLINE_LAMBDA_SIZE to 64 bytes, directly addressing #3081's RPC dispatch bloat and the ~3KB regression from #3084.
Out of Scope Changes check ✅ Passed Both code changes directly target the stated objectives: conditional compilation of rpc.discover to reduce RPC dispatch mass and reverting the SBO bump to fix the LowMemory regression.

✏️ 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/rpc-gate-discover-3081

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.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 15, 2026
@zackees
zackees merged commit e18aa2b 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/rpc-gate-discover-3081 branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment