Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document state storage refactoring #51420

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
``` ini
tmat marked this conversation as resolved.
Show resolved Hide resolved

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
AMD Ryzen Threadripper 3960X, 1 CPU, 48 logical and 24 physical cores
[Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT
DefaultJob : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT


```
| Method | DocumentCount | Mean | Error | StdDev | Median | Gen 0 | Gen 1 | Gen 2 | Allocated |
|-------------------------- |-------------- |----------------:|--------------:|--------------:|----------------:|-------:|-------:|------:|----------:|
| **Project.DocumentIds** | **0** | **23.34 ns** | **0.494 ns** | **0.891 ns** | **22.91 ns** | **-** | **-** | **-** | **-** |
| Project.Documents | 0 | 77.22 ns | 0.537 ns | 0.502 ns | 77.31 ns | 0.0772 | - | - | 128 B |
| Solution.WithDocumentText | 0 | 14.60 ns | 0.324 ns | 0.690 ns | 14.57 ns | - | - | - | - |
| **Project.DocumentIds** | **100** | **8,159.41 ns** | **10.113 ns** | **8.965 ns** | **8,157.79 ns** | **0.0305** | **-** | **-** | **72 B** |
| Project.Documents | 100 | 16,356.60 ns | 97.365 ns | 91.076 ns | 16,382.64 ns | 0.0916 | - | - | 201 B |
| Solution.WithDocumentText | 100 | 14,436.90 ns | 355.846 ns | 1,015.248 ns | 14,392.68 ns | 0.8240 | 0.2136 | - | 5285 B |
| **Project.DocumentIds** | **10000** | **863,988.25 ns** | **1,297.511 ns** | **1,213.693 ns** | **863,625.88 ns** | **-** | **-** | **-** | **80 B** |
| Project.Documents | 10000 | 1,861,933.16 ns | 11,538.506 ns | 10,793.125 ns | 1,859,064.65 ns | - | - | - | 208 B |
| Solution.WithDocumentText | 10000 | 14,088.55 ns | 281.041 ns | 453.828 ns | 14,003.49 ns | 0.8698 | 0.2289 | - | 5539 B |
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Method,Job,AnalyzeLaunchVariance,EvaluateOverhead,MaxAbsoluteError,MaxRelativeError,MinInvokeCount,MinIterationTime,OutlierMode,Affinity,EnvironmentVariables,Jit,Platform,PowerPlanMode,Runtime,AllowVeryLargeObjects,Concurrent,CpuGroups,Force,HeapAffinitizeMask,HeapCount,NoAffinitize,RetainVm,Server,Arguments,BuildConfiguration,Clock,EngineFactory,NuGetReferences,Toolchain,IsMutator,InvocationCount,IterationCount,IterationTime,LaunchCount,MaxIterationCount,MaxWarmupIterationCount,MinIterationCount,MinWarmupIterationCount,RunStrategy,UnrollFactor,WarmupCount,DocumentCount,Mean,Error,StdDev,Median,Gen 0,Gen 1,Gen 2,Allocated
Project.DocumentIds,DefaultJob,False,Default,Default,Default,Default,Default,Default,111111111111111111111111111111111111111111111111,Empty,RyuJit,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 4.8,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,0,23.34 ns,0.494 ns,0.891 ns,22.91 ns,0.0000,0.0000,0.0000,0 B
Project.Documents,DefaultJob,False,Default,Default,Default,Default,Default,Default,111111111111111111111111111111111111111111111111,Empty,RyuJit,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 4.8,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,0,77.22 ns,0.537 ns,0.502 ns,77.31 ns,0.0772,0.0000,0.0000,128 B
Solution.WithDocumentText,DefaultJob,False,Default,Default,Default,Default,Default,Default,111111111111111111111111111111111111111111111111,Empty,RyuJit,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 4.8,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,0,14.60 ns,0.324 ns,0.690 ns,14.57 ns,0.0000,0.0000,0.0000,0 B
Project.DocumentIds,DefaultJob,False,Default,Default,Default,Default,Default,Default,111111111111111111111111111111111111111111111111,Empty,RyuJit,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 4.8,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,100,"8,159.41 ns",10.113 ns,8.965 ns,"8,157.79 ns",0.0305,0.0000,0.0000,72 B
Project.Documents,DefaultJob,False,Default,Default,Default,Default,Default,Default,111111111111111111111111111111111111111111111111,Empty,RyuJit,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 4.8,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,100,"16,356.60 ns",97.365 ns,91.076 ns,"16,382.64 ns",0.0916,0.0000,0.0000,201 B
Solution.WithDocumentText,DefaultJob,False,Default,Default,Default,Default,Default,Default,111111111111111111111111111111111111111111111111,Empty,RyuJit,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 4.8,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,100,"14,436.90 ns",355.846 ns,"1,015.248 ns","14,392.68 ns",0.8240,0.2136,0.0000,5285 B
Project.DocumentIds,DefaultJob,False,Default,Default,Default,Default,Default,Default,111111111111111111111111111111111111111111111111,Empty,RyuJit,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 4.8,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,10000,"863,988.25 ns","1,297.511 ns","1,213.693 ns","863,625.88 ns",0.0000,0.0000,0.0000,80 B
Project.Documents,DefaultJob,False,Default,Default,Default,Default,Default,Default,111111111111111111111111111111111111111111111111,Empty,RyuJit,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 4.8,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,10000,"1,861,933.16 ns","11,538.506 ns","10,793.125 ns","1,859,064.65 ns",0.0000,0.0000,0.0000,208 B
Solution.WithDocumentText,DefaultJob,False,Default,Default,Default,Default,Default,Default,111111111111111111111111111111111111111111111111,Empty,RyuJit,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 4.8,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,1,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,10000,"14,088.55 ns",281.041 ns,453.828 ns,"14,003.49 ns",0.8698,0.2289,0.0000,5539 B
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8' />
<title>IdeCoreBenchmarks.ProjectOperationBenchmarks.IterateDocuments-20210223-114823</title>

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }
</style>
</head>
<body>
<pre><code>
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
AMD Ryzen Threadripper 3960X, 1 CPU, 48 logical and 24 physical cores
[Host] : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT
DefaultJob : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT
</code></pre>
<pre><code></code></pre>

<table>
<thead><tr><th> Method</th><th>DocumentCount</th><th> Mean</th><th> Error</th><th> StdDev</th><th> Median</th><th>Gen 0</th><th>Gen 1</th><th>Gen 2</th><th>Allocated</th>
</tr>
</thead><tbody><tr><td>Project.DocumentIds</td><td>0</td><td>23.34 ns</td><td>0.494 ns</td><td>0.891 ns</td><td>22.91 ns</td><td>-</td><td>-</td><td>-</td><td>-</td>
</tr><tr><td>Project.Documents</td><td>0</td><td>77.22 ns</td><td>0.537 ns</td><td>0.502 ns</td><td>77.31 ns</td><td>0.0772</td><td>-</td><td>-</td><td>128 B</td>
</tr><tr><td>Solution.WithDocumentText</td><td>0</td><td>14.60 ns</td><td>0.324 ns</td><td>0.690 ns</td><td>14.57 ns</td><td>-</td><td>-</td><td>-</td><td>-</td>
</tr><tr><td>Project.DocumentIds</td><td>100</td><td>8,159.41 ns</td><td>10.113 ns</td><td>8.965 ns</td><td>8,157.79 ns</td><td>0.0305</td><td>-</td><td>-</td><td>72 B</td>
</tr><tr><td>Project.Documents</td><td>100</td><td>16,356.60 ns</td><td>97.365 ns</td><td>91.076 ns</td><td>16,382.64 ns</td><td>0.0916</td><td>-</td><td>-</td><td>201 B</td>
</tr><tr><td>Solution.WithDocumentText</td><td>100</td><td>14,436.90 ns</td><td>355.846 ns</td><td>1,015.248 ns</td><td>14,392.68 ns</td><td>0.8240</td><td>0.2136</td><td>-</td><td>5285 B</td>
</tr><tr><td>Project.DocumentIds</td><td>10000</td><td>863,988.25 ns</td><td>1,297.511 ns</td><td>1,213.693 ns</td><td>863,625.88 ns</td><td>-</td><td>-</td><td>-</td><td>80 B</td>
</tr><tr><td>Project.Documents</td><td>10000</td><td>1,861,933.16 ns</td><td>11,538.506 ns</td><td>10,793.125 ns</td><td>1,859,064.65 ns</td><td>-</td><td>-</td><td>-</td><td>208 B</td>
</tr><tr><td>Solution.WithDocumentText</td><td>10000</td><td>14,088.55 ns</td><td>281.041 ns</td><td>453.828 ns</td><td>14,003.49 ns</td><td>0.8698</td><td>0.2289</td><td>-</td><td>5539 B</td>
</tr></tbody></table>
</body>
</html>
6 changes: 3 additions & 3 deletions src/EditorFeatures/CSharpTest/Workspaces/WorkspaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ public async Task TestAddedSubmissionParseTreeHasEmptyFilePath()
// Check that a parse tree for a submission has an empty file path.
var tree1 = await workspace.CurrentSolution
.GetProjectState(project1.Id)
.GetDocumentState(document1.Id)
.DocumentStates.GetState(document1.Id)
.GetSyntaxTreeAsync(CancellationToken.None);
Assert.Equal("", tree1.FilePath);

