Repository navigation
perf(tuple): single-pass O(N) tuple_cat, move_from_tuple fast path, wrap_in_fields, and concat_literals - #255
Open
clockblocker wants to merge 1 commit into
Open
clockblocker wants to merge 1 commit into
clockblocker wants to merge 1 commit into
Conversation
…rap_in_fields, and concat_literals
Replace quadratic/cubic compile-time and runtime folds across tuple
concatenation, tuple-to-struct reconstruction, field wrapping, and
compile-time literal concatenation with single-pass O(N) algorithms:
- `internal/tuple/concat.hpp`: replace the left-fold of pairwise
`concat_two` calls (Theta(N^3) compile-time, Theta(N^2) runtime moves)
with a consteval `(outer, inner)` index table and flat indexed
reference table (`TupleRefs`), constructing the result `rfl::Tuple` in
one pack expansion with zero intermediate tuples and strictly one
move (rvalue) or one copy (all-lvalue) per element. Qualify internal
helper calls (`rfl::internal::tuple::get_ref`, `extract_concat_element`,
`concat_impl`) to prevent C++20 ADL hijacking by user element
namespaces. Also fixes the latent `const Head&` overload bug that
previously returned `TupleWrapper` instead of `rfl::Tuple`, and
handles 0/1/empty/mixed lvalue+rvalue/move-only tuples cleanly.
- `internal/move_from_tuple.hpp`: guard `unflatten_ptr_tuple` with
`has_flatten_fields<ptr_tuple_t<T>>()` and `flatten_c_arrays` with
`has_arrays<TupleType>()`, fast-pathing plain structs directly into
aggregate initialization `T{std::move(rfl::get<I>(_t))...}` without
pointer tuples or `tuple_cat`. Replace the O(N^2) `IndptrHelper` fold
with a consteval prefix-sum `std::array`, fix nested `rfl::Flatten`
pointer unwrapping in `calc_flattened_size`, and recurse
`flatten_c_arrays` into nested `rfl::Flatten` pointer tuples (covering
C-style arrays inside `rfl::Flatten` and C-arrays declared after
`rfl::Flatten`; note that the pre-existing `move_from_pointers`
limitation remains when a C-array precedes an `rfl::Flatten` field in
the same struct, as expanding a preceding C-array shifts indices in
`Pointers` relative to `ptr_tuple_t<T>`).
- `internal/wrap_in_fields.hpp` + `internal/calc_flattened_size.hpp`:
replace recursive parameter-pack peeling and `flattened_ptr_tuple_t`
materialization with a consteval `name_offsets` array and a single
non-recursive `index_sequence` expansion.
- `internal/concat_literals.hpp`: preserve the 0/1/all-single fast paths
and replace the general left-fold (which instantiated O(N)
intermediate `rfl::Literal` types with O(N^2) NTTP args on structs
containing `rfl::Flatten`) with a single-pass `(outer, inner)` index
table over flat `LiteralTypeTable` base packs, with qualified
`rfl::internal::get_indexed_literal_type` lookups to prevent ADL
hijacking.
Verified standalone header self-containment (20/20 passed, standard and
`-DREFLECT_CPP_C_ARRAYS_OR_INHERITANCE`) and full CTest suite on both
Clang 23.1.6 and GCC 13.4.0 with `-DREFLECTCPP_STRICT_WARNINGS=ON`
(0 warnings, 782 passed / 1 expected locale skip out of 783).
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.
Related munich-data-engineering/reflect-cpp#795
Problem
rfl::tuple_cat,wrap_in_fields, andconcat_literalsrely on recursiveMeanwhile,
move_from_tuplenever wired the plain-struct fast path imported in upstream PR #795.Summary
move_from_tuple.-O3(refl-cpp-workbench#33).tuple_catand C-arrays inside or afterrfl::Flatten.OSS consumers
munich-data-engineering/sqlgensqlgenrfl::Flattenandtuple_catquery builders.games-on-whales/wolfwolfFor Agents
upstream-queue(7c449ff1) · Score68/100(S=17,M=21,D=20,R=10) ·+388/-160(5f)queue-tests/generic/test_tuple_cat.cpp,queue-tests/json_c_arrays_and_inheritance/test_c_array_flatten.cpp