Skip to content

[meta] Break up oversized .cpp files into <1K LOC chunks (string.cpp, AutoResearchRemote.cpp, fixed_point.cpp) #3127

Closed

Description

@zackees

Goal

Split three monolithic .cpp files so each resulting file is under 1,000 LOC. The current files are 4K–6.5K lines each, causing slow re-compiles, large unity-build blast radius (any edit re-builds the whole TU), painful navigation, and brittle merge conflicts on review.

File Lines Size Proposed split
tests/fl/stl/string.cpp 6,468 216 kB 9 files
tests/fl/math/fixed_point.cpp 5,230 170 kB 8 files
examples/AutoResearch/AutoResearchRemote.cpp 4,017 171 kB 7 files

All three files already have clear // SECTION: markers or natural per-type/per-RPC boundaries — the cuts are largely mechanical.


Sub-task 1 — tests/fl/stl/string.cpp (6,468 → 9 files of ~800 LOC)

The file is already self-described as a concatenation of four legacy test files plus four newer sections. Each one becomes its own .cpp. Each new file gets its own FL_TEST_FILE(FL_FILEPATH) block (same pattern every other tests/fl/stl/*.cpp already uses).

New file Source range (current line nums) Approx LOC
tests/fl/stl/string_basic_a.cpp 1–2283 ~870
tests/fl/stl/string_basic_b.cpp 2284–3129 ~840
tests/fl/stl/string_comprehensive.cpp 3130–3896 ~770
tests/fl/stl/string_memory_bugs.cpp 3897–4271 ~370
tests/fl/stl/string_optimization.cpp 4272–4727 ~460
tests/fl/stl/string_type_erased.cpp 4728–4922 (basic_string COW/move/inline-to-heap) ~195
tests/fl/stl/string_append_concat.cpp 4923–5230 ~310
tests/fl/stl/string_comparison_hash.cpp 5231–5500 ~270
tests/fl/stl/string_ctor_iterator.cpp 5501–6468 ~970

All // SECTION: headers in the current file map 1:1 to these targets. The 0–3129 range is the only one that needs an internal split — splitting it at line 2284 (FL_TEST_CASE("string reverse iterators")) lands two ~850-line files.


Sub-task 2 — tests/fl/math/fixed_point.cpp (5,230 → 8 files of ~700 LOC)

The file already documents its structure in the top-of-file comment block (lines 1–102). The natural per-type seams give the cleanest cut. The shared accuracy_bounds<T> template specializations and constexpr/bit-exact infrastructure (lines 104–1262) move into a new private header.

New file Content Source range Approx LOC
tests/fl/math/fixed_point_bounds.h accuracy_bounds<T> specializations + helpers (no tests) 104–810 ~705
tests/fl/math/fixed_point_constexpr.cpp constexpr raw / from_raw / arithmetic / math / value verification 811–1130 ~320
tests/fl/math/fixed_point_bit_exact.cpp Bit-exact + Transcendental tests + accuracy reports 1131–1970 ~840
tests/fl/math/fixed_point_signed_types.cpp signed fixed_point<> bit-exact + accuracy bounds (s4x12, s8x8, s12x4, s8x24, s16x16, s24x8) 1971–2186 + GitHub-#2174 regression at 2084 ~210
tests/fl/math/fixed_point_u4x12_u8x8.cpp u4x12 + u8x8 type-specific tests 2187–3055 ~870
tests/fl/math/fixed_point_u12x4_u16x16.cpp u12x4 + u16x16 type-specific tests 3056–3968 ~915
tests/fl/math/fixed_point_u8x24_u24x8.cpp u8x24 + u24x8 type-specific tests 3969–4817 ~850
tests/fl/math/fixed_point_misc.cpp scalar alignment, constexpr scalar ops, integer ctor, pow boundary (#2969) 4818–5230 ~410

The namespace { ... } anonymous block currently spanning the entire file would be rewritten as namespace fl::test::fp_detail { ... } (or similar) in the shared header, so per-file translation units don't drag in the full bounds table when they only need one type.

Note: the u4x12_u8x8 and u12x4_u16x16 merges land at ~870 and ~915 LOC respectively. If either creeps past 1000 during the actual extraction (extra blank lines, header re-includes), split them per-type — the cut point is obvious in each case.


Sub-task 3 — examples/AutoResearch/AutoResearchRemote.cpp (4,017 → 7 files of ~600 LOC)

This is the dominant compile-time hog. registerFunctions() alone is lines 1302–3919 = 2,617 lines — a single C++ method. Splitting it by RPC family is the win.

Hook policy note: ci/hooks/protect_example_ino.py blocks new .ino files but allows new .cpp companions to an existing .ino. AutoResearch's example sketch is AutoResearch.ino; sibling .cpp files like AutoResearchRemote.cpp already exist, so this split adds more siblings — no override needed.

New file Content Source range Approx LOC
examples/AutoResearch/AutoResearchRemoteCore.cpp helpers (printJsonRaw, printStreamRaw, ScopedFastLedBrightness), ctor/dtor, tick(), registerAllMethods() glue, top-level registerFunctions() shell that calls bind*Methods() 1–310 + 3920–4017 + new dispatch shell ~480
examples/AutoResearch/AutoResearchRemoteRegistry.cpp runSingleTestImpl() + simple RPCs (status, debugTest, deliberateHang, drivers, runSingleTest) 311–1376 ~870 → split if needed
examples/AutoResearch/AutoResearchRemoteParallel.cpp runParallelTest, flexioObjectFledTest, RX-only bypass paths 1377–1963 ~590
examples/AutoResearch/AutoResearchRemoteGpio.cpp testGpioConnection, setTxPin, pin/driver state RPCs 1964–2487 ~525
examples/AutoResearch/AutoResearchRemoteSimd.cpp testSimd, testSimdBenchmark, parlioStreamValidate 2488–2844 ~360
examples/AutoResearch/AutoResearchRemoteAsync.cpp testAsync, runNetClientTest, runNetLoopback 2845–3162 ~320
examples/AutoResearch/AutoResearchRemoteCoroutines.cpp Coroutine tests (basic, stop-while-running, multi-concurrent, promise then/catch, pipeline) 3163–3919 ~760

Split mechanism. registerFunctions() stays a thin shell in Core.cpp and calls free helpers defined in each family file:

// In Core.cpp
void AutoResearchRemoteControl::registerFunctions(fl::shared_ptr<AutoResearchState> state) {
    mState = state;
    bindRegistryMethods(mRemote, mState, this);
    bindParallelMethods(mRemote, mState, this);
    bindGpioMethods(mRemote, mState);
    bindSimdMethods(mRemote, mState);
    bindAsyncMethods(mRemote, mState);
    bindCoroutineMethods(mRemote, mState);
}

Each family file exposes void bind<Family>Methods(fl::Remote*, fl::shared_ptr<AutoResearchState>, ...) from an internal header AutoResearchRemoteFamilies.h. This is the minimal-diff path. Alternative: each family file becomes a .cpp.hpp included once from Core.cpp — discuss in the implementation PR.


Why this matters (cross-cutting)

  1. Edit-recompile blast radius. Changing one assertion in string.cpp triggers a 216 kB TU recompile (cold ~8–15 s on Windows, warm ~1–3 s after compiler cache hit). Splitting cuts the edit-recompile loop by 4–8x for the file under active edit.
  2. PCH thrash. tests/test_pch.h pulls in FastLED.h (~1,170 transitive headers). Smaller TUs mean the per-TU post-PCH compile time drops linearly with the new file size.
  3. Review/navigation. Diffs on a 6.5K-line file are unreviewable in the GitHub UI without clicking "Load more" repeatedly; 1K-line files render in a single page.
  4. Editor responsiveness. clangd/LSP on 6.5K-line files with deep template instantiation (fixed_point) takes 5–10 s per re-index after every save.

Execution order (recommended)

  1. fixed_point.cpp first — cleanest cut, per-type seams already exist, lowest risk of regression. Each sub-PR is mechanical extraction. One PR per new file so each is reviewable.
  2. string.cpp second — // SECTION: markers already in the file; cuts are 1:1 with markers. Same one-PR-per-file rhythm.
  3. AutoResearchRemote.cpp last — most architectural (factoring registerFunctions body), benefits from learnings on the test files first. Pre-PR: confirm split style with @zackees.

Acceptance criteria

  • Every resulting .cpp file is < 1,000 LOC.
  • Each new test file has its own FL_TEST_FILE(FL_FILEPATH) (matches every other tests/fl/stl/*.cpp).
  • bash test --cpp passes on all three sets — no test loss, no test rename without justification.
  • bash compile uno --examples AutoResearch succeeds.
  • bash autoresearch --parlio smoke test still succeeds against an attached device (or the host CI dry-run).
  • Build-system source-list cache picks up the new files automatically (ci/meson/test_discovery.py scans tests/**/*.cpp).
  • Each file split lands in its own PR stacked on master, not bundled.

