Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc85a40

Browse files
authored
Merge pull request#48356 from sharwell/perf-1224834
Implement low-hanging performance improvements from feedback investigation
2 parents055d05c +4646331 commitbc85a40

File tree

39 files changed

+263
-129
lines changed

39 files changed

+263
-129
lines changed

‎src/CodeStyle/Core/CodeFixes/LanguageServices/SemanticModelWorkspaceService/SemanticModelWorkspaceServiceFactory.SemanticModelWorkspaceService.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public SemanticModelReuseWorkspaceService(Workspace _)
1717
{
1818
}
1919

20-
publicTask<SemanticModel>ReuseExistingSpeculativeModelAsync(Documentdocument,SyntaxNodenode,CancellationTokencancellationToken)
20+
publicValueTask<SemanticModel>ReuseExistingSpeculativeModelAsync(Documentdocument,SyntaxNodenode,CancellationTokencancellationToken)
2121
{
2222
// TODO: port the GetSemanticModelForNodeAsync implementation from Workspaces layer,
2323
// which currently relies on a bunch of internal APIs.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
usingSystem;
6+
usingSystem.Collections.Concurrent;
7+
usingRoslyn.Utilities;
8+
usingXunit;
9+
10+
namespaceMicrosoft.CodeAnalysis.UnitTests.InternalUtilities
11+
{
12+
publicclassConcurrentDictionaryExtensionsTests
13+
{
14+
[Fact]
15+
publicvoidTestAdd()
16+
{
17+
vardictionary=newConcurrentDictionary<int,int>();
18+
dictionary.Add(0,0);
19+
Assert.Equal(0,dictionary[0]);
20+
21+
Assert.Throws<ArgumentException>(()=>dictionary.Add(0,0));
22+
}
23+
24+
[Fact]
25+
publicvoidTestGetOrAdd()
26+
{
27+
varfirst=newobject();
28+
varsecond=newobject();
29+
30+
vardictionary=newConcurrentDictionary<int,object>();
31+
Assert.Same(first,dictionary.GetOrAdd(0,static(key,arg)=>arg,first));
32+
Assert.Same(first,dictionary[0]);
33+
Assert.Single(dictionary);
34+
Assert.Same(first,dictionary.GetOrAdd(0,static(key,arg)=>arg,second));
35+
Assert.Same(first,dictionary[0]);
36+
Assert.Single(dictionary);
37+
}
38+
}
39+
}

‎src/Compilers/Core/Portable/InternalUtilities/ConcurrentDictionaryExtensions.cs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
usingSystem;
56
usingSystem.Collections.Concurrent;
7+
usingMicrosoft.CodeAnalysis.PooledObjects;
68

79
namespaceRoslyn.Utilities
810
{
@@ -19,8 +21,22 @@ public static void Add<K, V>(this ConcurrentDictionary<K, V> dict, K key, V valu
1921
{
2022
if(!dict.TryAdd(key,value))
2123
{
22-
thrownewSystem.ArgumentException("adding a duplicate");
24+
thrownewArgumentException("adding a duplicate",nameof(key));
2325
}
2426
}
27+
28+
publicstaticTValueGetOrAdd<TKey,TArg,TValue>(thisConcurrentDictionary<TKey,TValue>dictionary,TKeykey,Func<TKey,TArg,TValue>valueFactory,TArgfactoryArgument)
29+
whereTKey:notnull
30+
{
31+
#ifNETCOREAPP
32+
returndictionary.GetOrAdd(key,valueFactory,factoryArgument);
33+
#else
34+
if(dictionary.TryGetValue(key,outvarvalue))
35+
returnvalue;
36+
37+
usingvar_=PooledDelegates.GetPooledFunction(valueFactory,factoryArgument,outvarboundFunction);
38+
returndictionary.GetOrAdd(key,boundFunction);
39+
#endif
40+
}
2541
}
2642
}

‎src/EditorFeatures/TestUtilities/ChangeSignature/AddedParameterOrExistingIndex.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public override string ToString()
6161

6262
internalAddedParameterGetAddedParameter(Documentdocument)
6363
{
64-
varsemanticModel=document.GetRequiredSemanticModelAsync(CancellationToken.None).Result;
64+
varsemanticModel=document.GetRequiredSemanticModelAsync(CancellationToken.None).AsTask().Result;
6565

6666
vartype=document.Project.Languageswitch
6767
{

‎src/Features/Core/Portable/ChangeSignature/DelegateInvokeMethodReferenceFinder.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected override Task<ImmutableArray<Document>> DetermineDocumentsToSearchAsyn
7171
returnTask.FromResult(project.Documents.ToImmutableArray());
7272
}
7373

74-
protectedoverrideasyncTask<ImmutableArray<FinderLocation>>FindReferencesInDocumentAsync(
74+
protectedoverrideasyncValueTask<ImmutableArray<FinderLocation>>FindReferencesInDocumentAsync(
7575
IMethodSymbolmethodSymbol,
7676
Documentdocument,
7777
SemanticModelsemanticModel,

‎src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.ExtensionMethodSymbolComputer.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Task PopulateIndicesAsync(CancellationToken cancellationToken)
8484
foreach(varpeReferenceinGetAllRelevantPeReferences())
8585
{
8686
tasks.Add(Task.Run(()
87-
=>SymbolTreeInfo.GetInfoForMetadataReferenceAsync(Solution,peReference,loadOnly:false,cancellationToken),cancellationToken));
87+
=>SymbolTreeInfo.GetInfoForMetadataReferenceAsync(Solution,peReference,loadOnly:false,cancellationToken).AsTask(),cancellationToken));
8888
}
8989

9090
returnTask.WhenAll(tasks.ToImmutable());
@@ -100,7 +100,7 @@ public Task PopulateIndicesAsync(CancellationToken cancellationToken)
100100
tasks.Add(Task.Run(()=>GetExtensionMethodSymbolsFromPeReferenceAsync(
101101
peReference,
102102
forceIndexCreation,
103-
cancellationToken),cancellationToken));
103+
cancellationToken).AsTask(),cancellationToken));
104104
}
105105

106106
foreach(varprojectinGetAllRelevantProjects())
@@ -184,7 +184,7 @@ private ImmutableArray<PortableExecutableReference> GetAllRelevantPeReferences()
184184
:GetExtensionMethodsForSymbolsFromDifferentCompilation(matchingMethodSymbols,cancellationToken);
185185
}
186186

187-
privateasyncTask<ImmutableArray<IMethodSymbol>?>GetExtensionMethodSymbolsFromPeReferenceAsync(
187+
privateasyncValueTask<ImmutableArray<IMethodSymbol>?>GetExtensionMethodSymbolsFromPeReferenceAsync(
188188
PortableExecutableReferencepeReference,
189189
boolforceIndexCreation,
190190
CancellationTokencancellationToken)

‎src/Features/Core/Portable/IncrementalCaches/SymbolTreeInfoCacheService.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public SymbolTreeInfoCacheService(
2929
_metadataIdToInfo=metadataIdToInfo;
3030
}
3131

32-
publicasyncTask<SymbolTreeInfo>TryGetMetadataSymbolTreeInfoAsync(
32+
publicasyncValueTask<SymbolTreeInfo>TryGetMetadataSymbolTreeInfoAsync(
3333
Solutionsolution,
3434
PortableExecutableReferencereference,
3535
CancellationTokencancellationToken)

‎src/VisualStudio/Core/Def/Implementation/AbstractEditorFactory.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ private void FormatDocumentCreatedFromTemplate(IVsHierarchy hierarchy, uint item
321321

322322
// Organize using directives
323323
addedDocument=ThreadHelper.JoinableTaskFactory.Run(()=>OrganizeUsingsCreatedFromTemplateAsync(addedDocument,cancellationToken));
324-
rootToFormat=ThreadHelper.JoinableTaskFactory.Run(()=>addedDocument.GetRequiredSyntaxRootAsync(cancellationToken));
324+
rootToFormat=ThreadHelper.JoinableTaskFactory.Run(()=>addedDocument.GetRequiredSyntaxRootAsync(cancellationToken).AsTask());
325325

326326
// Format document
327327
varunformattedText=addedDocument.GetTextSynchronously(cancellationToken);

‎src/VisualStudio/Core/Def/Implementation/ChangeSignature/AddParameterDialogViewModel.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal class AddParameterDialogViewModel : AbstractNotifyPropertyChanged
2727
publicAddParameterDialogViewModel(Documentdocument,intpositionForTypeBinding)
2828
{
2929
_notificationService=document.Project.Solution.Workspace.Services.GetService<INotificationService>();
30-
_semanticModel=document.GetRequiredSemanticModelAsync(CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
30+
_semanticModel=document.GetRequiredSemanticModelAsync(CancellationToken.None).AsTask().WaitAndGetResult_CanCallOnBackground(CancellationToken.None);
3131

3232
TypeIsEmptyImage=Visibility.Visible;
3333
TypeBindsImage=Visibility.Collapsed;

‎src/Workspaces/Core/Portable/ExternalAccess/Pythia/Api/PythiaDocumentExtensions.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Pythia.Api
1111
internalstaticclassPythiaDocumentExtensions
1212
{
1313
publicstaticTask<SemanticModel>GetSemanticModelForNodeAsync(thisDocumentdocument,SyntaxNode?node,CancellationTokencancellationToken)
14-
=>DocumentExtensions.ReuseExistingSpeculativeModelAsync(document,node,cancellationToken);
14+
=>DocumentExtensions.ReuseExistingSpeculativeModelAsync(document,node,cancellationToken).AsTask();
1515
}
1616
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp