Skip to content

perf(parsing): add DirectStructParser bypassing NamedTuple/Tuple for plain aggregates - #124

Open
clockblocker wants to merge 3 commits into
feat-rfl-metadatafrom
perf-direct-struct-parser
Open

clockblocker wants to merge 3 commits into
feat-rfl-metadatafrom
perf-direct-struct-parser

Conversation

@clockblocker

Copy link
Copy Markdown
Owner

Summary

Stacked on #118 (perf-parser-symbol-isolation) -> #119 (feat-rfl-metadata).

Adds Tier 2 DirectStructParser (include/rfl/parsing/DirectStructParser.hpp) + value-level DirectFieldNames<T> (include/rfl/internal/DirectFieldNames.hpp) so eligible plain aggregate structs bypass rfl::NamedTuple<Field<Literal<...>, T>...>, rfl::Tuple<...>, rfl::ViewReader*, and NamedTupleParser completely during read, write, and to_schema — with zero public API changes.

Key Architectural Changes

  • Value-level field name table (DirectFieldNames<T>): Extracts field names directly via internal::get_field_names<T> into a compact constexpr string buffer + std::array<std::string_view, N> (no rfl::Literal<...> type lists or rfl::Field<...> wrapper packs).
  • Direct field address binding (internal::apply_to_fields + FieldAddrCollector): Binds struct members via std::addressof into a flat void* / const void* pointer array without instantiating rfl::Tuple<Field0*, ..., FieldN-1*> or variadic generic lambdas.
  • Type-erased per-field function-pointer descriptors (DirectFieldDesc): One tiny DirectStructParser descriptor table per struct with non-T, non-N runtime drivers (DirectStructViewReader, run_direct_read, run_direct_write, run_direct_to_schema, DirectDestroyGuard).
  • Fail-closed eligibility (can_use_direct_struct_parser_v<T, ProcessorsType, R>): Activates for plain aggregates with identity/builtin processors (excluding Flatten, ExtraFields, non-identity name-transform/custom processors, rfl::env::Reader, and schemaful/positional readers that require static ViewType::size() or is_view_reader_v). Preserves rfl::DefaultVal, rfl::Skip, rfl::Rename, rfl::Attribute, rfl::Validator, rfl::Metadata<T>, DefaultIfMissing, NoExtraFields, NoOptionals, NoFieldNames, AllOf/FailFast, const fields, move-only types, and C-arrays (REFLECT_CPP_C_ARRAYS_OR_INHERITANCE).

Benchmarks (AppleClang 17 arm64, uncontended CPU)

1. Real-World Production Guinea Pig: upstream slang-server (1b413a4, -O2 -g, no PCH, zero source changes)

Translation Unit Wall (#118+#119 -> Tier 2) .o Size __text Mangled Bytes Max Symbol NamedTuple Syms
SlangServer.cpp 30.08s -> 21.98s (-26.9%) 53.58 -> 37.78 MiB (-29.5%) 0.914 -> 0.667 MiB (-27.0%) 1.11 -> 0.83 MiB 8,330 -> 1,790 403 -> 0
Config.cpp 4.19s -> 3.66s (-12.6%) 10.89 -> 6.54 MiB (-39.9%) 0.115 -> 0.113 MiB 0.35 -> 0.18 MiB (-48.6%) 13,322 -> 1,790 38 -> 0
gen_config_main.cpp 3.33s -> 3.04s (-8.7%) 9.14 -> 5.91 MiB (-35.3%) 0.096 -> 0.093 MiB 0.25 -> 0.19 MiB 13,357 -> 1,806 10 -> 0
  • gen_config_schema JSON output parity: 8,904 bytes vs 8,904 bytes (100% byte-identical).

2. Synthetic 48-Field ConfigData Benchmark (bench_48_*, stacked on #118+#119)

Target (Config) Wall (#118+#119 -> Tier 2) .o Size Mangled Bytes Max Symbol NamedTuple Syms
bench_48_plain (-O0 -g) 2.06s -> 1.61s (-21.8%) 9.04 -> 3.00 MiB (-66.8%) (vs pre-#118 19.12 MiB: -84.3%) 2.13 -> 0.52 MiB (-75.6%) 6,084 -> 705 (-88.4%) 225 -> 0
bench_48_metadata (-O0 -g) 2.02s -> 1.61s (-20.3%) 9.06 -> 3.02 MiB (-66.7%) 2.13 -> 0.52 MiB (-75.6%) 6,084 -> 705 (-88.4%) 225 -> 0
bench_48_desc (-O0 -g) 3.64s -> 2.35s (-35.4%) 93.36 -> 11.37 MiB (-87.8%) (vs pre-#118 148.71 MiB: -92.4% / 13.1x) 38.31 -> 2.34 MiB (-93.9%) 38,866 -> 1,171 (-97.0%) 319 -> 0
bench_48_plain (-O2 -g) 2.77s -> 2.31s (-16.6%) 4.21 -> 2.24 MiB (-46.8%) 0.13 -> 0.06 MiB 6,084 -> 629 7 -> 0
bench_48_metadata (-O2 -g) 2.77s -> 2.28s (-17.7%) 4.23 -> 2.27 MiB (-46.3%) 0.13 -> 0.06 MiB 6,084 -> 629 7 -> 0
bench_48_desc (-O2 -g) 5.36s -> 4.15s (-22.6%) 20.18 -> 9.68 MiB (-52.0%) — 38,866 -> 1,171 (-97.0%) 6 -> 0
  • Runtime throughput (bench_48_plain, 50k iters, -O2): read 97.6-98.7ms vs 105.0-106.2ms (~1.3 ns/field for indirect dispatch); read_default 100.9-103.2ms vs 102.7-104.6ms; write 60.4-61.4ms vs 65.5-66.7ms.

Verification

  • Standalone header compilation: All new/modified headers compile standalone with -std=gnu++20 -Wall -Wextra -Werror (Parser_default.hpp with -Wall -Werror).
  • Full CMake build (REFLECTCPP_STRICT_WARNINGS=ON): 401/401 targets, 0 warnings.
  • Full CTest suite (json, json_c_arrays_and_inheritance, generic, cli, env, xml): 680/680 passed (100%).
  • UBSan (-fsanitize=undefined -fno-sanitize-recover=all): test_direct_struct_parser (6/6) and test_direct_struct_c_arrays (1/1, including std::string[2] partial-construction cleanup) pass cleanly.
  • Independent Dual-Judge Reviews: Passed Round 1 (REQUEST CHANGES -> all 7 blockers and 11 nits resolved) and Round 2 (APPROVE WITH NITS from both Correctness/UB and Architecture/Perf Judges; remaining non-blocking nits also polished).

…Collector, found_count fast path, noexcept read_with_default, deduplicated readers, expanded tests)
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