Skip to content

Generate accessors for custom TemplateContext models - #992

Merged
sebastienros merged 1 commit into
mainfrom
sebros/infer-context-model-accessors
Aug 21, 2026
Merged

Generate accessors for custom TemplateContext models#992
sebastienros merged 1 commit into
mainfrom
sebros/infer-context-model-accessors

Conversation

@sebastienros

Copy link
Copy Markdown
Owner

Motivation

Custom models passed to TemplateContext currently rely on runtime member discovery unless applications explicitly register every model type. This leaves performance on the table and makes the NativeAOT/trimming boundary harder to understand.

Approach

  • Infer concrete model types passed to new TemplateContext(model, customOptions) and generate direct per-member accessors for eligible public fields and properties.
  • Activate inferred accessors only for the matching runtime type and custom options instance. TemplateOptions.Default remains unchanged.
  • Preserve explicit registration precedence, custom value converters, async behavior, and reflection fallback semantics.
  • Add a thread-safe generated-accessor registry and cache invalidation for newly activated model types.
  • Document which generated, explicitly registered, and reflection-based patterns are compatible with NativeAOT and trimming.

Performance

The targeted custom-model rendering benchmark improved from 145.0 ns to 138.3 ns (4.6%) with allocations unchanged at 608 B. The standard rendering benchmark remained effectively unchanged at 16.373 us versus 16.356 us.

Validation

Both interpreted and compiled grammar test passes succeed with 2,790 passing tests and 20 existing skips in each mode.

Infer concrete model types passed to TemplateContext with custom options and activate direct source-generated member accessors while preserving explicit registrations and reflection fallback semantics. Document NativeAOT and trimming compatibility boundaries.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3d315571-9fc7-4662-bd2d-5d739ff55308
@sebastienros
sebastienros merged commit f35a692 into main Aug 21, 2026
3 checks passed
@sebastienros
sebastienros deleted the sebros/infer-context-model-accessors branch August 21, 2026 05:21
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