Skip to content

Async methods become slower to compile in applications which have a very large number of assemblies #94936

@davidwrighton

Description

@davidwrighton

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions