-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
When there are many different assemblies in the product which are used, and these assemblies all have async code in them, performance of FindOrCreateAssociatedMethodDesc becomes very slow. The repro is fairly simple (although not practical to include in this bug, as it is extremely large). Create 6000 small assemblies each with a number of async methods in it. Then call System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod on each async method. Observe in a profiler, that the time spent in the application during the series of calls to PrepareMethod that the runtime spends approximately 50% of the time in the JIT calling FindOrCreateAssociatedMethodDesc, and that the time in there is spent walking a linked list in the InstMethodHashTable.
Configuration
All configurations, all OS.
Regression?
This is not a regression.
Data
The benchmark above takes approximately 56 seconds to run on my local machine.
Analysis
An analysis of the InstMethodHashTable indicates that the hash function does not hash on the unique types used in a method instantiation. Instead it hashes based on the TypeDef token of those types. In the presence of 6000 small assemblies of similar shape, the hash tables ends up with extremely unbalanced bucket sizes, and a depth of 6000 entries in the linked list walk to find a single MethodDesc.