Skip to content

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
perf-parser-symbol-isolationfrom
feat-rfl-metadata
Open

clockblocker wants to merge 3 commits into
perf-parser-symbol-isolationfrom
feat-rfl-metadata

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Stacked on #118. Adds opt-in out-of-band struct and field metadata via rfl::Metadata<T> so large structs can attach JSON Schema descriptions and deprecation notices without embedding long StringLiteral template arguments into every field's C++ type.

Example

struct ConfigData {
  std::string cache_dir = "/var/cache/app";
  int max_files = 100;
  bool legacy_gzip = false;
};

template <>
struct rfl::Metadata<ConfigData> {
  static constexpr std::string_view description = "Cache configuration";
  static constexpr std::array<rfl::FieldMeta, 3> fields = {{
      {"cache_dir", "Root cache directory"},
      {"max_files", "Maximum number of cached files"},
      {"legacy_gzip", "Legacy compression flag", "Use compression_codec instead"},
  }};
};

Compile-time & binary impact

48-field ConfigData with 48 full-sentence field descriptions (AppleClang 17 arm64):

Variant (-O0 -g Debug) Wall time .o size Symbol-name bytes
main (inline rfl::Description) 3.93 s 118.98 MiB 52.21 MiB
#118 (inline rfl::Description) 3.60 s 93.30 MiB 39.23 MiB
This PR (rfl::Metadata<T>) 2.02 s (-48.6%) 9.07 MiB (-92.4%) 2.18 MiB (-95.8%)

Key details

  • Consulted only during to_schema() — zero impact on struct layout, read, or write.
  • fields and description accept either static constexpr values or static functions returning borrowed views (so definitions can live out-of-line in a .cpp; dangling by-value containers are rejected via static_assert).
  • Matches processed wire field names first, then pre-processor C++ names (SnakeCaseToCamelCase, Rename, Flatten, TaggedUnion alternatives, and Reflector<T> types).
  • Fixes Type::Deprecated in JSON Schema so empty deprecation descriptions don't overwrite inner rfl::Description or emit "description": "", and unwraps Description/Deprecated cleanly in Avro and Cap'n Proto schema emitters.

AI-authored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant