Skip to content

perf(schema): fast-path scalar defaults in NamedTupleParser::to_schema - #237

Open
clockblocker wants to merge 1 commit into
queue/perf-named-tuple-parser-isolationfrom
queue/perf-schema-scalar-defaults
Open

clockblocker wants to merge 1 commit into
queue/perf-named-tuple-parser-isolationfrom
queue/perf-schema-scalar-defaults

Conversation

@clockblocker

@clockblocker clockblocker commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

AI-authored below this line.

Related munich-data-engineering/reflect-cpp#641

Stacked on: #228 (queue/perf-named-tuple-parser-isolation)

Problem

Every rfl::DefaultVal<T> field in a schema-generating struct instantiated the full rfl::to_generic and rfl::generic::Writer pipeline.

That pulled in heavy template instantiations just to convert trivial scalar defaults into rfl::Generic.

struct Config {
  rfl::DefaultVal<bool> enabled = true;
  rfl::DefaultVal<int> retries = 3;
  rfl::DefaultVal<std::optional<double>> timeout = 1.5;
  rfl::DefaultVal<std::string> host = "localhost";
};
// Before: instantiates rfl::to_generic<ProcessorsType> + generic::Writer per field
// After:  constructs rfl::Generic directly for scalars and std::optional<Scalar>

Summary

  • Fast-paths bool, plain integers, floating-point types, std::string, and std::optional wrappers around them while matching rfl::generic::Writer semantics.
  • Falls back to rfl::to_generic for composite or custom defaults (structs, vectors, maps) with identical schema output.
For Agents

Adds `rfl::parsing::to_default_generic` so scalar and `std::optional<scalar>`
default values (`bool`, plain integers, floating-point, `std::string`) construct
`rfl::Generic` directly during JSON Schema emission instead of instantiating
`rfl::to_generic<ProcessorsType>` / `rfl::generic::Writer`, while keeping
complex types on `rfl::to_generic` with identical semantics.

Parent: depends on `perf(parsing): isolate per-field helpers in NamedTupleParser,
destructors, and flatten` for `build_named_tuple_field_schema`.

Judge polish applied:
- Drops the consumer-specific `std::vector<std::string>` special case (falls
  back cleanly to `rfl::to_generic`) and documents parity with
  `rfl::generic::Writer::to_generic`.
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