Skip to content

perf(parsing): peel transparent metadata wrappers before Parser read, write, and to_schema - #260

Open
clockblocker wants to merge 1 commit into
queue/perf-view-reader-isolationfrom
queue/perf-peel-transparent-wrappers
Open

clockblocker wants to merge 1 commit into
queue/perf-view-reader-isolationfrom
queue/perf-peel-transparent-wrappers

Conversation

@clockblocker

@clockblocker clockblocker commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

AI-authored below this line.

Stacked on: #234 (queue/perf-view-reader-isolation)

Problem

Every distinct string literal inside rfl::Description<"...", T>, rfl::Deprecated<"...", "...", T>, rfl::Rename<"...", T>, or rfl::Short<"...", T> creates a unique C++ type. ViewReader, ViewReaderWithDefault, and NamedTupleParser pass that still-wrapped type straight into Parser<R, W, WrappedT, ProcessorsType>::{read, write, to_schema}, multiplying full parser, rfl::Result<WrappedT>, and schema template instantiations across every documented or renamed field—and baking the description strings into mangled symbols and DWARF debug info.

// Before (N distinct documentation strings -> N separate Parser::read/write/to_schema instantiations):
struct Config {
  rfl::Description<"Max worker threads", int> threads;   // Parser<..., Description<"Max worker...", int>>
  rfl::Description<"RPC timeout in ms", int> timeout_ms; // Parser<..., Description<"RPC timeout...", int>>
};

// After (metadata peeled at the field boundary -> 1 shared Parser<..., int> instantiation):
// - read:      parses CoreType (int), then wraps into Description/Deprecated/Rename/Short at slot assignment
// - write:     unwraps to const CoreType& before calling Parser<..., CoreType>::write
// - to_schema: builds CoreType schema once, then attaches runtime Type::Description / Type::Deprecated nodes
  • Measured impact (N=3 strictly interleaved vs. 23146188, Linux Clang 23.1.6 & GCC 13.4.0, ccache off — refl-cpp-workbench#45):
    • openmoq/moqx (184 wrapper sites): Loader.cpp .o -23.2% (6.51 → 5.00 MB), wall -12.7%, peak RSS -11.0%; full cold project build -6.8% (328.7 → 306.5 s, total .o -1.4 MiB).
    • hudson-trading/slang-server (29 wrapper sites, PCH-free): Config.cpp .o -20.7% (994 → 788 KB), .text -17.5%, wall -16.5%, wrapper-named symbols -53.1% (207 → 97).
    • 64-field wrapped config stress (read + DefaultIfMissing + write + to_schema):
      • Clang 23 Release: wall -22.8%, RSS -12.5%, .o -44.0%, .text -51.1%, wrapper symbols -66.2%.
      • Clang 23 Debug (-O0 -g): wall -36.2%, RSS -11.0%, .o -9.3% (-10.5 MB), .text -36.4%.
      • GCC 13 Release: wall -22.3%, RSS -18.3%, .o -40.2%, .text -52.4%, wrapper symbols -67.5%.

Summary

  • Adds include/rfl/parsing/peel_transparent_wrappers.hpp to recursively peel rfl::Description, rfl::Deprecated, rfl::Rename, and rfl::Short at compile time while stopping at semantic boundaries (rfl::DefaultVal, rfl::Skip, rfl::Attribute, rfl::ExtraFields, rfl::Validator, raw pointers, C-arrays, references, const/volatile inner types, rfl::Reflector<Outer>, and R::has_custom_constructor<Outer>).
  • Wires peeling into the existing ViewReader, ViewReaderWithDefault, and NamedTupleParser (read, write, and to_schema) with zero parallel engine, zero public API change, and MSVC /W4 /WX (C4714/C4100/C4127) + Clang 15 constexpr guards.
  • Note: assumes no user specializes internal rfl::parsing::Parser directly on Description/Deprecated/Rename/Short (public rfl::Reflector<Outer> and R::has_custom_constructor<Outer> remain respected).
Consumer Location Pain point solved
openmoq/moqx src/config/Loader.cpp 184 Description/Deprecated/Rename config sites caused 6.51 MB Loader.cpp.o (-23.2% .o, -12.7% wall after peeling).
hudson-trading/slang-server include/Config.h#L35-L170 29 documented/deprecated server config fields multiplied Parser symbols (-20.7% .o, -16.5% wall, -53.1% wrapper symbols).
For Agents
  • Queue placement: Rank 41 in upstream-queue (0bca6f0f) · Score 82/100 (S=21, M=25, D=24, R=12) · +495/-26 (4f)
  • Stacking note: + #228, #257
  • Standalone regression tests: queue-tests/json/test_peel_transparent_wrappers.cpp
  • Verification: CHECK_HEADERS 24/24 PASS (-Wall -Wextra -Wextra-semi -Wsign-conversion -Wpedantic -Werror, Clang 23 & GCC 13 across C++20/23 & C-arrays); queue-tests/ 234/234 PASS across all 12 formats on Clang 23 & GCC 13; ASan+UBSan 5/5 PASS (0 errors/leaks); upstream CI 673/673 PASS (Clang 23 JSON+YAML, 0 warnings).
  • Benchmarks (refl-cpp-workbench#45, N=3 interleaved): moqx Loader.cpp -23.2% .o / -12.7% wall / -11.0% RSS (-6.8% full build); slang-server Config.cpp -20.7% .o / -17.5% .text / -16.5% wall / -53.1% wrapper symbols; 64-field wrapped stress -44.0% .o & -51.1% .text (Clang 23), -52.4% .text (GCC 13), -36.2% wall & -10.5 MB .o (Clang 23 Debug).
  • Portability: Uses RFL_PEEL_ALWAYS_INLINE (inline on MSVC, RFL_ALWAYS_INLINE on GCC/Clang) to prevent MSVC /W4 /WX C4714, suppresses discarded-branch C4100, guards schema_meta_count > 0 (no std::array<..., 0> / C4127), and uses constexpr + static constexpr .rodata for older Clang compatibility.

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