Repository navigation
feat(schema): add opt-in zero-bloat rfl::Metadata<T> for out-of-band field/struct documentation - #119
Open
clockblocker wants to merge 3 commits into
Open
clockblocker wants to merge 3 commits into
clockblocker wants to merge 3 commits into
Conversation
…field/struct documentation
…tadata, empty Deprecated description, Cap'n Proto literal unwrap) and nits
… alternative has no description
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
Stacked on PR #118 (
perf-parser-symbol-isolation, follow-up to munich-data-engineering#795 & munich-data-engineering#799).Motivation (real-world adoption context)
While prototyping a
reflect-cppmigration ofccache's 48-fieldConfigDatastruct usingrfl::Description<StringLiteral, rfl::DefaultVal<T>>field wrappers, Debug.osizes exploded to 118.98 MiB (65.17 MiB__debug_str+ 52.2 MiB mangled symbol names) andRelWithDebInfo.osizes reached 34.73 MiB (~5.5 s/TU). Even with PR #118's internal symbol isolation, embedding long documentation prose asStringLiteralnon-type template parameters inside every field's C++ type permanently bloatsNamedTuple<FieldTypes...>manglings, DWARF debug info, and compile times (and requires modifying the struct's C++ member types). Similar large-struct pressure appeared inslang-server,transmission(81-fieldTorrentInfo/ 53-fieldSessionSetParams), andosmium-tool.What this PR adds
Opt-in, zero-bloat out-of-band metadata via
rfl::Metadata<T>(include/rfl/Metadata.hpp, included byinclude/rfl.hpp):read/write/ struct layout:rfl::Metadata<T>is consulted only duringto_schema()— field types stay plain C++ types with zeroStringLiteralNTTP bloat.fieldscan be astatic constexprcontiguous sized range (std::array,std::span, C array) or astaticfunctionfields()returning a borrowed contiguous sized range (e.g.,std::span<const rfl::FieldMeta>orconst auto&— allowing definitions to live out-of-line in a.cppfile; by-value containers that would dangle are rejected at compile time viastatic_assert). Optional struct-leveldescriptionalso supports both variable and function forms.rfl::SnakeCaseToCamelCase,rfl::Rename,rfl::AddStructName,rfl::Flatten,rfl::NoFieldNames,rfl::DefaultVal).rfl::TaggedUnioninternal wrappers (TaggedUnionWrapperWithFields/TaggedUnionWrapperNoFields) sorfl::Metadata<Alternative>works seamlessly on tagged union alternatives.Metadata<T>::descriptiononReflectionType/Reflector<T>types as well as aggregate structs.src/rfl/json/to_schema.cpp:Type::Deprecatednow setsannotations.descriptiononly when non-empty (preserving an inner inlinerfl::Descriptionwhen out-of-bandFieldMetaadds onlydeprecation_message, and omitting"description"rather than emitting"description":""when empty).src/rfl/avro/to_schema.cpp,include/rfl/capnproto/is_named_type.hpp, andsrc/rfl/capnproto/to_schema.cpp: recursively unwrapType::DescriptionandType::Deprecatedinis_named_typeand Cap'n Protois_literal_type.Benchmark (48-field
ConfigDatawith 48 full-sentence field descriptions, AppleClang 17 arm64, median of 3 runs).osize__text__debug_str-O0 -g) —origin/main(290bdb24), inlinerfl::Description-O0 -g) — PR 1 (perf-parser-symbol-isolation), inlinerfl::Description-O0 -g) — PR 2 (rfl::Metadata<T>)-O0 -g) — control: 48-field plain struct on PR 1 (no descriptions)-O2 -g) —origin/main(290bdb24), inlinerfl::Description-O2 -g) — PR 1 (perf-parser-symbol-isolation), inlinerfl::Description-O2 -g) — PR 2 (rfl::Metadata<T>)-O2 -g) — control: 48-field plain struct on PR 1 (no descriptions)Adding all 48 full-sentence field descriptions via
rfl::Metadata<T>adds only +73 KiB (+0.8%) in Debug and +81 KiB (+1.9%) in RelWithDebInfo over an undescribed plain struct.Testing
generic,json,json_c_arrays_and_inheritance,cli,env,xml): 673/673 passed under AppleClang 17-Wall -Werror+REFLECTCPP_STRICT_WARNINGS=ON.rfl/Metadata.hpp,rfl/parsing/NamedTupleParser.hpp,rfl/parsing/tagged_union_wrapper_no_ptr.hpp,rfl/parsing/Parser_default.hpp, andrfl/capnproto/is_named_type.hpp.tests/json/test_metadata.cppandtests/json_c_arrays_and_inheritance/test_c_array_schema_defaults.cppcovering parity with inlineDescription/Deprecated,DefaultVal, runtimefields()/description(),SnakeCaseToCamelCase,Rename,AddStructName, wire-name precedence, inline-description preservation, plain deprecation omitting empty"description",TaggedUnionalternatives,Flatten, empty structs,NoFieldNames,ReflectionType, C-arrays, and conceptstatic_asserts.