Repository navigation
perf(parsing): O(log K) lookup and symbol isolation for FieldVariantReader, FieldVariantParser, and ParserTaggedUnion - #250
Open
clockblocker wants to merge 1 commit into
Conversation
…eader, FieldVariantParser, and ParserTaggedUnion Eliminates O(K) non-short-circuiting linear scans, O(K^2) member/lambda symbol instantiations, and `define_literal` O(K^2) template peeling across externally tagged (`FieldVariantReader`/`FieldVariantParser`) and internally tagged (`ParserTaggedUnion`) union parsers: - `find_field_index.hpp`: adds `find_in_field_name_table` (linear scan with `field_name_equals` for <= 8 entries, binary search for > 8) and non-cold `FieldNameLookup::find_direct` while keeping `FieldNameLookup::find` marked `RFL_COLD` for `ViewReader`'s out-of-order fallback. - `FieldVariantReader.hpp` & `FieldVariantParser.hpp`: dispatches field names via `FieldNameLookup::find_direct` in O(log K), short-circuits via `||` fold over lockstep `(_is, FieldTypes)...`, and isolates per-alternative read, write (`FieldVariantWriter`), and schema (`field_variant_alternative_to_schema`) helpers at namespace scope without repeating `FieldTypes...`. Preserves exact duplicate/unknown/empty error messages and nested `Error::details()` paths. - `ParserTaggedUnion.hpp`: adds `TaggedUnionTagLookup` built directly from `internal::tag_t<_discriminator, AlternativeTypes>...` (supporting single- and multi-value `rfl::Literal` tags), checks duplicate tags on the constexpr-sorted table in O(M) without `define_literal` peeling, looks up discriminators in O(log M), and isolates discriminator extraction, read, write (`TaggedUnionWriter`), and schema helpers at namespace scope. Preserves zero-copy writing when the discriminator is already a struct field, declaration-order allowed-tag lists, `NoFieldNames` handling, and nested `Error::details()` paths. - `tests/json/test_tagged_and_field_variant_dispatch.cpp`: adds focused correctness and scale tests for 24-alternative `TaggedUnion` (including multi-value `rfl::Literal` tags, `NoFieldNames`, `Error::details()`, and schema) and 24-alternative `FieldVariantReader`/`FieldVariantParser`. Verified: - Standalone self-containment checks on all 4 touched headers on Clang 23.1.6 and GCC 13.4.0 (`-std=c++20 -Wall -Wextra -Wextra-semi -Werror`, default and `-DREFLECTCPP_C_ARRAYS_OR_INHERITANCE`). - `tests/json/test_tagged_and_field_variant_dispatch.cpp` compiled with `-std=c++20 -O2 -Wall -Wextra -Wextra-semi -Werror` and passed (2/2 tests) on both Clang 23.1.6 and GCC 13.4.0.
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
Field-variant and tagged-union parsers scan all$K$ alternatives linearly on every read.
They also check duplicate tags via$O(K^2)$ $O(K^2)$ member symbols repeating the full alternative pack.
define_literalpeeling and emitSummary
FieldNameLookup/TaggedUnionTagLookup) and free per-alternative helpers.-O3, refl-cpp-workbench#33):TaggedUnionread 3.31x faster; 32-alt 1.62x–1.67x faster.o, -39.0% symbol bytes (-11.7%.ooncuda-quantum)Error::details()paths, no-field-name handling, multi-value tags, and zero-copy tag writes.OSS consumers
NVIDIA/cuda-quantumTargetConfigYamlAdapters.h#L27-L75.o(-11.7%) and symbols (-12.5%) on target unions.games-on-whales/wolfpartials/spec.json#L939-L948TaggedUnionparser symbols on REST handlers.For Agents
upstream-queue(0576c04b) · Score76/100(S=19,M=25,D=21,R=11) ·+537/-265(4f)#231,#247queue-tests/json/test_tagged_and_field_variant_dispatch.cpp