Repository navigation
Description
Symptom
On LPC845 LowMemory + FASTLED_LPC_RX_SCT_WS2812=1 (the build that overflows 64 KB FLASH by 11 KB per meta #3079), the JSON-RPC dispatch surface is the single largest .text cluster. Real arm-none-eabi-nm --print-size figures:
| Symbol | Bytes |
|---|---|
fl::Rpc::handle(fl::json const&) |
3,124 |
fl::Remote::processRpc(fl::json const&) |
2,996 |
fl::TypedRpcBinding<fl::string(int,int,int,int)>::invokeWithReturn |
2,196 |
fl::detail::TypedSchemaGenerator<fl::string(int,int,int,int)>::params |
856 |
fl::TypedRpcBinding<int(int)>::invokeWithReturn |
610 |
fl::JsonArgConverter<int(int)>::convertArg<0u> |
512 |
fl::JsonArgConverter<fl::string(int,int,int,int)>::convertArg<0u> |
512 |
Plus three unordered_map<string, RpcEntry>::rehash_inline_no_resize instantiations |
~1,800 |
| Total | ~12,600 bytes (~17% of .text) |
A single 4-int-argument RPC method (pinToggleRx) lifts a TypedRpcBinding<string(int,int,int,int)>::invokeWithReturn of 2,196 bytes, plus a sibling 856-byte TypedSchemaGenerator<...>::params template. The pattern multiplies per registered method signature; on LPC8xx where only 3-4 methods are registered, this is ~12 KB of dispatch overhead vs ~3 KB of actual method-body code.
Hypothesis
fl::Rpc::handle and fl::Remote::processRpc look like they over-inline the JSON-walking + method-lookup + error-formatting + response-emit pipeline into a single monolithic function. On a 64 KB target with no I-cache, that monolith is paid in flash even when each per-method instantiation duplicates similar bytes.
TypedRpcBinding<Sig>::invokeWithReturn is a function template: each unique Sig registered emits a fresh ~600-2,200 byte clone. On targets like ESP32 with 4 MB flash this is irrelevant; on LPC845 with 64 KB it is a budget breaker.
Possible directions
- De-template the binding glue. Move the type-erased dispatch path through a single non-template function that takes a
(void* binding, json const& args, ResponseSend& resp) -> voidthunk, with the per-signature glue reduced to a tiny ~50-byte trampoline that argument-extracts then calls the actual user function. Saves ~80% ofTypedRpcBinding::invokeWithReturnper signature. - Split
fl::Rpc::handleandfl::Remote::processRpcinto outline + slow paths. The hot path (method-name lookup + dispatch) stays inline; error formatting, schema-help, and async-ack handling outline into separate translation units that get DCE'd when not reachable. - Merge the three
unordered_map<string, ...>::rehash_inline_no_resizeinstantiations — they differ only in the value type (RpcEntryvsAsyncRequestvsshared_ptr<StringHolder>). A single non-template rehash that takes a per-entry-stride parameter would save ~1.2 KB. - Schema generation behind a build flag.
TypedSchemaGenerator<...>::paramsis 856 bytes per signature; it only matters for runtime introspection (the__rpc_schemadiscovery method). Gate it behindFASTLED_RPC_SCHEMA=1so LowMemory builds drop it entirely.
Repro
Same as meta #3079.
arm-none-eabi-nm --print-size --size-sort --demangle firmware.elf | \
awk '$3=="t" || $3=="T"' | tail -25
fl::Rpc::handle and fl::Remote::processRpc are the top two .text symbols today.
Acceptance
-
fl::Rpc::handledrops below 1.5 KB -
fl::Remote::processRpcdrops below 1.5 KB - Per-signature
TypedRpcBinding<Sig>::invokeWithReturndrops below 500 bytes for a 4-int signature - Total RPC-dispatch
.textmass on LPC845 LowMemory + RX_SCT_WS2812 build drops below 5 KB (from ~12.6 KB today) - No regression in RPC dispatch semantics or async-ack behavior on ESP32 / Teensy
Related
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Jun 15, 2026
Tracked under meta #3079 alongside #3076 (soft-FP), #3077 (fl::function variant), #3082 (JSON codec). Depends on FastLED/fbuild#594 for proper bloat iteration.
zackees commentedon Jun 15, 2026
Investigation findings (2026-06-15)
Source survey
TypedRpcBinding<R(Args...)>::invokeWithReturnis defined as a class-template member function insrc/fl/remote/rpc/typed_rpc_binding.h:75. For each registered RPC method signature, the compiler emits a fresh instantiation containing inlined:Converter::convert(jsonArgs)—JsonArgConverter<R(Args...)>template that walks thejsonargs and tuples up converted C++ values.fl::make_tuple(...)+fl::tuple<...>constructors for the C++ value tuple.detail::TypeToJson<R>::convert(returnValue)— converts the C++ return value back tojson.mFunction(...)call throughfl::function<R(Args...)>'s variant.For the
fl::string(int,int,int,int)signature (used bypinToggleRx), the resultinginvokeWithReturnis 2,196 bytes. The 4-int variant is 0.6 KB; the string-return + tuple machinery dominates.fl::Rpc::handle(fl::json const&)at 3,124 bytes is the table-lookup + dispatch + error-formatting + response-emit pipeline rolled into a single function.fl::Remote::processRpc(fl::json const&)at 2,996 bytes is the JSON-RPC envelope handler (id/jsonrpc-version validation + async vs sync dispatch + ACK emit).Why this is hard
TypedRpcBindingis the central abstraction. Every registered RPC method routes through it. De-templating it would mean:void invoke_thunk(void* binding_state, const json& args, ResponseSend& resp)that gets stored alongside method names in the dispatch tableThe risk: the dispatch table currently relies on compile-time type information to safely route a
jsonto the rightfl::function<Sig>. Type-erasing it means re-introducing the runtime type-check that the templates were designed to avoid. It's a real engineering trade-off, not a clear win.Scope honesty
This is genuine API-surface design work. It cannot be done as a single drive-by PR. Estimated scope: 2-3 weeks of careful design + implementation + cross-platform CI verification (the RPC path is used on ESP32 + Teensy + LPC + WASM hosts).
Marking as scoped for design discussion before PR work. Recommend deferring until #3076 lands first — if dropping the
floatvariant alternative saves the 8 KB soft-FP cascade, the LPC845 LowMemory build may fit without touching the RPC dispatch at all, and this issue becomes "nice to have" rather than blocker.perf(rpc/lpc): gate schema generator + enable RX_SCT_WS2812 default o…
perf(rpc): gate rpc.discover + revert SBO bump to fix LowMemory build…