Tracking issue for reflection invoke perf improvements
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 18/100
Research direction
Start by reviewing the partial reference implementation in PR 109901 and the remaining unchecked work items, including the CoreCLR interpreted-invoke removal and possible Mono calli support. The completed PRs linked in the issue provide context, but this tracking issue does not define a single entry point or completion criterion for the remaining design work.
Written by the indexing model from the issue text.
Description
This covers work items to address various reflection invoke benefits:
- Faster startup and warmup of applications by avoiding IL Emit for common signatures.
- Removal of C++ code from the runtime that handles the "interpreted invoke".
See the PR https://github.com/dotnet/runtime/pull/109901 for a partial reference implementation.
- Modify or remove existing tests that are too dependent on the current implementation's idiosyncrasies. See https://github.com/dotnet/runtime/pull/113000
- Collect statistics from applications to determine when reflection is used during startup so we know what signatures to address ahead-of-time. Currently, only a simple "hello world" console application has been used. Done - see "Signatures to pre-generate" below.
- Support the ExplicitThis calling convention for use with instance-based function pointers. See https://github.com/dotnet/runtime/pull/113666
- Add internal runtime support for calling a function pointer on an instance. Currently, function pointers in C# can only be called on static methods. This is key to share signatures across compatible method signatures. See https://github.com/dotnet/runtime/pull/114495
- Add the main feature leveraging the above.
- For CoreClr, remove the C++ "interpreted invoke" code from the runtime along with the
ForceEmitInvokeandForceInterpretedInvokefeature switches. - Possibly add support for calli on Mono; if so, we need to move code to the shared location.
- Evaluate whether we want to cache previously generated IL for signatures not handled during startup, and\or whether we need to provide per-assembly code generation to handle cases where the signatures can't exist in CoreLib, such as a signature that contains a value type declared in an assembly not reachable from CoreLib.
- Consider removing the Emit functionality or portions of it for DependencyInjection and System.Text.Json.
Signatures to pre-generate:
Applications used: a console app and WPF app (just `EventAttribute` properties), and Telerik AspNetCoreApp (200+ dynamic methods; mostly constructors)void ()
void (object, object)
void (object, object, object, object)
void (object, object, object, object, object)
void (object, object, object, object, object, object)
void (object, object, object, object, object, object, object)
void (Guid)
void (byte)
void (string)
void (bool)
void (ushort)
void (long)
void (IEnumerable<object>, IEnumerable<object>)
From the list above, we will add getters and setters for all primitive types. All reference types will be treated as object and enums will be treated as their underlying type. Full list:
// One-arg methods which includes setters:
void (object)
void (bool)
void (byte)
void (char)
void (decimal)
void (double)
void (float)
void (Guid)
void (int)
void (long)
void (sbyte)
void (short)
void (string)
void (uint)
void (ulong)
void (ushort)
// Zero-arg methods which includes getters:
void ()
object ()
bool ()
byte ()
char ()
decimal ()
double ()
float ()
Guid ()
int ()
long ()
sbyte ()
short ()
uint ()
ulong ()
ushort ()
// Remaining signatures found in test applications:
void (object, object)
void (object, object, object)
void (object, object, object, object)
void (object, object, object, object, object)
void (object, object, object, object, object, object)
void (object, object, object, object, object, object, object)
void (IEnumerable<object>)
void (IEnumerable<object>, IEnumerable<object>)
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSResourceGet#2056 ·