Tracking issue for reflection invoke perf improvements

Open
#112,994 2 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
18/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp, csharp
Domain
devtools

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

area-System.Reflection tenet-performance tracking

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 ForceEmitInvoke and ForceInterpretedInvoke feature 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.