Skip to content

Use cached reflection invokers in no-emit accessors - #479

Merged
eiriktsarpalis merged 3 commits into
mainfrom
eiriktsarpalis-optimize-member-accessors
Jul 21, 2026
Merged

Use cached reflection invokers in no-emit accessors#479
eiriktsarpalis merged 3 commits into
mainfrom
eiriktsarpalis-optimize-member-accessors

Conversation

@eiriktsarpalis

Copy link
Copy Markdown
Owner

Apply the MethodInvoker and ConstructorInvoker pattern from dotnet/runtime#131018 to PolyType's no-emit reflection member accessor on .NET 8 and later. Invokers are cached when accessors are created for methods, constructors, events, collection factories and appenders, nested tuple getters, member initializers, and F# functions. net472 and netstandard2.0 retain the existing reflection fallback.

Ordinary property getters and setters already use typed delegates and remain unchanged. Value-type targets continue to be boxed and copied back where mutation is observable.

MethodInvokeBenchmarks.MethodShapeReflection on .NET 10 improved from 142.7 ns to 131.1 ns for six arguments (about 8%); allocations remained at 272 B.

make test passed with 289,687 CLR tests and 29 Native AOT tests.

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

Copilot-Session: 2bac0ef2-0b37-41bc-991c-9d7181fb1e21
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2bac0ef2-0b37-41bc-991c-9d7181fb1e21
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2bac0ef2-0b37-41bc-991c-9d7181fb1e21
@eiriktsarpalis
eiriktsarpalis merged commit 5042929 into main Jul 21, 2026
7 checks passed
@eiriktsarpalis
eiriktsarpalis deleted the eiriktsarpalis-optimize-member-accessors branch July 21, 2026 15:24
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