perf: type-bound member accessors and no bool boxing (~10-33% faster object rendering) - #652
Merged
Conversation
Plain-object descriptors are cached per type, but ReflectionMemberAccessor re-resolved its per-type accessor table on every member access via a type-keyed lookup. The descriptor's member accessor is now pre-bound to the described type, so the common case (instance type matches the descriptor) goes straight to the member-name lookup. Mismatched instance types fall back to the original shared path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Value-type properties returned through the cached Func<object, object>
getters box on every access. For bool properties — common in {{#if}}/
{{#unless}}-heavy templates — return the cached BoxedValues.True/False
instances instead of allocating a fresh box per read.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ssor Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
rexm
enabled auto-merge
August 5, 2026 03:45
|
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
Two targeted optimizations to the reflection-based member access path (the path used when rendering plain .NET objects, including anonymous types):
Type-bound member accessors.
ObjectDescriptors are already cached per type, but the sharedReflectionMemberAccessorre-resolved its per-type accessor table on every member access via a type-keyedLookupSlimlookup. The descriptor's member accessor is now pre-bound to the described type at descriptor creation, so the common case (instance type matches the descriptor) goes straight to the member-name lookup. If the instance type doesn't match the bound type, it falls back to the original shared path — behavior is unchanged.No boxing for
boolproperty reads. The cachedFunc<object, object>getters box value-type property values on every read.boolproperties — ubiquitous in{{#if}}/{{#unless}}-heavy templates — now return the cachedBoxedValues.True/Falseinstances instead of allocating a fresh box per read.Dictionary-based data paths are untouched. All 1837 tests pass.
Benchmarks
MediumRun (LaunchCount=1, 15 iterations), Apple M4, .NET 10. Baseline is master @ 37ca7b9.
Object-path suites (the target of this change):
Full suite (including neutral paths):
All 30 benchmark cases
Dictionary/expando cases and helper-dispatch (
Execution.*) benchmarks are neutral (within ±3% run-to-run noise), as expected — this change only affects the reflection member-access path.Remaining
RenderListallocations at larger N are iterator index boxing beyond theBoxedValuesint cache (0–19) — identical for object and dictionary data, and a possible follow-up.🤖 Generated with Claude Code