Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking issue for reflection invoke perf improvements #112994

Open
2 of 6 tasks
steveharter opened this issue Feb 27, 2025 · 2 comments
Open
2 of 6 tasks

Tracking issue for reflection invoke perf improvements #112994

steveharter opened this issue Feb 27, 2025 · 2 comments
Assignees
Labels
area-System.Reflection tenet-performance Performance related issue tracking This issue is tracking the completion of other related issues.
Milestone

Comments

@steveharter
Copy link
Member

steveharter commented Feb 27, 2025

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.
  • 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.
  • 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.
  • Add the main feature leveraging the above.
  • Remove the C++ code from the runtime along with the ForceEmitInvoke and ForceInterpretedInvoke feature switches.
  • 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.
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>)
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 27, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 27, 2025
@steveharter steveharter added area-System.Reflection tenet-performance Performance related issue tracking This issue is tracking the completion of other related issues. and removed untriaged New issue has not been triaged by the area owner needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 27, 2025
@steveharter steveharter added this to the 10.0.0 milestone Feb 27, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

@timcassell
Copy link

  • 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.

Sounds like great motivation to push C# to add the support! dotnet/csharplang#7331

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Reflection tenet-performance Performance related issue tracking This issue is tracking the completion of other related issues.
Projects
None yet
Development

No branches or pull requests

2 participants