Out of scope (deliberately deferred)

  • Splitting src/ aggregators (separate issue family — touches the src/fl/build/*+.cpp unity-build design).
  • Test deduplication / cross-section merges (preserve test content 1:1 in this round).
  • Renaming any FL_TEST_CASE strings.

Open questions

  1. fixed_point_bounds.h — should accuracy_bounds<T> move to a public-ish detail header under src/fl/math/, or stay test-only under tests/fl/math/? Recommendation: test-only.
  2. AutoResearchRemote split style — free-function-per-family vs .cpp.hpp inline-includes. Need maintainer call.
  3. Should string_basic_a.cpp + string_basic_b.cpp get more descriptive names (e.g., string_construction.cpp, string_search.cpp)? Mechanical names ship faster; semantic names need test-case-by-test-case classification.

cc: @zackees

Generated with Claude Code.

Activity

  1. added
    type: feature
    priority: medium
    area: ci
    on Jun 16, 2026
  2. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    Sub-issues filed for the three file splits, in the recommended execution order:

    Total: 24 PRs across the three sub-issues. Working sequentially.

    Related: #3129 tracks build-system rebuild workarounds (separate audit, separate fix list).

  3. 17 remaining items

  4. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    Meta #3127 — Completion summary

    Two of three sub-issues complete; #3132 deferred with documented architectural blocker.

    Sub-issue #3130 — tests/fl/math/fixed_point.cpp (5,230 LOC → all files under 1K) ✅ CLOSED

    7 PRs merged to master:

    Sub-issue #3131 — tests/fl/stl/string.cpp (6,468 LOC → 11 files under 1K, original deleted) ✅ CLOSED

    9 PRs merged to master:

    Sub-issue #3132 — AutoResearchRemote.cpp split ⏸ DEFERRED

    Closed as "not planned" — needs a fresh sub-issue once @zackees decides on the split mechanism. Rationale documented in the closing comment on #3132. The file has evolved beyond the original plan with multiple new RPC bindings; updating the plan + getting the architectural call is required before safely starting the work.

    Bonus deliverable

    Filed #3129 (build-system rebuild workarounds audit + zccache upstream blockers) as a separate meta during this run.

    Totals

    • 16 PRs merged across two sub-issues
    • 22 new files created (tests/fl/math/* and tests/fl/stl/*)
    • 2 files deleted (tests/fl/stl/string.cpp consolidated away; original tests/fl/math/fixed_point.cpp retained at 613 LOC since some bit-exact + transcendental + accuracy report tests remain there per the helper-extraction design)
    • 1 hook updated (ci/hooks/check_test_file_pairing.py — sibling-split allowance unblocks future test-file splits)

    Closing meta. Re-open if anything needs follow-up beyond what's already in #3129 or a future #3132-successor.

  5. moved this from Triage to Done in FastLED Trackeron Jun 16, 2026
  6. moved this from Done to Triage in FastLED Trackeron Jun 16, 2026
  7. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    All three sub-issues complete:

    Total: 17 PRs merged, 30+ new files, every resulting .cpp under 1,000 LOC.

    Closing meta.

  8. moved this from Triage to Done in FastLED Trackeron Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cipriority: mediumtype: feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions