Skip to content

perf(parsing): isolate per-field helpers in NamedTupleParser, destructors, and flatten - #228

Open
clockblocker wants to merge 1 commit into
mainfrom
queue/perf-named-tuple-parser-isolation
Open

clockblocker wants to merge 1 commit into
mainfrom
queue/perf-named-tuple-parser-isolation

Conversation

@clockblocker

@clockblocker clockblocker commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

AI-authored below this line.

Related munich-data-engineering/reflect-cpp#795 · Related munich-data-engineering/reflect-cpp#799

Problem

Per-field write, schema, missing-field, and destructor helpers lived inside templates parameterized on the entire struct field pack.

An $N$-field struct therefore emitted $N$ symbols each repeating all $N$ field types, causing $O(N^2)$ object-size and compile-time blowup.

Before (O(N^2) symbol & DWARF growth):
  NamedTupleParser<..., F1, ..., FN>::write_field<i>    // N symbols × N-field pack each
  call_destructor_on_one_if_necessary<ViewType, N, i>   // instantiated even for int/double

After (O(N) isolated helpers, shared across structs):
  write_named_tuple_field<..., FieldType>               // keyed on 1 field type only
  destroy_field_if_set<FieldPtrType>                    // skipped for trivial fields

Summary

  • Lifts per-field write, schema, missing-field, and cleanup helpers into free templates keyed on a single field type, skips trivial destructors, and removes the per-index flatten helper.
  • Measured impact combined with effb0f7c and 32f5fcfb (3-run medians vs main, refl-cpp-workbench#34):
    • Debug .o size -15.0% (slang-server), -17.5% (moqx), and -27.1% (fanuc_driver).
    • Release .o size -19.4% (wolf) and compile wall time -4.4% to -9.9%.
For Agents

…tors, and flatten

Moves per-field serialization, schema building, missing-field handling, and
destructor helpers out of `NamedTupleParser<..., FieldTypes...>` into free
templates parameterized only on each field's type (never the enclosing
`NamedTuple` pack), and skips instantiating destructors for trivially
destructible fields/arrays. Eliminates O(N^2) symbol-table and DWARF growth on
wide structs with zero public API changes.

Split from parser-symbol-isolation (#118) into an independent, reviewable chunk
(no lookup algorithm changes; `to_default_generic` fast-path and `ViewReader`
isolation follow in separate commits).

Follow-up to: munich-data-engineering#795, munich-data-engineering#799
Downstream receipts (combined Wave 1 N=3 interleaved medians vs main):
- hudson-trading/slang-server (`SlangServer.cpp` Debug): -15.0% `.o` Clang, -9.6% GCC, -6.1% wall
- openmoq/moqx (`Loader.cpp` Debug): -17.5% `.o` Clang, -13.5% GCC, -4.4% wall
- FANUC-CORPORATION/fanuc_driver (`serialization.cpp` Debug): -27.1% `.o` Clang, -9.9% wall
- games-on-whales/wolf (`unix_socket_server.cpp` Release): -19.4% `.o` Clang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant