Perf improvement for completion of unimported extension methods#45283
Perf improvement for completion of unimported extension methods#45283genlu merged 17 commits intodotnet:masterfrom
Conversation
All array types for one elemnt type is consider same in our index. e.g. int[], int[][] and int[,] are just represent as int[]
Since they are already from the same compilation that triggered completion.
src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs
Show resolved
Hide resolved
| => s_aliasMapListPool.Allocate(); | ||
|
|
||
| protected static string CreateTargetTypeStringForArray(string elementTypeName) | ||
| => elementTypeName + "[]"; |
There was a problem hiding this comment.
the + "[]" part is repeated several times. can we share code?
src/Workspaces/VisualBasic/Portable/FindSymbols/VisualBasicDeclaredSymbolInfoFactoryService.vb
Outdated
Show resolved
Hide resolved
src/Workspaces/VisualBasic/Portable/FindSymbols/VisualBasicDeclaredSymbolInfoFactoryService.vb
Outdated
Show resolved
Hide resolved
...table/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs
Outdated
Show resolved
Hide resolved
...table/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs
Outdated
Show resolved
Hide resolved
| elementTypeSymbol = symbol.ElementType; | ||
| } | ||
| case INamedTypeSymbol namedType: | ||
| return namedType.IsTupleType ? string.Empty : namedType.MetadataName; |
There was a problem hiding this comment.
do we have tests for these special cases?
There was a problem hiding this comment.
This is actually incorrect. I have fixed the handling of ValueTuple type in source and added tests.
...table/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo_Metadata.cs
Outdated
Show resolved
Hide resolved
...table/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs
Outdated
Show resolved
Hide resolved
| /// - By reference type of any types above | ||
| /// - Array types of with element of any types above | ||
| /// </summary> | ||
| public readonly bool IsComplexType; |
There was a problem hiding this comment.
if IsArrayType implies IsComplexType, should we use an enum instead?
There was a problem hiding this comment.
No, array doesn't indicate it's complex type, it depends on the element of the array
There was a problem hiding this comment.
ah... that wasn't totally clear to me from the docs (though they docs are correct). perhaps explicitly call out that simple array types (i.e. Int32[]) wouldn't be complex.
Awesome! What's the perf when called on an array type? |
|
|
||
| // We do not differentiate array of different kinds sicne they are all represented in the indices as "NonArrayElementTypeName[]" | ||
| // e.g. int[], int[][], int[,], etc. are all represented as "int[]", whereas array of complex type such as T[] is "[]". | ||
| return elementTypeName + "[]"; |
There was a problem hiding this comment.
any concerns about things like (int, int)[]? or (int[], int[])? i.e. mixes of tuples/arrays?
There was a problem hiding this comment.
if we use the "[]" elsewhere, consider a named ocnstant. or a hel that makes htis name.
There was a problem hiding this comment.
any concerns about things like (int, int)[]? or (int[], int[])? i.e. mixes of tuples/arrays?
Those should work now.
...table/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs
Outdated
Show resolved
Hide resolved
...table/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs
Outdated
Show resolved
Hide resolved
|
Overall this is looking fine to me. :) My overall request is to always be keeping an eye to simplicity and clarity. I think some small tweaks would help a lot. Thanks! |
I don't have a concrete number, but it would be slower since it will have potentially a lot more symbols to check. But in the repro project I have it still takes less than a sec |
Awesome! That's still more than acceptable to get us past this major regression :) |
…framework Set ignoreAssemblyKey to true during SymbolKey resolution
There was a problem hiding this comment.
File #45404 to track this issue. Not fixing it as part of this PR.
The perf with ignoreAssemblyKey = true doesn't meet the bar
|
@CyrusNajmabadi Now the avg time for getting unimported extension method items (just computation in OOP, not including communication between devenv and OOP) is ~30ms in the repro solution, which takes 65s everything included for each completion session w/o this change. Could you please take another look? |
|
yup, i will look later today. ping me if i forget |
...Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ImportCompletionItem.cs
Show resolved
Hide resolved
...Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ImportCompletionItem.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs
Outdated
Show resolved
Hide resolved
| public MultiDictionary<string, ExtensionMethodInfo>.ValueSet GetExtensionMethodInfoForReceiverType(string typeName) | ||
| => _receiverTypeNameToExtensionMethodMap != null | ||
| ? _receiverTypeNameToExtensionMethodMap[typeName] | ||
| : new MultiDictionary<string, ExtensionMethodInfo>.ValueSet(null, null); |
There was a problem hiding this comment.
singleton for this?
There was a problem hiding this comment.
Good to know. a readonly static field might still be nice for clarity, but i don't care then :)
...table/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs
Show resolved
Hide resolved
...table/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs
Outdated
Show resolved
Hide resolved
...table/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs
Outdated
Show resolved
Hide resolved
...table/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs
Show resolved
Hide resolved
|
done with pass. |
…onProvider/ExtensionMethodImportCompletionHelper.cs Co-authored-by: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
...table/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs
Show resolved
Hide resolved
|
Thanks! @CyrusNajmabadi |
Fix #45042.
I only did some quick measurement with stopwatch, the completion perf using repro project (ConsoleApp with reference to Accord.Math package) improved from ~65s to ms.
@CyrusNajmabadi could you please take a look?
FYI @AmadeusW