Skip to content

Commit

Permalink
Merge pull request #63153 from CyrusNajmabadi/indexPrecalculate
Browse files Browse the repository at this point in the history
Remove solution crawler pre-indexing of documents
  • Loading branch information
CyrusNajmabadi authored Aug 3, 2022
2 parents e526fe3 + b6dd1c5 commit 4865344
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 119 deletions.

This file was deleted.

8 changes: 3 additions & 5 deletions src/Tools/IdeCoreBenchmarks/NavigateToBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ internal partial class AbstractSyntaxIndex<TIndex> : IObjectWritable

public readonly Checksum? Checksum;

public static int PrecalculatedCount;
public static int ComputedCount;

protected static async Task<TIndex?> LoadAsync(
Document document,
Checksum textChecksum,
Expand Down Expand Up @@ -151,63 +148,6 @@ private async Task<bool> 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<bool> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ private SyntaxTreeIndex(
_globalAliasInfo = globalAliasInfo;
}

public static Task PrecalculateAsync(Document document, CancellationToken cancellationToken)
=> PrecalculateAsync(document, CreateIndex, cancellationToken);

public static ValueTask<SyntaxTreeIndex> GetRequiredIndexAsync(Document document, CancellationToken cancellationToken)
=> GetRequiredIndexAsync(document, ReadIndex, CreateIndex, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@
// 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;

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<TopLevelSyntaxTreeIndex?> LoadAsync(
IChecksummedPersistentStorageService storageService, DocumentKey documentKey, Checksum? checksum, StringTable stringTable, CancellationToken cancellationToken)
{
Expand Down

0 comments on commit 4865344

Please sign in to comment.