Repository navigation
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
Conversation
…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)
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughAdds ChangesLow-memory platform feature gating
CI regex precomputation cleanup
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Possibly related PRs
Poem
✨ 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 |
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)
.text + .dataCumulative 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)
fix(ci/ty)sorted(...)lists aslist[str]for ty inference (master unblocker)perf(remote)perf(remote)perf(rpc)perf(json)perf(json)perf(string)write(i64)/write(u64)to i32 pathperf(remote)perf(rpc)Tier 1B — Remote + Rpc dispatch slim
Three independent gate axes:
Remote::processRpc(thetimestamp != 0branch) — dropsscheduleFunction, its lambda capture, and the JSON ack construction.mAsyncRequestswrites/erases + the__async/__skipenvelope 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).ResponseSendconstruction +mResponseAwareFninvoke 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 perRemoteinstance. Public methods (sendAsyncResponse,sendStreamUpdate,sendStreamFinal,tick,pendingCount) become source-compatible no-ops on Low-memory.Tier 2D/2E — JSON codec slim
JsonBuilder::on_tokenARRAY_UINT8/INT16/FLOAT cases gated (packed-array optimizations unused on Low-memory).JsonTokenizer::scan_array_lookaheadskipped entirely because the tokens it produces are now unreachable.Tier 3G — string slim
basic_string::write(const i64&)/(const u64&)routed throughfl::itoa/fl::utoa32(32-bit divmod) instead offl::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.pytytype-inference fix (sorted(..., key=len)infers aslist[Sized], notlist[str]).Test plan
bash test --cpp fl/stl/json.cpp→ passedbash test --cpp fl/remote/rpc.cpp→ passedbash test --cpp functional→ passedPLATFORMIO_SRC_DIR=examples/AutoResearch fbuild build -e lpc845brk) → flash 49,396 B (75.4%), RAM 9,984 B (60.9%)nm --print-sizeverification: zero references to all double-precision soft-FP routines, zeroparseFloat, zeroformat_float, zero__aeabi_fadd / fsub / fmul / fdiv, zeromAsyncRequests/mResults/mSchedulerstorage on the LPC845 LowMemory buildbash lint --cpppassesBehavior change on Low-memory targets
Remote::sendAsyncResponse/sendStreamUpdate/sendStreamFinalbecome one-lineFL_WARN_LITno-ops; async dispatch is not supported on Low-memory targets.Remote::tickreturns 0 andRemote::pendingCountreturns 0 on Low-memory (no scheduler).request.timestamp != 0) silently fall through to immediate execution."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
nm --print-sizeworkflow used throughout)__async/__skipenvelope markers🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes