Skip to content

perf(lpc): close meta #3224 -- Tier 1B/2D/2E/3G + RAM gate (-10.3 KB flash, -1.3 KB RAM, on top of #3226) - #3232

Merged
zackees merged 9 commits into
masterfrom
feat/lpc-drop-float-variant-singleprec-softfp
Jun 18, 2026
Merged

zackees merged 9 commits into
masterfrom
feat/lpc-drop-float-variant-singleprec-softfp

Conversation

@zackees

@zackees zackees commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

Closes #3224.

Summary

Follow-on to PR #3226 (Tier 1A, already merged). This PR carries the remaining 9 commits that grow the LPC845-BRK headroom from ~6 KB (after Tier 1A) to ~16 KB and free another ~1.3 KB of RAM. Covers Tier 1B, Tier 2D, Tier 2E, Tier 3G, and the RAM-side companion to Tier 1B.

Cumulative numbers (LPC845-BRK, on top of #3226's Tier 1A)

Metric Master start (pre-Tier 1A) After Tier 1A (#3226) After this PR
Flash .text + .data 63,992 B 59,672 B 49,396 B
Flash headroom (64 KB) 1,544 B 5,864 B 16,140 B
RAM total 11,236 B 11,244 B 9,984 B
RAM free (16 KB) 5,148 B 5,140 B 6,400 B

Cumulative delta vs master start: −14,596 B flash (-22.8%) and −1,252 B RAM (-11.1%). Far exceeds #3224's 6 KB acceptance bar.

Commits (in chronological order)

Commit Topic Saved Tier
fix(ci/ty) Annotate sorted(...) lists as list[str] for ty inference (master unblocker) n/a unblocker
perf(remote) Tier 1B: gate scheduled-RPC + result-tracking paths −1,496 B 1B
perf(remote) Tier 1B: gate async-tracking + ACK detection −2,948 B 1B
perf(rpc) Tier 1B: gate async + response-aware + warnings in Rpc::handle −1,928 B 1B
perf(json) Tier 2D: gate packed-array tokens + float-number store in JsonBuilder −796 B 2D
perf(json) Tier 2E: gate JsonTokenizer array-lookahead −636 B 2E
perf(string) Tier 3G: narrow write(i64) / write(u64) to i32 path −68 B 3G
perf(remote) RAM: drop scheduler + result-vector + async-map fields −2,336 B flash, −1,260 B RAM 1B RAM
perf(rpc) Short error message constants −68 B 1B follow-on

Tier 1B — Remote + Rpc dispatch slim

Three independent gate axes:

  1. Scheduled execution path in Remote::processRpc (the timestamp != 0 branch) — drops scheduleFunction, its lambda capture, and the JSON ack construction.
  2. Async tracking — drops mAsyncRequests writes/erases + the __async / __skip envelope marker setters (see follow-on Rename RPC envelope markers '__async' / '__skip' -- they look reserved-namespace but are public envelope-control fields #3228 about the marker naming).
  3. Response-aware methods — drops ResponseSend construction + mResponseAwareFn invoke path.

Plus the RAM-side companion: drop the field declarations themselves (mScheduler, mResults, mAsyncRequests) when their usage is gated out, recovering ~1.3 KB of RAM per Remote instance. Public methods (sendAsyncResponse, sendStreamUpdate, sendStreamFinal, tick, pendingCount) become source-compatible no-ops on Low-memory.

Tier 2D/2E — JSON codec slim

JsonBuilder::on_token ARRAY_UINT8/INT16/FLOAT cases gated (packed-array optimizations unused on Low-memory). JsonTokenizer::scan_array_lookahead skipped entirely because the tokens it produces are now unreachable.

Tier 3G — string slim

basic_string::write(const i64&) / (const u64&) routed through fl::itoa / fl::utoa32 (32-bit divmod) instead of fl::itoa64 / fl::utoa64 (64-bit divmod). The 64-bit divmod on Cortex-M0+ pulls libgcc-nofp's __udivmoddi4 + __clzdi2 (~1.5 KB). Values exceeding INT32 / UINT32 saturate.

Pre-existing master unblocker bundled in

ci/lint_cpp/legacy_log_macro_checker.py + ci/tools/migrate_fl_logs.py ty type-inference fix (sorted(..., key=len) infers as list[Sized], not list[str]).

Test plan

  • Host JSON unit tests: bash test --cpp fl/stl/json.cpp → passed
  • Host RPC unit tests: bash test --cpp fl/remote/rpc.cpp → passed
  • Host functional tests: bash test --cpp functional → passed
  • LPC845-BRK build (PLATFORMIO_SRC_DIR=examples/AutoResearch fbuild build -e lpc845brk) → flash 49,396 B (75.4%), RAM 9,984 B (60.9%)
  • nm --print-size verification: zero references to all double-precision soft-FP routines, zero parseFloat, zero format_float, zero __aeabi_fadd / fsub / fmul / fdiv, zero mAsyncRequests / mResults / mScheduler storage on the LPC845 LowMemory build
  • bash lint --cpp passes
  • CI: full matrix

Behavior change on Low-memory targets

  • Remote::sendAsyncResponse / sendStreamUpdate / sendStreamFinal become one-line FL_WARN_LIT no-ops; async dispatch is not supported on Low-memory targets.
  • Remote::tick returns 0 and Remote::pendingCount returns 0 on Low-memory (no scheduler).
  • Scheduled RPCs (request.timestamp != 0) silently fall through to immediate execution.
  • JSON RPC error messages on Low-memory use short tags ("method", "404: ", "params") instead of descriptive sentences.

Sketches that need any of these behaviors on Low-memory targets can opt in by defining -DFL_PLATFORM_HAS_LARGE_MEMORY=1.

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Chores
    • Optimized framework for memory-constrained platforms by conditionally disabling advanced features (async RPC handling, float parsing, packed array support) on low-memory targets, reducing memory footprint and binary size.
    • Refactored internal regex patterns for improved code maintainability.
    • Added interrupt control fallback implementations for ARM platforms.

zackees added 9 commits June 18, 2026 13:35
…ence

`ty check` was failing on master for two CI/tools files because
`sorted(STR_TUPLE, key=len)` infers as `list[Sized]` (the `key=len`
constrains the element type to whatever `len` accepts, which is the
broader `Sized` protocol). The downstream `re.escape(name)` then
fails its `AnyStr` type-variable constraint.

Workaround: rewrite as `key=lambda s: len(s)` and add an explicit
`list[str]` annotation. Same runtime behavior.

Pre-existing master breakage; surfaced while building #3224 Tier 1A.
…y; -1.5 KB

#3224 Tier 1B: slim `Remote::processRpc` on no-FPU Low-memory targets.
The LPC8xx integer-only RPC contract is invoked immediate-only and never
introspects past RPC results through `mResults`. Gate two cold blocks on
`FL_PLATFORM_HAS_LARGE_MEMORY`:

1. The `timestamp != 0` scheduled-execution path -- drops the call to
   `scheduleFunction`, the object's lambda capture, and the JSON ack
   construction. ~700 B.
2. The `recordResult(...)` call after immediate execution -- drops the
   `mResults` push_back path and its `RpcResult` constructor.

Restructured to make the hot (immediate) path the fall-through case and
the cold (scheduled) path the early return, so the inliner stops merging
their bodies.

## Verification (LPC845-BRK)

    flash 59,672 B -> 58,176 B  (-1,496 B saved)
    headroom 5,864 B -> 7,360 B  (over the 6 KB #3224 acceptance bar)

Refs #3224 (Tier 1B item B, "Outline Remote::processRpc")
#3224 Tier 1B follow-on: the previous commit gated the scheduled-RPC
and result-tracking paths in Remote::processRpc. This commit also gates
the async-tracking path: `mAsyncRequests` writes, the post-call
`response["__async"]` ACK detection branch, and the post-call erase().

No production LowMemory sketch uses bindAsync / sendAsyncResponse today
(verified by grep across examples/AutoResearch/AutoResearchLowMemory.h
and friends). The async path stays available on Large-memory targets
where its cost is negligible.

## Verification (LPC845-BRK)

    flash 58,176 B -> 55,228 B  (-2,948 B saved)
    headroom 7,360 B -> 10,308 B

Total #3224 progress: -8.8 KB net since meta filing, headroom up 4x.

Refs #3224 (Tier 1B item B continued)
…e on Low-memory; -1.9 KB

#3224 Tier 1B continued: slim Rpc::handle by gating three cold/unused
paths on FL_PLATFORM_HAS_LARGE_MEMORY:

1. Async-ACK send block (json::object() + 4× set() + sink invoke).
   LowMemory sketches don't register async methods (verified by grep).
2. Response-aware dispatch branch (ResponseSend construction +
   mResponseAwareFn invoke). Same justification.
3. Warnings-array response builder (json::array() + per-warning
   json::push_back).
4. The "__async" response marker setter (skipped when the gate
   above drops the isAsync local).

## Verification (LPC845-BRK)

    flash 55,228 B -> 53,300 B  (-1,928 B saved)
    headroom 10,308 B -> 12,236 B

Total #3224 progress since meta filing: -10.7 KB, headroom up 8x.

Refs #3224 (Tier 1B continued)
…der; -0.8 KB

#3224 Tier 2D: slim `JsonBuilder::on_token` on Low-memory by gating two
cold cases:

1. `case ARRAY_UINT8 / ARRAY_INT16 / ARRAY_FLOAT` -- the tokenizer's
   array-packing optimization. Drops 3 large
   `make_shared<json_value>(vector<T>)` variant emplace instantiations
   plus the `parse_int_array<T>` and `parse_float_array` templates that
   feed them. The LowMemory integer-only RPC contract never sends
   packed JSON arrays.

2. `case NUMBER` float branch -- previously stored `0.0f` to short the
   `ieee754_parse_decimal` path (#3082). That `0.0f` still instantiated
   `make_shared<json_value>(float)` + the variant `float` emplace path.
   Replace with `i64(0)` so the float emplace is fully unreached on
   LowMemory.

## Verification (LPC845-BRK)

    flash 53,300 B -> 52,504 B  (-796 B saved)
    headroom 12,236 B -> 13,032 B

Refs #3224 (Tier 2D item D)
#3224 Tier 2E: the tokenizer's `scan_array_lookahead` path is dead work
on Low-memory because the packed-array tokens (ARRAY_UINT8 / INT16 /
FLOAT) it produces are now gated out of `JsonBuilder::on_token`. Skip
the lookahead entirely and always emit LBRACKET. Drops the lookahead
state machine + classify_array_token helper from the link.

## Verification (LPC845-BRK)

    flash 52,504 B -> 51,868 B  (-636 B saved)
    headroom 13,032 B -> 13,668 B

Refs #3224 (Tier 2E item E)
…1 KB

#3224 Tier 3G: `basic_string::write(const i64&)` and
`basic_string::write(const u64&)` call `fl::itoa64` / `fl::utoa64` which
internally use 64-bit divmod -- on Cortex-M0+ that anchors libgcc-nofp's
`__udivmoddi4` + `__clzdi2` (~1.5 KB combined). On Low-memory the
integer-only RPC contract never emits values outside int32 range, so
route through the 32-bit `itoa` / `utoa32` instead and saturate on
overflow.

## Verification (LPC845-BRK)

    flash 51,868 B -> 51,800 B  (-68 B saved from the i64 path)

The full 1.5 KB savings is blocked by another caller (autoResearch
sketch lambda#1) still using u64 divmod via `unsigned long` math.
Filing follow-on to slim that.

Refs #3224 (Tier 3G item G)
…w-memory; -2.3 KB flash, -1.3 KB RAM

#3224 Tier 1B RAM-side companion: the prior Tier 1B commits gated the
*usage* of `mScheduler`, `mResults`, and `mAsyncRequests` inside
`Remote::processRpc` / `tick` / `clear` / `update`, but the field
declarations stayed in the class -- so every `Remote` instance still
carried ~4 KB of dead RAM.

This commit gates the field declarations themselves and the implementing
methods (`scheduleFunction`, `recordResult`, `sendAsyncResponse`,
`sendStreamUpdate`, `sendStreamFinal`) under `FL_PLATFORM_HAS_LARGE_MEMORY`.
The three async-send methods keep their public signatures and become
one-line `FL_WARN_LIT` no-ops on Low-memory so source-level callers
don't have to be gated, just rebuilt.

## CMSIS intrinsic fix

The new Low-memory link path actually reaches the `__get_PRIMASK` /
`__enable_irq` / `__disable_irq` references in `m0clockless_c.h` -- the
previous `extern "C"` forward declarations satisfied the compile but
not the link. Replace with `static inline` Cortex-M inline-asm fallbacks
that are still guarded with `#ifndef` so a transitively-included
`cmsis_gcc.h` continues to win on platforms that have it on the path.

## Verification (LPC845-BRK)

    flash 51,800 B -> 49,464 B  (-2,336 B saved)
    RAM   11,244 B ->  9,984 B  (-1,260 B saved)
    headroom 13,668 B -> 16,072 B  (10x growth since meta filing)
    RAM free 5,140 B -> 6,400 B    (1.2 KB more for feature work)

Refs #3224 (Tier 1B item B RAM-side)
Replaces the descriptive error message strings (`"Invalid Request:
missing 'method'"`, etc.) with short tags (`"method"`, `"404: "`, …)
on Low-memory builds. Saves ~70 B by collapsing the per-call-site
`fl::string` literal-ctor + `operator+` concat at each `makeJsonRpcError`
call inside `Rpc::handle`. Large-memory targets keep the descriptive
form.

Refs #3224 (Tier 1B follow-on)
@zackees
zackees merged commit 51323eb into master Jun 18, 2026
10 checks passed
@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b6a9b106-423e-464d-9c66-c7ab7f011929

📥 Commits

Reviewing files that changed from the base of the PR and between 447bd1d and 9435ec5.

📒 Files selected for processing (8)
  • ci/lint_cpp/legacy_log_macro_checker.py
  • ci/tools/migrate_fl_logs.py
  • src/fl/remote/remote.cpp.hpp
  • src/fl/remote/remote.h
  • src/fl/remote/rpc/rpc.cpp.hpp
  • src/fl/stl/basic_string.cpp.hpp
  • src/fl/stl/json.cpp.hpp
  • src/platforms/arm/common/m0clockless_c.h

📝 Walkthrough

Walkthrough

Adds FL_PLATFORM_HAS_LARGE_MEMORY compile-time gating across Remote, Rpc, JsonTokenizer/JsonBuilder, and basic_string to eliminate async tracking, scheduled results, packed-array fast paths, float parsing, and 64-bit formatting on low-memory ARM targets. Replaces CMSIS extern "C" intrinsic declarations with guarded inline-asm fallbacks on M0. Two CI scripts extract inline macro-sort expressions into named module-level lists.

Changes

Low-memory platform feature gating

Layer / File(s) Summary
Remote class header: memory-gated declarations
src/fl/remote/remote.h
Adds sketch_macros.h include and wraps mAsyncRequests, scheduleFunction, recordResult, mScheduler, and mResults behind FL_PLATFORM_HAS_LARGE_MEMORY; only the lightweight AsyncRequest struct remains unconditionally declared.
Remote implementation: async/scheduling gating
src/fl/remote/remote.cpp.hpp
Adds sketch_macros.h include; gates sendAsyncResponse/sendStreamUpdate/sendStreamFinal as warning-only no-ops on low-memory; wraps timestamp extraction, async request-ID tracking, result recording, tick/pendingCount/clear scheduler paths, and the update loop's mResults flush behind FL_PLATFORM_HAS_LARGE_MEMORY.
RPC handler: compact error strings and response-aware gating
src/fl/remote/rpc/rpc.cpp.hpp
Introduces FL_RPC_ERR_* compact string constants; updates all JSON-RPC error returns to use them on low-memory targets; gates the response-aware invocation branch and "warnings" array emission behind FL_PLATFORM_HAS_LARGE_MEMORY.
STL: basic_string 64-bit formatting and JSON parsing gating
src/fl/stl/basic_string.cpp.hpp, src/fl/stl/json.cpp.hpp
Routes u64/i64 formatting through 32-bit saturating helpers on low-memory targets. In the JSON layer, bypasses array lookahead in the tokenizer, removes packed-array token fast-paths, and replaces float parsing with integer-only (i64) parsing on low-memory builds.
ARM M0 CMSIS intrinsic inline fallbacks
src/platforms/arm/common/m0clockless_c.h
Replaces extern "C" forward declarations for __get_PRIMASK, __enable_irq, and __disable_irq with #ifndef-guarded static inline fallback definitions using inline ARM assembly and FL_NOEXCEPT.

CI regex precomputation cleanup

Layer / File(s) Summary
Precompute sorted macro lists in CI scripts
ci/lint_cpp/legacy_log_macro_checker.py, ci/tools/migrate_fl_logs.py
Extracts inline sorted(...) calls inside re.compile(...) into named module-level lists (_SORTED_MACROS, _SORTED_MACRO_KEYS), both sorted by descending macro-name length.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • #3224 (LPC845 flash-budget Phase 2): This PR directly implements Tier 1-B (Remote::processRpc outline/gating), Tier 1-A (JSON float variant elimination on low-memory), Tier 2-D (JsonBuilder::on_token packed-array path removal), and Tier 3-G (basic_string::write 32-bit saturation path) — all sub-issues listed in the meta issue.

Possibly related PRs

  • FastLED/FastLED#3087: Both PRs modify src/fl/stl/json.cpp.hpp to conditionally disable IEEE754 float parsing and array lookahead under FL_PLATFORM_HAS_LARGE_MEMORY.
  • FastLED/FastLED#3088: Both PRs modify Rpc::handle() in src/fl/remote/rpc/rpc.cpp.hpp to gate control-flow paths behind FL_PLATFORM_HAS_LARGE_MEMORY.
  • FastLED/FastLED#3089: Both PRs add FL_PLATFORM_HAS_LARGE_MEMORY gating to the RPC/Remote layer — this PR gates async/scheduled-result flows while the retrieved PR gates schema generator construction.

Poem

🐰 Hop, hop — the flash is tight,
So I tucked the async code out of sight.
No floats on the M0, just integers run free,
CMSIS inline now, as clean as can be.
With #if and #else, I carved every byte —
A lean little rabbit makes low-memory delight! ✨

✨ 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/lpc-drop-float-variant-singleprec-softfp

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.

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.

META: LPC845 flash-budget Phase 2 — grow headroom from 1.4 KB to ~6-10 KB for feature capacity

1 participant