-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Reduce allocations in AbstractProjectExtensionProvider.FilterExtensions #74112
Reduce allocations in AbstractProjectExtensionProvider.FilterExtensions #74112
Conversation
This ends up reducing allocations in the profile where I repeatedly brough up a lightbulb by about 0.7%. 1) Got rid of an Enum.ToString that happened on each filtering. Instead changed the code that reads the mef attributes to convert from string -> enum. 2) Got rid of a a couple Contains calls which were allocating an enumerator 3) Got rid of some closures by using the args version of WhereAsArray and by creating a separate method to handle the CWT insertion.
|
||
bool ShouldIncludeExtension(TExtension extension) | ||
static bool ShouldIncludeExtension(TExtension extension, (TextDocument, Func<TExportAttribute, ExtensionInfo>) args) |
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 have no problem with you inlining this method into WhereAsArray.
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.
Tried it, stared at it for a minute, and I personally like it better in the current form. Will gladly change it though if you feel fairly strongly or have an objective reason.
src/Features/Core/Portable/Common/AbstractProjectExtensionProvider.cs
Outdated
Show resolved
Hide resolved
|
||
if (extensionInfo == null) | ||
return true; | ||
|
||
if (!extensionInfo.DocumentKinds.Contains(document.Kind.ToString())) | ||
if (-1 == Array.IndexOf(extensionInfo.DocumentKinds, document.Kind)) |
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.
would prefer a < 0
check. even if doc'ed some apis end up returning different from -1.
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.
Done!
src/Features/Core/Portable/Common/AbstractProjectExtensionProvider.cs
Outdated
Show resolved
Hide resolved
} | ||
|
||
return new(kinds, attribute.DocumentExtensions); | ||
} |
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.
can we not have a helper for this? (since it seems duplicated).
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.
Done!
…ider.cs Co-authored-by: Cyrus Najmabadi <[email protected]>
…Provider_FilterExtensions' of https://github.com/toddgrun/roslyn into dev/toddgrun/ReduceAlocationsIn_AbstractProjectExtensionProvider_FilterExtensions
|
||
internal class EnumArrayConverter | ||
{ | ||
public static TEnum[] FromStringArray<TEnum>(string[] strings) where TEnum : struct |
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.
public static TEnum[] FromStringArray<TEnum>(string[] strings) where TEnum : struct | |
public static TEnum[] FromStringArray<TEnum>(string[] strings) where TEnum : struct, System.Enum |
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.
Nite: consider returning ImmutableArray instread if you don't need to mutate hte array.
|
||
namespace Microsoft.CodeAnalysis.CodeFixesAndRefactorings; | ||
|
||
internal class EnumArrayConverter |
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.
internal class EnumArrayConverter | |
internal static class EnumArrayConverter |
This ends up reducing allocations in the profile where I repeatedly brough up a lightbulb by about 0.7%.
*** Prior allocations that no longer show up ***