Skip to content

fix(autoresearch): gate 6 companion .cpp files on FASTLED_AUTORESEARCH_LOW_MEMORY (refs #3076) - #3123

Merged
zackees merged 1 commit into
masterfrom
feat/3076-autoresearch-low-memory-cpp-gates
Jun 16, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/3076-autoresearch-low-memory-cpp-gates

Conversation

@zackees

@zackees zackees commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Gates the six companion .cpp files in examples/AutoResearch/ on FASTLED_AUTORESEARCH_LOW_MEMORY so they become empty translation units under LowMemory builds — mirroring the gate AutoResearch.ino already applies to its own setup/loop body.

Why

Two problems at once:

1. Master build regression on LowMemory (verified now)

AutoResearchRemote.cpp:3650 calls bare memcpy. With current master plus a LowMemory target (e.g. bash autoresearch lpc845brk --pin-toggle-rx), the compile fails with:

examples/AutoResearch/AutoResearchRemote.cpp:3650:13: error: 'memcpy' was not declared in this scope
 3650 |             memcpy(dst_buf, src_buf, bytes);
      |             ^~~~~~

The LowMemory bring-up surface (AutoResearchLowMemory.h) doesn't use anything in Remote.cpp, so gating it out fixes the regression cleanly. Same applies to the other five companion files — none are used in LowMemory mode.

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 / FastLED brightness chain — and the LTO output now reflects that without anyone needing to read 3000+ lines of Remote.cpp to confirm.

Pattern

Each .cpp picks up the same auto-detect via fl/system/sketch_macros.h:

#include "fl/system/sketch_macros.h"
#if !defined(FASTLED_AUTORESEARCH_LOW_MEMORY) && !FL_PLATFORM_HAS_LARGE_MEMORY
#define FASTLED_AUTORESEARCH_LOW_MEMORY 1
#endif
#if !(defined(FASTLED_AUTORESEARCH_LOW_MEMORY) && FASTLED_AUTORESEARCH_LOW_MEMORY)

// ... original file contents ...

#endif  // !FASTLED_AUTORESEARCH_LOW_MEMORY

Matches the conditional structure of AutoResearch.ino itself (line 18). AVR / ATtiny / similar Tiny-memory targets benefit automatically via FL_PLATFORM_HAS_LARGE_MEMORY == 0 without needing an explicit build flag.

Files

File Before After
AutoResearchBle.cpp full BLE state accessor empty under LowMemory
AutoResearchHelpers.cpp pulls in fl/channels/manager.h, validation suite empty under LowMemory
AutoResearchNet.cpp pulls in fl/stl/json.h + ESP32 net stack empty under LowMemory
AutoResearchOta.cpp pulls in fl/net/ota.h empty under LowMemory
AutoResearchRemote.cpp the full RPC dispatch surface (3000+ lines, has the memcpy regression) empty under LowMemory
AutoResearchTest.cpp pulls in <FastLED.h> + entire chipset matrix empty under LowMemory

Verification

On LPC845-BRK against current master:

  • Before this PR: bash autoresearch lpc845brk --pin-toggle-rx --upload-port COM10 fails at compile with the bare-memcpy error.
  • After this PR: build succeeds, fits 64 KB flash budget, firmware flashes, echo RPC round-trips end-to-end. (The pinToggleRx RPC silent-fail observed is a separate runtime concern about the 8 KB EdgeTime[2048] stack frame on a 16 KB SRAM part — tracked separately, not in scope here.)

Refs

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Added low-memory platform support to AutoResearch examples, enabling the library to function on memory-constrained devices by automatically disabling non-essential features during compilation.

…RESEARCH_LOW_MEMORY

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

coderabbitai Bot commented Jun 16, 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: 414d8488-30e1-4245-8a43-46fac54f1910

📥 Commits

Reviewing files that changed from the base of the PR and between ebfda30 and a0d4f69.

📒 Files selected for processing (6)
  • examples/AutoResearch/AutoResearchBle.cpp
  • examples/AutoResearch/AutoResearchHelpers.cpp
  • examples/AutoResearch/AutoResearchNet.cpp
  • examples/AutoResearch/AutoResearchOta.cpp
  • examples/AutoResearch/AutoResearchRemote.cpp
  • examples/AutoResearch/AutoResearchTest.cpp

📝 Walkthrough

Walkthrough

Six AutoResearch example .cpp files each gain an identical compile-time guard pattern: they include fl/system/sketch_macros.h, define FASTLED_AUTORESEARCH_LOW_MEMORY to 1 when FL_PLATFORM_HAS_LARGE_MEMORY is false, and wrap their existing implementation body with #if !(FASTLED_AUTORESEARCH_LOW_MEMORY) / #endif to exclude BLE, helpers, networking, OTA, remote/RPC, and test-matrix code from low-memory platform builds.

Changes

AutoResearch Low-Memory Compile Guards

Layer / File(s) Summary
Low-memory #if/#endif guards across all AutoResearch files
examples/AutoResearch/AutoResearchBle.cpp, examples/AutoResearch/AutoResearchHelpers.cpp, examples/AutoResearch/AutoResearchNet.cpp, examples/AutoResearch/AutoResearchOta.cpp, examples/AutoResearch/AutoResearchRemote.cpp, examples/AutoResearch/AutoResearchTest.cpp
Each file gains an opening block that includes fl/system/sketch_macros.h, conditionally defines FASTLED_AUTORESEARCH_LOW_MEMORY 1 when FL_PLATFORM_HAS_LARGE_MEMORY is false, and wraps the existing implementation with #if !FASTLED_AUTORESEARCH_LOW_MEMORY / #endif, excluding the heavy implementation from low-memory builds.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3041: Directly related — introduces the low-memory mode concept in the unified AutoResearch.ino sketch using the same FASTLED_AUTORESEARCH_LOW_MEMORY gating concept that this PR extends to all component .cpp files.
  • FastLED/FastLED#2753: Related — adds RPC endpoints inside AutoResearchRemote.cpp, the same file this PR now wraps with a low-memory exclusion guard.

Poem

🐇 Hoppity-hop through the preprocessor gate,
Where memory's small, we conditionally wait.
#if !LOW_MEMORY — the big code may pass,
But tiny platforms skip BLE and class.
With FL_PLATFORM_HAS_LARGE_MEMORY in hand,
The rabbit trims builds as the compiler planned! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% 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 clearly and concisely summarizes the main change: gating six AutoResearch companion .cpp files on the FASTLED_AUTORESEARCH_LOW_MEMORY preprocessor flag, which is precisely what all the file summaries document.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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/3076-autoresearch-low-memory-cpp-gates

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.

@zackees
zackees merged commit 2df75a6 into master Jun 16, 2026
6 of 7 checks passed
@zackees
zackees deleted the feat/3076-autoresearch-low-memory-cpp-gates branch June 16, 2026 02:34
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 16, 2026
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