-
Notifications
You must be signed in to change notification settings - Fork 468
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
[Performance] Improve SpecifyIFormatProvider (CA1305) performance #6865
Conversation
{ | ||
var semanticModel = argument.SemanticModel!; | ||
|
||
var symbol = semanticModel.GetSymbolInfo(argument.Value.Syntax, oaContext.CancellationToken).Symbol; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mavasani I assume semantic model calls are more expensive than getting info directly from IOperation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, definitely.
(targetMethod.Equals(stringFormatMemberWithStringAndObjectParameter) || | ||
targetMethod.Equals(stringFormatMemberWithStringObjectAndObjectParameter) || | ||
targetMethod.Equals(stringFormatMemberWithStringObjectObjectAndObjectParameter) || | ||
targetMethod.Equals(stringFormatMemberWithStringAndParamsObjectParameter))) | ||
targetMethod.Equals(stringFormatMemberWithStringAndParamsObjectParameter)) && | ||
!oaContext.Options.IsConfiguredToSkipAnalysis(IFormatProviderAlternateStringRule, targetMethod, oaContext.ContainingSymbol, oaContext.Compilation)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Symbol equality should be faster than IsConfiguredToSkipAnalysis
private static IEnumerable<int> GetIndexesOfParameterType(IMethodSymbol targetMethod, INamedTypeSymbol formatProviderType) | ||
{ | ||
return targetMethod.Parameters | ||
.Select((Parameter, Index) => (Parameter, Index)) | ||
.Where(x => x.Parameter.Type.Equals(formatProviderType)) | ||
.Select(x => x.Index); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm now looping over arguments directly and than checking if the parameter is of interest. The new implementation should hopefully be more performant and more straightforward.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #6865 +/- ##
=======================================
Coverage 96.39% 96.39%
=======================================
Files 1403 1403
Lines 330977 330968 -9
Branches 10890 10891 +1
=======================================
- Hits 319055 319050 -5
+ Misses 9188 9182 -6
- Partials 2734 2736 +2 |
@buyaa-n for another review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
No description provided.