Skip to content

Tracking issue for reflection invoke perf improvements #112994

Open
@steveharter

Description

@steveharter

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 #109901 for a partial reference implementation.

  • Modify or remove existing tests that are too dependent on the current implementation's idiosyncrasies. See Harden some reflection invoke tests #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 Support HasThis and ExplicitThis calling conventions in AssemblyBuilder and DynamicMethod #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 Add internal intrinsics for instance-based calli #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>)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions