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

Improve performance of spell checking analyzer #6569

Merged
merged 8 commits into from
Apr 5, 2023
Merged

Conversation

CyrusNajmabadi
Copy link
Member

Addresses the enormous amount of dictionary allocations performed on every compilation start:

image

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner April 4, 2023 21:45
/// Todo, use an actual AdditionalTextValueProvider once it is available:
/// https://github.com/dotnet/roslyn/issues/67611
/// </summary>
private readonly ConditionalWeakTable<AdditionalText, CodeAnalysisDictionary> _textToDictionary = new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private readonly ConditionalWeakTable<AdditionalText, CodeAnalysisDictionary> _textToDictionary = new();

Not sure what the lifetime of this object is, but I assume this member is intentionally not static. If so, might be nice to doc that too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Manish preferred non-static CWTs for additional-text mappings.


return dictionary;

// Local function to avoid unnecessary lambda alloc in mainline case.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ Wouldn't it only need to alloc the lambda if the lambda references additionalText from the containing scope? In this case, it only seems to reference dictionary from the current scope.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check the IL, but i believe it will still create a closure.

=> !projectDictionary.UnrecognizedWords.Contains(word) && projectDictionary.RecognizedWords.Contains(word);
{
var unrecognizedWordsContains = dictionaries.Any(static (d, word) => d.ContainsUnrecognizedWord(word), word);
var recognizedWordsContains = dictionaries.Any(static (d, word) => d.ContainsRecognizedWord(word), word);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var recognizedWordsContains = dictionaries.Any(static (d, word) => d.ContainsRecognizedWord(word), word);

nit: the new code always executes both lookups, maybe it's worth it for the additional clarity?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. it would def make sense to shortcircuit. i'll do that.

@codecov
Copy link

codecov bot commented Apr 4, 2023

Codecov Report

Merging #6569 (bac0aee) into main (7e98f62) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6569   +/-   ##
=======================================
  Coverage   96.43%   96.43%           
=======================================
  Files        1373     1373           
  Lines      320341   320260   -81     
  Branches    10309    10296   -13     
=======================================
- Hits       308911   308837   -74     
+ Misses       8972     8966    -6     
+ Partials     2458     2457    -1     

@CyrusNajmabadi CyrusNajmabadi merged commit 4208547 into main Apr 5, 2023
@CyrusNajmabadi CyrusNajmabadi deleted the spellChecker branch April 5, 2023 07:35
@github-actions github-actions bot added this to the vNext milestone Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants