Repository navigation
perf(named-tuple): O(1)-instantiation find_index, non-recursive find_extra_fields, and fold-based struct traits - #239
Open
clockblocker wants to merge 1 commit into
Conversation
This was referenced Dec 2, 2026
…extra_fields, and fold-based struct traits
Eliminate superlinear template instantiation chains across NamedTuple and struct/tuple trait helpers:
- find_index.hpp: replace FieldWrapper + operator| fold chains (O(N^2) Clang / O(N^3) GCC-MSVC) with a single FindIndexImpl specialization per tuple type that scans constexpr std::array<std::string_view, N> in a consteval loop. Preserves first-match semantics, empty-tuple handling, std::tuple support, and the exact static_assert diagnostic.
- NamedTuple.hpp: replace the eagerly evaluated O(N)-depth recursive find_extra_fields<>() with a non-recursive consteval loop returning -2 on a second match plus static_assert(pos_extra_fields_ != -2, ...) for the exact duplicate-ExtraFields error. Simplify both make_fields overloads to expand FieldTypes... directly with _is..., removing per-field wrap lambdas and nth_element_t lookups.
- has_fields.hpp: inspect member types in a single pass via rfl::internal::apply_to_fields and fold expressions (with a zero-flatten fast path) instead of materializing ptr_tuple_t<T> (rfl::Tuple + calculate_positions), preserving exact semantics for NamedTuple (including empty NamedTuple<> inside rfl::Flatten via `flags{sizeof...(Fields) > 0, true}`), Flatten, raw pointer members, empty structs, non-aggregates, C arrays, inheritance, and mixed-annotation diagnostics.
- has_flatten_fields.hpp & has_arrays.hpp: pattern-match rfl::Tuple<Ts...> and std::tuple<Ts...> directly with fold expressions, eliminating integer_sequence, per-element lambdas, and nth_element_t.
- is_empty.hpp: check rfl::num_fields<U> == 0 (after stripping cvref/pointers and handling NamedTuple/Tuple directly) instead of materializing ptr_tuple_t<U>.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Core$O(N^2)$ –$O(N^3)$ operator-fold chains, recursive extra-field scans, and eager
rfl::NamedTuplelookup and struct traits expandedptr_tuple_tmaterializations.On wide aggregates, that template explosion drove significant compile latency and peak RSS across downstream builds.
Summary
constevalloops and fold expressions built onapply_to_fields.static_assertdiagnostics, fixes empty-tuplefind_index, and keeps exact emptyFlatten<NamedTuple<>>, C-array, and inheritance semantics.cuda-quantum: -9.5% wall time, -8.6% peak RSS.sqlgen: -7.5% wall time, -3.4%.osize.fanuc-libs: -4.4% wall time, -4.3% peak RSS.OSS consumers
munich-data-engineering/sqlgensqlgen.osize on wide SQL schemas.NVIDIA/cuda-quantumcuda-quantumFANUC-CORPORATION/fanuc_driverfanuc_driverFor Agents
upstream-queue(732e0f98) · Score82/100(S=26,M=25,D=21,R=10) ·+218/-141(6f)queue-tests/json/test_named_tuple_traits.cpp,queue-tests/json_c_arrays_and_inheritance/test_c_array_and_inheritance_traits.cpp