EWSoftware / VSSpellChecker

A Visual Studio spell checker editor extension that checks the spelling of comments, strings, and plain text as you type. Supports configuration and various languages.
Other
377 stars 65 forks source link

Spellchecker analyzer consuming larges amounts of CPU #305

Closed davkean closed 8 months ago

davkean commented 10 months ago

Hey folks, I'm from the Visual Studio team, and our CPU telemetry (talked about here) has caught an issue in the wild, where the Roslyn spellchecker analyzers are consuming extraordinally large amounts of CPU in many sessions. This is currently Visual Studio's 16th CPU consumer in 17.7 ranked by cores usage and session count.

We've caught this issue approx 125 times over the past 30 days, with a 50th (medium) percentile of .5 of a core, and 90th percentile of 2.2 cores and super keen to see this addressed.

Here's an example of a Visual Studio session that we caught earlier this week where ServiceHub.RoslynCodeAnalysisService.exe, which hosts analyzers, consumed over 2 CPU cores over a continuous 20 minute period. We automatically traced between the two purple triangles, and found that the below stack was blamed as consuming an average of 1.2 of those cores over that period.

image
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteSyntaxTreeActions
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor+<>c.<ExecuteSyntaxTreeActions>b___
VisualStudio.SpellChecker.CodeAnalyzer.dll!VisualStudio.SpellChecker.CodeAnalyzer.CSharpSpellCheckCodeAnalyzer.AnalyzeSyntaxTree
VisualStudio.SpellChecker.Common.dll!VisualStudio.SpellChecker.Common.SpellingDictionary.SuggestCorrections
VisualStudio.SpellChecker.Common.dll!VisualStudio.SpellChecker.Common.GlobalDictionary.SuggestCorrections
NHunspell.dll!NHunspell.SpellFactory.Suggest
NHunspell.dll!NHunspell.Hunspell.Suggest

Looking at the implemention, it appears that the analyzer produces suggestions at the time the analyzer finds a misspelled word, and this is consuming large amounts of CPU. Might I suggest that the production of the suggestions is moved to the point that the user attempts to fix the issue? That way suggestions are not provided unless actually needed and this will very likely address the entire problem.

Let me know if you need more information about this problem.

Regards David

EWSoftware commented 8 months ago

The latest release (v2023.12.29.0) should resolve this issue. Please let me know if there are any further problems. Thanks.