Repository navigation
Avoid O(N^2) template instantiations in no_duplicate_field_names - #799
Merged
liuzicheng1987 merged 1 commit intoNov 27, 2026
Conversation
Collaborator
|
@clockblocker, this is an excellent contribution! Thank you very much! I am merging. |
liuzicheng1987
merged commit Nov 27, 2026
de5bd9f
into
munich-data-engineering:main
176 checks passed
This was referenced Nov 27, 2026
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.
Summary
Addresses #350 (eliminates the recursive template instantiations that trigger MSVC
C1202on large field counts).Replaces the$O(N^2)$ recursive template expansion in
rfl::internal::no_duplicate_field_names(iterate_over_i→iterate_over_j→compare_two_fields<Fields, _i, _j>) with a singleconstexprsort-and-scan overstd::array<std::string_view, N>.For an 80-field tuple or$\binom{80}{2} = 3{,}160$
rfl::Literal, the previous implementation instantiatedcompare_two_fieldsfunction templates per type.Compile-time benchmark
Single TU with one 80-field
rfl::Tuple<rfl::Field<...>...>and one 80-entryrfl::Literal<...>(-std=c++20 -fsyntax-only):main)Key details
constexprShell sort overstd::array<std::string_view, N>(no<algorithm>dependency) and evaluates intoconstexpr bool resultso nostd::string_viewarray escapes the lambda.falsewhen duplicates exist instead of firing an internalstatic_assertand always returningtrue:rfl::Literal<...>::has_duplicates()now works as aconstexpr boolpredicate (returningtrueon duplicates instead of failing to compile).to_ptr_named_tuple.hpp,FieldVariantParser.hpp,ParserTaggedUnion.hpp) all wrap the check in their ownstatic_assertand now report their own domain-specific messages.json.test_literal_has_duplicatesintests/json/test_literal.cppcovering unique/duplicaterfl::Literal(up to 32 entries) andrfl::internal::no_duplicate_field_nameson empty, single, distinct, and duplicaterfl::Fieldtuples.AI-authored.