// Check that a parse tree for a script does not have an empty file path.
var tree2 = await workspace.CurrentSolution
.GetProjectState(project2.Id)
.GetDocumentState(document2.Id)
.DocumentStates.GetState(document2.Id)
.GetSyntaxTreeAsync(CancellationToken.None);
Assert.Equal("a.csx", tree2.FilePath);
}
Expand Down Expand Up @@ -821,7 +821,7 @@ public async Task TestAnalyzerConfigFile_Properties()

Assert.Equal(1, project.Documents.Count());
Assert.Equal(1, project.AnalyzerConfigDocuments.Count());
Assert.Equal(1, project.State.AnalyzerConfigDocumentIds.Count());
Assert.Equal(1, project.State.AnalyzerConfigDocumentStates.Count);

var doc = project.GetDocument(analyzerConfigDoc.Id);
Assert.Null(doc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public int GetDocumentCount(Solution solution)
{
foreach (var projectState in solution.State.ProjectStates)
{
count += projectState.Value.DocumentIds.Count;
count += projectState.Value.DocumentStates.Count;
}

return count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private static void TryReportCompilationThrownAway(SolutionState solutionState,
// We log the number of syntax trees that have been parsed even if there was no compilation created yet
var projectState = solutionState.GetRequiredProjectState(projectId);
var parsedTrees = 0;
foreach (var documentState in projectState.DocumentStates.Values)
foreach (var documentState in projectState.DocumentStates.States)
{
if (documentState.TryGetSyntaxTree(out _))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public RemoveAnalyzerConfigDocumentUndoUnit(
}

protected override IReadOnlyList<DocumentId> GetDocumentIds(Project fromProject)
=> fromProject.State.AnalyzerConfigDocumentIds.AsImmutable();
=> fromProject.State.AnalyzerConfigDocumentStates.Ids;

protected override TextDocument? GetDocument(Solution currentSolution)
=> currentSolution.GetAnalyzerConfigDocument(this.DocumentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ private static async Task<Checksum> ComputeSourceSymbolsChecksumAsync(ProjectSta

// Order the documents by FilePath. Default ordering in the RemoteWorkspace is
// to be ordered by Guid (which is not consistent across VS sessions).
var textChecksumsTasks = projectState.DocumentStates.OrderBy(d => d.Value.FilePath, StringComparer.Ordinal).Select(async d =>
var textChecksumsTasks = projectState.DocumentStates.States.OrderBy(state => state.FilePath, StringComparer.Ordinal).Select(async state =>
{
var documentStateChecksum = await d.Value.GetStateChecksumsAsync(cancellationToken).ConfigureAwait(false);
var documentStateChecksum = await state.GetStateChecksumsAsync(cancellationToken).ConfigureAwait(false);
return documentStateChecksum.Text;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public IEnumerator<Checksum> GetEnumerator()
IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();

internal static async Task FindAsync<TKey, TValue>(
ImmutableSortedDictionary<TKey, TValue> documentStates,
internal static async Task FindAsync<TState>(
TextDocumentStates<TState> documentStates,
HashSet<Checksum> searchingChecksumsLeft,
Dictionary<Checksum, object> result,
CancellationToken cancellationToken) where TValue : TextDocumentState
CancellationToken cancellationToken) where TState : TextDocumentState
{
foreach (var (_, state) in documentStates)
foreach (var state in documentStates.States)
{
Contract.ThrowIfFalse(state.TryGetStateChecksums(out var stateChecksums));

Expand Down
Loading