From b6dd1c5cd8eb40b27d4df0ad3634f3bf2e636eb4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 2 Aug 2022 16:42:19 -0700 Subject: [PATCH] Remove solution crawler pre-indexing of documents --- ...ntaxTreeInfoIncrementalAnalyzerProvider.cs | 42 ------------- .../IdeCoreBenchmarks/NavigateToBenchmarks.cs | 8 +-- .../Shared/AbstractSyntaxIndex_Persistence.cs | 60 ------------------- .../FindSymbols/SyntaxTree/SyntaxTreeIndex.cs | 3 - .../TopLevelSyntaxTreeIndex_Persistence.cs | 9 --- 5 files changed, 3 insertions(+), 119 deletions(-) delete mode 100644 src/Features/Core/Portable/IncrementalCaches/SyntaxTreeInfoIncrementalAnalyzerProvider.cs diff --git a/src/Features/Core/Portable/IncrementalCaches/SyntaxTreeInfoIncrementalAnalyzerProvider.cs b/src/Features/Core/Portable/IncrementalCaches/SyntaxTreeInfoIncrementalAnalyzerProvider.cs deleted file mode 100644 index 285fc09e1f2a7..0000000000000 --- a/src/Features/Core/Portable/IncrementalCaches/SyntaxTreeInfoIncrementalAnalyzerProvider.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Composition; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.FindSymbols; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.SolutionCrawler; - -namespace Microsoft.CodeAnalysis.IncrementalCaches -{ - [ExportIncrementalAnalyzerProvider(nameof(SyntaxTreeInfoIncrementalAnalyzerProvider), new[] { WorkspaceKind.RemoteWorkspace }), Shared] - internal class SyntaxTreeInfoIncrementalAnalyzerProvider : IIncrementalAnalyzerProvider - { - [ImportingConstructor] - [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] - public SyntaxTreeInfoIncrementalAnalyzerProvider() - { - } - - public IIncrementalAnalyzer CreateIncrementalAnalyzer(Workspace workspace) - => new IncrementalAnalyzer(); - - private class IncrementalAnalyzer : IncrementalAnalyzerBase - { - public override async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, CancellationToken cancellationToken) - { - if (!document.SupportsSyntaxTree) - { - // Not a language we can produce indices for (i.e. TypeScript). Bail immediately. - return; - } - - await SyntaxTreeIndex.PrecalculateAsync(document, cancellationToken).ConfigureAwait(false); - await TopLevelSyntaxTreeIndex.PrecalculateAsync(document, cancellationToken).ConfigureAwait(false); - } - } - } -} diff --git a/src/Tools/IdeCoreBenchmarks/NavigateToBenchmarks.cs b/src/Tools/IdeCoreBenchmarks/NavigateToBenchmarks.cs index 10fd86d301602..def5ae023e819 100644 --- a/src/Tools/IdeCoreBenchmarks/NavigateToBenchmarks.cs +++ b/src/Tools/IdeCoreBenchmarks/NavigateToBenchmarks.cs @@ -125,12 +125,10 @@ public async Task RunSerialIndexing() foreach (var document in project.Documents) { // await WalkTree(document); - await SyntaxTreeIndex.PrecalculateAsync(document, default).ConfigureAwait(false); + await SyntaxTreeIndex.GetIndexAsync(document, default).ConfigureAwait(false); } } Console.WriteLine("Serial: " + (DateTime.Now - start)); - Console.WriteLine("Precalculated count: " + SyntaxTreeIndex.PrecalculatedCount); - Console.WriteLine("Computed count: " + SyntaxTreeIndex.ComputedCount); Console.ReadLine(); } @@ -161,7 +159,7 @@ public async Task RunProjectParallelIndexing() async () => { // await WalkTree(d); - await TopLevelSyntaxTreeIndex.PrecalculateAsync(d, default); + await TopLevelSyntaxTreeIndex.GetIndexAsync(d, default); })).ToList(); await Task.WhenAll(tasks); } @@ -177,7 +175,7 @@ public async Task RunFullParallelIndexing() Console.WriteLine("Starting indexing"); var start = DateTime.Now; var tasks = _workspace.CurrentSolution.Projects.SelectMany(p => p.Documents).Select(d => Task.Run( - () => SyntaxTreeIndex.PrecalculateAsync(d, default))).ToList(); + () => SyntaxTreeIndex.GetIndexAsync(d, default))).ToList(); await Task.WhenAll(tasks); Console.WriteLine("Solution parallel: " + (DateTime.Now - start)); } diff --git a/src/Workspaces/Core/Portable/FindSymbols/Shared/AbstractSyntaxIndex_Persistence.cs b/src/Workspaces/Core/Portable/FindSymbols/Shared/AbstractSyntaxIndex_Persistence.cs index 7020f4dea8087..2df78993fa529 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Shared/AbstractSyntaxIndex_Persistence.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Shared/AbstractSyntaxIndex_Persistence.cs @@ -30,9 +30,6 @@ internal partial class AbstractSyntaxIndex : IObjectWritable public readonly Checksum? Checksum; - public static int PrecalculatedCount; - public static int ComputedCount; - protected static async Task LoadAsync( Document document, Checksum textChecksum, @@ -151,63 +148,6 @@ private async Task SaveAsync( return false; } - protected static async Task PrecalculateAsync(Document document, IndexCreator create, CancellationToken cancellationToken) - { - if (!document.SupportsSyntaxTree) - return; - - using (Logger.LogBlock(FunctionId.SyntaxTreeIndex_Precalculate, cancellationToken)) - { - Debug.Assert(document.IsFromPrimaryBranch()); - - var (textChecksum, textAndDirectivesChecksum) = await GetChecksumsAsync(document, cancellationToken).ConfigureAwait(false); - - // Check if we've already created and persisted the index for this document. - if (await PrecalculatedAsync(document, textChecksum, textAndDirectivesChecksum, cancellationToken).ConfigureAwait(false)) - { - PrecalculatedCount++; - return; - } - - using (Logger.LogBlock(FunctionId.SyntaxTreeIndex_Precalculate_Create, cancellationToken)) - { - // If not, create and save the index. - var data = await CreateIndexAsync(document, textChecksum, textAndDirectivesChecksum, create, cancellationToken).ConfigureAwait(false); - await data.SaveAsync(document, cancellationToken).ConfigureAwait(false); - ComputedCount++; - } - } - } - - private static async Task PrecalculatedAsync( - Document document, Checksum textChecksum, Checksum textAndDirectivesChecksum, CancellationToken cancellationToken) - { - var solution = document.Project.Solution; - var persistentStorageService = solution.Services.GetPersistentStorageService(); - - // check whether we already have info for this document - try - { - var storage = await persistentStorageService.GetStorageAsync(SolutionKey.ToSolutionKey(solution), cancellationToken).ConfigureAwait(false); - await using var _ = storage.ConfigureAwait(false); - - // Check if we've already stored a checksum and it matches the checksum we expect. If so, we're already - // precalculated and don't have to recompute this index. Otherwise if we don't have a checksum, or the - // checksums don't match, go ahead and recompute it. - // - // Check with both checksums as we don't know at this reading point if the document has pp-directives in - // it or not, and we don't want parse the document to find out. - return await storage.ChecksumMatchesAsync(document, s_persistenceName, textChecksum, cancellationToken).ConfigureAwait(false) || - await storage.ChecksumMatchesAsync(document, s_persistenceName, textAndDirectivesChecksum, cancellationToken).ConfigureAwait(false); - } - catch (Exception e) when (IOUtilities.IsNormalIOException(e)) - { - // Storage APIs can throw arbitrary exceptions. - } - - return false; - } - bool IObjectWritable.ShouldReuseInSerialization => true; public abstract void WriteTo(ObjectWriter writer); diff --git a/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex.cs b/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex.cs index a0a8404b812d1..e5b837a1c7d32 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex.cs @@ -30,9 +30,6 @@ private SyntaxTreeIndex( _globalAliasInfo = globalAliasInfo; } - public static Task PrecalculateAsync(Document document, CancellationToken cancellationToken) - => PrecalculateAsync(document, CreateIndex, cancellationToken); - public static ValueTask GetRequiredIndexAsync(Document document, CancellationToken cancellationToken) => GetRequiredIndexAsync(document, ReadIndex, CreateIndex, cancellationToken); diff --git a/src/Workspaces/Core/Portable/FindSymbols/TopLevelSyntaxTree/TopLevelSyntaxTreeIndex_Persistence.cs b/src/Workspaces/Core/Portable/FindSymbols/TopLevelSyntaxTree/TopLevelSyntaxTreeIndex_Persistence.cs index 61a946c3e3480..1cf158302a07e 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/TopLevelSyntaxTree/TopLevelSyntaxTreeIndex_Persistence.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/TopLevelSyntaxTree/TopLevelSyntaxTreeIndex_Persistence.cs @@ -2,15 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Internal.Log; -using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.Storage; using Roslyn.Utilities; @@ -18,9 +12,6 @@ namespace Microsoft.CodeAnalysis.FindSymbols { internal sealed partial class TopLevelSyntaxTreeIndex : IObjectWritable { - public static Task PrecalculateAsync(Document document, CancellationToken cancellationToken) - => PrecalculateAsync(document, CreateIndex, cancellationToken); - public static Task LoadAsync( IChecksummedPersistentStorageService storageService, DocumentKey documentKey, Checksum? checksum, StringTable stringTable, CancellationToken cancellationToken) {