Do less work building Delegate.GetMethodInfo lookup (#86930)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Wed, 31 May 2023 05:40:57 +0000 (14:40 +0900)
committerGitHub <noreply@github.com>
Wed, 31 May 2023 05:40:57 +0000 (22:40 -0700)
commit4860b6c28f4c39b64b600f16b428931bf3dc4455
tree2010a9d1194c0d8cf8a93a62a111ffdd2e2afdef
parent1345190bb6a65802c7762d9bc718c950f0a60a10
Do less work building Delegate.GetMethodInfo lookup (#86930)

This code is very problematic for startup. We're spending 6.6% of startup samples of the Stage2 app in `ComputeLdftnReverseLookup_InvokeMap`. This code supports `Delegate.GetMethodInfo` and builds a reverse lookup table to lookup code metadata from code address. The data structure we have in the image is optimized for lookups in the other direction. 2.2% of the total time is spent trying to decode the entrypoint as an unboxing stub (the requires looking up unwinding info for the method). Shortcut this and do it only for valuetypes.

Medium term we'd want to do something about this. In the end this is the same problem as https://github.com/dotnet/runtime/pull/79921#discussion_r1056547078. Except this time we need to be able to lookup this information both ways (from metadata to function pointer and from function pointer to metadata). One thing I'm thinking about is whether we could store the hashcode of the owning type in the unwinding information of the method to give us something to go off.
src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs