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

Spikes in CPU usage when resolving references to methods implementing System.IDisposable #38223

Closed
SirIntruder opened this issue Aug 22, 2019 · 3 comments
Assignees
Labels
Area-IDE Concept-Continuous Improvement IDE-Navigation Navigation and search Need More Info The issue needs more information to proceed.
Milestone

Comments

@SirIntruder
Copy link

SirIntruder commented Aug 22, 2019

Finding references to a method that implement System.IDisposable in any non-trivially sized project takes a long time and causes a big spike in CPU usage. I replicated this behaviour in VS2019, VS2017 and VSCode with omnisharp. It's impossible to avoid this issue if you want to use Code Lens.

After making a cpu profile, it seems that core issue is here:

// WORKAROUND:
// perf check metadata reference using newly created empty compilation with only metadata references.
//
// TODO(cyrusn): Why don't we call project.TryGetCompilation first?
// wouldn't we want to use that compilation if it's available?
var compilation = project.LanguageServices.CompilationFactory.CreateCompilation(
project.AssemblyName, project.CompilationOptions);
compilation = compilation.AddReferences(project.MetadataReferences);
foreach (var reference in project.MetadataReferences)
{
cancellationToken.ThrowIfCancellationRequested();
if (compilation.GetAssemblyOrModuleSymbol(reference) is IAssemblySymbol symbol)
{
var result = predicate(symbol);
if (result != null)
{
return result;
}
}
}

Namely, to find references to MyClass.Dispose(), Roslyn first tries to find all classes that implement System.IDisposable, with first step being filtering all projects in solution to those which have access to assembly containing System.IDisposable. Checking whether a project has access to the said assembly involves creating a whole new compilation object, and this is what seems to be taking most of the cpu cycles.

DisposeProfile

I assume what @CyrusNajmabadi remarked in the TODO would resolve/help with this issue?

@vatsalyaagrawal vatsalyaagrawal assigned mavasani and unassigned mavasani Aug 29, 2019
@vatsalyaagrawal vatsalyaagrawal added this to the Backlog milestone Aug 29, 2019
@vatsalyaagrawal vatsalyaagrawal added the IDE-Navigation Navigation and search label Aug 29, 2019
@jmarolf jmarolf self-assigned this May 13, 2020
@jmarolf
Copy link
Contributor

jmarolf commented May 13, 2020

In past we had optimizations here to not do full FAR on IDisposeable and object members (like ToString) since there are likely going to be tens of thousands of those in large project and finding every location of ToString is not worth the electricity. We should add a filter in front of our Call to SymbolFind.FindRefernces to exclude these types or do a more targeted type search.

@CyrusNajmabadi
Copy link
Member

Can a repro/trace be supplied here?

@CyrusNajmabadi CyrusNajmabadi added the Need More Info The issue needs more information to proceed. label Nov 1, 2022
@ghost ghost closed this as completed Nov 11, 2022
@ghost
Copy link

ghost commented Nov 11, 2022

Closing this issue as we've seen no reply to the request for more information. If you are able to get the requested information, please add it to the issue and we will retriage it.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Concept-Continuous Improvement IDE-Navigation Navigation and search Need More Info The issue needs more information to proceed.
Projects
None yet
Development

No branches or pull requests

6 participants