Skip to content

Perf improvement for completion of unimported extension methods#45283

Merged
genlu merged 17 commits intodotnet:masterfrom
genlu:CompletionPerf
Jun 26, 2020
Merged

Perf improvement for completion of unimported extension methods#45283
genlu merged 17 commits intodotnet:masterfrom
genlu:CompletionPerf

Conversation

@genlu
Copy link
Member

@genlu genlu commented Jun 18, 2020

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

@genlu genlu added the Area-IDE label Jun 18, 2020
@genlu genlu requested a review from a team as a code owner June 18, 2020 06:01
@genlu genlu requested a review from CyrusNajmabadi June 18, 2020 06:01
=> s_aliasMapListPool.Allocate();

protected static string CreateTargetTypeStringForArray(string elementTypeName)
=> elementTypeName + "[]";
Copy link
Contributor

Choose a reason for hiding this comment

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

the + "[]" part is repeated several times. can we share code?

elementTypeSymbol = symbol.ElementType;
}
case INamedTypeSymbol namedType:
return namedType.IsTupleType ? string.Empty : namedType.MetadataName;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have tests for these special cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is actually incorrect. I have fixed the handling of ValueTuple type in source and added tests.

/// - By reference type of any types above
/// - Array types of with element of any types above
/// </summary>
public readonly bool IsComplexType;
Copy link
Contributor

Choose a reason for hiding this comment

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

if IsArrayType implies IsComplexType, should we use an enum instead?

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, array doesn't indicate it's complex type, it depends on the element of the array

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@CyrusNajmabadi
Copy link
Contributor

ffrom ~65s to ms.

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 + "[]";
Copy link
Contributor

Choose a reason for hiding this comment

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

any concerns about things like (int, int)[]? or (int[], int[])? i.e. mixes of tuples/arrays?

Copy link
Contributor

Choose a reason for hiding this comment

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

if we use the "[]" elsewhere, consider a named ocnstant. or a hel that makes htis name.

Copy link
Member Author

Choose a reason for hiding this comment

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

any concerns about things like (int, int)[]? or (int[], int[])? i.e. mixes of tuples/arrays?

Those should work now.

@CyrusNajmabadi
Copy link
Contributor

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!

@genlu
Copy link
Member Author

genlu commented Jun 18, 2020

Awesome! What's the perf when called on an array type?

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

@CyrusNajmabadi
Copy link
Contributor

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
Copy link
Member Author

Choose a reason for hiding this comment

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

File #45404 to track this issue. Not fixing it as part of this PR.

The perf with ignoreAssemblyKey = true doesn't meet the bar
@genlu
Copy link
Member Author

genlu commented Jun 24, 2020

@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?

@CyrusNajmabadi
Copy link
Contributor

yup, i will look later today. ping me if i forget

public MultiDictionary<string, ExtensionMethodInfo>.ValueSet GetExtensionMethodInfoForReceiverType(string typeName)
=> _receiverTypeNameToExtensionMethodMap != null
? _receiverTypeNameToExtensionMethodMap[typeName]
: new MultiDictionary<string, ExtensionMethodInfo>.ValueSet(null, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

singleton for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's a struct

Copy link
Contributor

Choose a reason for hiding this comment

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

Good to know. a readonly static field might still be nice for clarity, but i don't care then :)

@CyrusNajmabadi
Copy link
Contributor

done with pass.

genlu and others added 2 commits June 25, 2020 15:40
…onProvider/ExtensionMethodImportCompletionHelper.cs

Co-authored-by: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
@genlu genlu merged commit ced84c0 into dotnet:master Jun 26, 2020
@ghost ghost added this to the Next milestone Jun 26, 2020
@genlu
Copy link
Member Author

genlu commented Jun 26, 2020

Thanks! @CyrusNajmabadi

@genlu genlu deleted the CompletionPerf branch June 26, 2020 20:42
@dibarbet dibarbet modified the milestones: Next, 16.7.P4 Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Show items from unimported namespaces" breaks members suggestions

3 participants