dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.91k stars 4.01k forks source link

DependentProjectsFinder.GetAssemblyReferenceType might perform unnecessary binding #41358

Open sharwell opened 4 years ago

sharwell commented 4 years ago

The DependentProjectsFinder.GetAssemblyReferenceType method obtains an assembly or module symbol here:

https://github.com/dotnet/roslyn/blob/e0567782254976e12f4a27444c3c0e82a91ae584/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentProjectsFinder.cs#L458

This symbol is passed to a predicate, where the only actual use of this predicate is the following:

https://github.com/dotnet/roslyn/blob/e0567782254976e12f4a27444c3c0e82a91ae584/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentProjectsFinder.cs#L419

The HasReferenceToAssembly method should be updated to avoid requiring symbol binding to check the name of an assembly.

🔗 Originally discovered while investigating internal issue DevDiv 1006914.

bleroy commented 4 years ago

FWIW, still repros in 16.5 Preview 3.

sharwell commented 3 years ago

😨 This was responsible for 3.5GiB allocations in a 100 second performance trace taken with 16.9 Preview 2 (IntPreview 1a8a5724).

CyrusNajmabadi commented 3 years ago

Any suggestions on an alternate path to take? If this is a PEReference we could attempt to crack it open directly. But that seems non-ideal. Esp. as i would hope we could get an IAssemblySymbol cheaply to do this check. Should this maybe go to compiler to see if htey can mkae things faster or more lightweight here?