Skip to content

AutoResearchParlioEncode.h times a mirror of production hot loop, not production code (facade cheat) #3524

Closed

Description

@zackees

Summary

examples/AutoResearch/AutoResearchParlioEncode.h benchmarks a mirror of the production hot loop, not the actual production code. This is a facade — if the production engine drifts and the mirror doesn't get updated, the bench reports misleading numbers that don't reflect real driver performance.

Where the facade lives

File: examples/AutoResearch/AutoResearchParlioEncode.h

Line 70-71 explicitly describes the pattern:

// Mirror of the engine's clockless hot loop for one byte-position, 16-lane
// Wave8 path (parlio_engine.cpp.hpp ≈line 981-994). lane_stride matches the
// production layout: lane k reads from scratch[k * lane_stride + byte_offset].

The fl_parlio_inner_one_byte_position_bf1 (line 73-88) and fl_parlio_inner_four_byte_positions_bf1_pipe4 (line 90-122) functions duplicate the encode inner loop from parlio_engine.cpp.hpp and are then timed by fl_parlio_measure().

The measureParlioEncode() handler returns the bench result but is timing the DUPLICATED code, not the real engine path.

Why this is a facade / cheating pattern

  1. Silent drift risk — if parlio_engine.cpp.hpp:981-994 gets optimized (or de-optimized) and the mirror stays static, the bench reports the mirror's timing, not production's. Users trust the bench numbers to guide production decisions.
  2. Duplicated code review surface — every future change to the production encode has to remember to update this mirror. Code review can miss the mirror because it lives under examples/.
  3. Divergence is invisible — nothing enforces that the mirror matches production. No compile-time check, no runtime cross-check, no host test.

Comparison: AutoResearchParlioStream.h does it right

The sibling AutoResearchParlioStream.h (line ~128 onward) drives the actual engine via FastLED.add(cfg) + FastLED.show() — the same path production code hits. That's the correct pattern. Its result numbers are real end-to-end measurements.

What "the right way" would look like

Two options:

A. Delete the mirror, expose the production hot loop as a callable benchmark helper. Move the byte-position inner loop into src/platforms/esp/32/drivers/parlio/parlio_engine.h (or a companion parlio_bench.h) as an inline function, then the harness times the SAME function production uses. Guarantees no drift.

B. Assert equivalence in a host test. Add a unit test in tests/platforms/esp/32/drivers/parlio/ that feeds the same input through both the mirror and the production path and asserts the output bytes match. Fails at test time if the mirror drifts.

Option A is cleaner. Option B is a lower-effort ratchet if the production hot loop is hard to expose cleanly.

Acceptance

  • AutoResearchParlioEncode.h no longer duplicates the production encode inner loop
  • measureParlioEncode() times the production hot loop directly, OR
  • A host-side unit test asserts byte-exact equivalence between the mirror and production output, failing loudly on drift
  • bash test --cpp — all host tests green
  • bash lint --cpp — clean

Non-goals

  • Not changing AutoResearchParlioStream.h — that one already drives the real engine correctly.
  • Not touching production PARLIO code paths unless option A requires it.
  • Not audit-sweeping every other AutoResearch harness in this issue — file separate issues if similar patterns exist elsewhere.

Reference

  • Facade site: examples/AutoResearch/AutoResearchParlioEncode.h:70-122
  • Production hot loop reference (per the mirror's own comment): src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp ≈line 981-994
  • The Bus::FLEX_IO runtime-selection rule that governs how AutoResearch should reach hardware: agents/docs/cpp-standards.md → "Runtime driver selection is Bus::FLEX_IO — legacy chipset templates are not (REQUIRED)"
  • Related meta: FastLED#3516 — I2S driver dev umbrella (called out during that session's harness drafting)

Blockers

None. Straightforward refactor.

Activity

  1. added
    type: bug
    priority: medium
    platform: esp32
    area: drivers
    on Jul 1, 2026
  2. added a commit that references this issue on Jul 1, 2026
  3. zackees commented on Jul 1, 2026

    @zackees
    MemberAuthor

    Retracted — my read was wrong

    On careful re-reading of `AutoResearchParlioEncode.h:73-122`, both `fl_parlio_inner_one_byte_position_bf1` and `fl_parlio_inner_four_byte_positions_bf1_pipe4` dispatch to the SHARED `fl::wave8Transpose_16_bf1` / `fl::wave8Transpose_16x4_bf1_pipe4` kernels — the exact same production kernels PARLIO's engine uses (`parlio_engine.cpp.hpp:1052-1067`).

    The "Mirror of the engine's clockless hot loop" comment (line 70-72) misled me — it's saying the WRAPPER shape mirrors production's (same input layout: scratch + lane_stride + byte_offset + lut), NOT that the transpose is duplicated. The transpose IS the production code. There's no drift risk because the bench and production share the same kernel — if production's kernel changes, the bench inherits the change automatically.

    The bench times:

    1. Array-into-locals gather from scratch (16 loads)
    2. Call into the shared transpose kernel
    3. XOR-checksum sink to prevent DCE

    That's exactly what production does. Measuring this IS measuring production's per-byte-position cost.

    Not cheating

    This isn't the facade pattern I described in the original issue text. Closing as won't-fix / retracted.

    Correction propagated: #3526 Phase 2a's "SHARED CODE ONLY" constraint (which I added citing this issue as the anti-drift ratchet) is still correct as a general rule — driver-specific work must reuse shared kernels — but the PARLIO bench is a compliant example of that rule, not a violation.

  4. moved this from Triage to Done in FastLED Trackeron Jul 1, 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: driversplatform: esp32priority: mediumtype: bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions