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

Provide a new implementation of IPersistenceService that sits on top of the new platform 'cloud cache' system. #50762

Merged
141 commits merged into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from 132 commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
bf62038
Throw if we can't successfully make a db
CyrusNajmabadi Jan 25, 2021
b7711fd
Print storage location
CyrusNajmabadi Jan 25, 2021
6e8f1aa
Add package reference
CyrusNajmabadi Jan 25, 2021
5a1bd0b
Working test
CyrusNajmabadi Jan 25, 2021
0ca6473
Update references
CyrusNajmabadi Jan 26, 2021
cc69cba
Merge branch 'asyncStorage' into cloudCache
CyrusNajmabadi Jan 26, 2021
ae267e7
Start fleshing out vs side
CyrusNajmabadi Jan 26, 2021
d6ba7b1
Merge branch 'asyncStorage' into cloudCache
CyrusNajmabadi Jan 26, 2021
fb3a0a3
Merge branch 'noChecksum' into cloudCache
CyrusNajmabadi Jan 26, 2021
8bc7b8e
Continued work
CyrusNajmabadi Jan 26, 2021
7ce39e0
Merge branch 'asyncStorage' into cloudCache
CyrusNajmabadi Jan 26, 2021
91527af
Everything compiles
CyrusNajmabadi Jan 26, 2021
4169f79
Rejigger
CyrusNajmabadi Jan 26, 2021
60c788c
Move code down
CyrusNajmabadi Jan 27, 2021
66cca33
VS side
CyrusNajmabadi Jan 27, 2021
33b4ed7
Update benchmark
CyrusNajmabadi Jan 27, 2021
92d018a
Perf work
CyrusNajmabadi Jan 27, 2021
7c734c0
Working
CyrusNajmabadi Jan 27, 2021
e75cc28
Merge remote-tracking branch 'upstream/master' into cloudCache
CyrusNajmabadi Jan 27, 2021
e99f17e
testing
CyrusNajmabadi Jan 27, 2021
e4b906b
Merge branch 'cloudCache' of https://github.com/CyrusNajmabadi/roslyn…
CyrusNajmabadi Jan 27, 2021
8799e80
Merge branch 'newSqlite' into cloudCache
CyrusNajmabadi Jan 27, 2021
100f085
Switch to sqlite
CyrusNajmabadi Jan 27, 2021
080d73c
Use same comparer as VSdoes
CyrusNajmabadi Jan 27, 2021
eae6643
Use reader
CyrusNajmabadi Jan 28, 2021
417eeaa
Add tests
CyrusNajmabadi Jan 28, 2021
c2d57b6
Fix dimensions
CyrusNajmabadi Jan 28, 2021
6d506fb
Fix test harness
CyrusNajmabadi Jan 28, 2021
2f3e7de
Merge branch 'storageChecksum' into cloudCache
CyrusNajmabadi Jan 28, 2021
ab0ac45
New key system
CyrusNajmabadi Jan 28, 2021
024654d
Merge branch 'storageChecksum' into cloudCache
CyrusNajmabadi Jan 28, 2021
e759fc5
Fallout
CyrusNajmabadi Jan 28, 2021
d482e6a
Merge remote-tracking branch 'upstream/master' into cloudCache
CyrusNajmabadi Jan 29, 2021
2da3576
Upgrade to latest
CyrusNajmabadi Jan 29, 2021
661d36c
Add message
CyrusNajmabadi Feb 1, 2021
70583a7
Buffer reads
CyrusNajmabadi Feb 1, 2021
237e39f
latest andrew
CyrusNajmabadi Feb 2, 2021
f8ed75b
update benchmarks
CyrusNajmabadi Feb 3, 2021
5c89b8e
Get building
CyrusNajmabadi Feb 8, 2021
66c89de
Merge remote-tracking branch 'upstream/master' into cloudCache
CyrusNajmabadi Feb 9, 2021
781f95d
Bmarks
CyrusNajmabadi Feb 9, 2021
393344d
Merge branch 'master' into cloudCache
CyrusNajmabadi Feb 12, 2021
d94d1de
import properly
CyrusNajmabadi Feb 12, 2021
845d817
Use latest version
CyrusNajmabadi Feb 12, 2021
249c654
Remove benchmarks
CyrusNajmabadi Feb 12, 2021
5c3e873
Update NuGet.config
CyrusNajmabadi Feb 12, 2021
b601fe3
Update eng/Versions.props
CyrusNajmabadi Feb 12, 2021
063d2e0
Add docs
CyrusNajmabadi Feb 13, 2021
e0aab47
Add docs
CyrusNajmabadi Feb 13, 2021
53e8cba
Remove unused code.
CyrusNajmabadi Feb 13, 2021
33c91ce
Set default back to sqlite
CyrusNajmabadi Feb 13, 2021
c3c1cd8
Add comment
CyrusNajmabadi Feb 13, 2021
af5d8e0
Update test
CyrusNajmabadi Feb 13, 2021
a5797a3
Merge remote-tracking branch 'upstream/master' into cloudCache
CyrusNajmabadi Feb 18, 2021
6c46b36
rejigger test
CyrusNajmabadi Feb 18, 2021
2fd3b81
rejigger test
CyrusNajmabadi Feb 18, 2021
fd0edcf
Merge remote-tracking branch 'upstream/master-vs-deps' into cloudCache
CyrusNajmabadi Feb 18, 2021
6cd3866
Merge branch 'cloudCache' of https://github.com/CyrusNajmabadi/roslyn…
CyrusNajmabadi Feb 18, 2021
cd7c7f6
Update version
CyrusNajmabadi Feb 18, 2021
81478ad
Merge branch 'cloudCache' of https://github.com/CyrusNajmabadi/roslyn…
CyrusNajmabadi Feb 18, 2021
8ae0851
Merge branch 'removeInternalDep' into cloudCache
CyrusNajmabadi Feb 18, 2021
40fc9b6
Remove
CyrusNajmabadi Feb 18, 2021
19741c2
Fixup
CyrusNajmabadi Feb 18, 2021
87aaab5
Async dispose
CyrusNajmabadi Feb 19, 2021
2eba470
Merge branch 'asyncDisposeStorage' into cloudCache
CyrusNajmabadi Feb 19, 2021
7f58d01
Tweak
CyrusNajmabadi Feb 19, 2021
e43b37d
Update version
CyrusNajmabadi Feb 23, 2021
228347b
Remove unused usings
CyrusNajmabadi Feb 23, 2021
c45e4b6
Merge remote-tracking branch 'upstream/master-vs-deps' into cloudCache
CyrusNajmabadi Feb 23, 2021
1d922ec
Merge remote-tracking branch 'origin/asyncDisposeStorage' into cloudC…
CyrusNajmabadi Feb 23, 2021
4cd5fda
merge conflict
CyrusNajmabadi Feb 23, 2021
d30bae7
Merge remote-tracking branch 'upstream/master' into cloudCache
CyrusNajmabadi Feb 23, 2021
3cc4fcf
Merge remote-tracking branch 'upstream/master-vs-deps' into cloudCache
CyrusNajmabadi Feb 23, 2021
bf3b5e2
Share code
CyrusNajmabadi Feb 23, 2021
8c47c1f
Share code
CyrusNajmabadi Feb 23, 2021
960d9fb
Share code
CyrusNajmabadi Feb 23, 2021
1056738
Update src/Tools/IdeCoreBenchmarks/Program.cs
CyrusNajmabadi Feb 23, 2021
0e8b2f5
Move
CyrusNajmabadi Feb 23, 2021
f6ca210
Merge branch 'cloudCache' of https://github.com/CyrusNajmabadi/roslyn…
CyrusNajmabadi Feb 23, 2021
3e28280
Share more test code
CyrusNajmabadi Feb 23, 2021
1d8543c
Add comment
CyrusNajmabadi Feb 23, 2021
289ff28
Add comments
CyrusNajmabadi Feb 23, 2021
6eff869
Update comment
CyrusNajmabadi Feb 23, 2021
cefb2c6
Remove option
CyrusNajmabadi Feb 23, 2021
f8a130d
Remove unnecessary call
CyrusNajmabadi Feb 23, 2021
50a817b
Use helper
CyrusNajmabadi Feb 23, 2021
826c5ec
Use proper comparer
CyrusNajmabadi Feb 23, 2021
2cab685
Add comment
CyrusNajmabadi Feb 23, 2021
917ceba
Narrow scope of field
CyrusNajmabadi Feb 23, 2021
9175866
Share code
CyrusNajmabadi Feb 23, 2021
27204a3
Add comment
CyrusNajmabadi Feb 23, 2021
c133ba7
Update version
CyrusNajmabadi Feb 23, 2021
711990e
Update mock
CyrusNajmabadi Feb 23, 2021
8bb9f24
Merge remote-tracking branch 'upstream/master' into cloudCache
CyrusNajmabadi Feb 24, 2021
f312c96
Build
CyrusNajmabadi Feb 24, 2021
b987f2e
Merge remote-tracking branch 'upstream/master-vs-deps' into cloudCache
CyrusNajmabadi Feb 24, 2021
2d92fad
Merge remote-tracking branch 'upstream/master-vs-deps' into cloudCache
CyrusNajmabadi Feb 25, 2021
e16117b
Merge remote-tracking branch 'upstream/master-vs-deps' into cloudCache
CyrusNajmabadi Mar 2, 2021
ff05577
Rename
CyrusNajmabadi Mar 2, 2021
2cc1213
Update comment
CyrusNajmabadi Mar 2, 2021
3b3068b
Update src/Workspaces/Core/Portable/Storage/CloudCache/ProjectCacheCo…
CyrusNajmabadi Mar 3, 2021
e1c6767
Update src/Workspaces/Core/Portable/Storage/CloudCache/CloudCachePers…
CyrusNajmabadi Mar 3, 2021
f19459a
Update src/Workspaces/Core/Portable/Storage/CloudCache/ProjectCacheCo…
CyrusNajmabadi Mar 3, 2021
d10adeb
Update src/VisualStudio/CSharp/Test/PersistentStorage/AbstractPersist…
CyrusNajmabadi Mar 3, 2021
ad72675
Update src/VisualStudio/Core/Def/Storage/VisualStudioCloudCacheServic…
CyrusNajmabadi Mar 3, 2021
23dfcd6
Merge remote-tracking branch 'upstream/master-vs-deps' into cloudCache
CyrusNajmabadi Mar 3, 2021
5e19d30
Renames
CyrusNajmabadi Mar 3, 2021
b73b763
Update comments
CyrusNajmabadi Mar 3, 2021
3f4101d
Renames
CyrusNajmabadi Mar 3, 2021
bc59fe2
Change enum value
CyrusNajmabadi Mar 3, 2021
a258e12
Add docs
CyrusNajmabadi Mar 3, 2021
c870298
remove check
CyrusNajmabadi Mar 3, 2021
ff1f9c9
remove check
CyrusNajmabadi Mar 3, 2021
efb818a
Renames
CyrusNajmabadi Mar 3, 2021
35e671a
Add comment
CyrusNajmabadi Mar 3, 2021
daf7418
Add docs
CyrusNajmabadi Mar 3, 2021
4a7544a
Spelling
CyrusNajmabadi Mar 3, 2021
bd08648
Add helper
CyrusNajmabadi Mar 3, 2021
ea2c17b
Share code
CyrusNajmabadi Mar 3, 2021
99a961e
Update
CyrusNajmabadi Mar 3, 2021
8591250
Add comment
CyrusNajmabadi Mar 3, 2021
fdf7348
Rename
CyrusNajmabadi Mar 3, 2021
5b4a533
Merge remote-tracking branch 'upstream/main-vs-deps' into cloudCache
CyrusNajmabadi Mar 4, 2021
de49957
Remove state objects.
CyrusNajmabadi Mar 4, 2021
25b1b25
mef work
CyrusNajmabadi Mar 4, 2021
f359dca
Proper mef
CyrusNajmabadi Mar 4, 2021
f85e575
Go back to sqlite
CyrusNajmabadi Mar 4, 2021
96054a5
Merge branch 'cloudCache' of https://github.com/CyrusNajmabadi/roslyn…
CyrusNajmabadi Mar 4, 2021
8f3bf8b
Merge remote-tracking branch 'upstream/main-vs-deps' into cloudCache
CyrusNajmabadi Mar 5, 2021
ebf3245
Rename
CyrusNajmabadi Mar 5, 2021
d0c7474
Clarity
CyrusNajmabadi Mar 5, 2021
ea2576b
Share code
CyrusNajmabadi Mar 5, 2021
3afb7ce
move all logic up to VS layer
CyrusNajmabadi Mar 5, 2021
5487582
Delete
CyrusNajmabadi Mar 5, 2021
09735a0
remote side
CyrusNajmabadi Mar 6, 2021
8163b52
Tweak
CyrusNajmabadi Mar 6, 2021
ec1bfdf
Share more code
CyrusNajmabadi Mar 6, 2021
1ff6721
perf code
CyrusNajmabadi Mar 6, 2021
1491a76
Merge remote-tracking branch 'upstream/main-vs-deps' into cloudCache
CyrusNajmabadi Mar 8, 2021
acbaa47
Fix
CyrusNajmabadi Mar 8, 2021
89e1b51
Fix
CyrusNajmabadi Mar 8, 2021
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
5 changes: 3 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<MicrosoftBuildTasksCoreVersion>$(MicrosoftBuildPackagesVersion)</MicrosoftBuildTasksCoreVersion>
<NuGetVisualStudioContractsVersion>5.7.0</NuGetVisualStudioContractsVersion>
<!-- This is working around Microsoft.VisualStudio.Shell.15.0 having an unstated conflicting reference on this with NuGet.VisualStudio.Contracts -->
<MicrosoftVisualStudioRpcContractsVersion>16.9.63</MicrosoftVisualStudioRpcContractsVersion>
<MicrosoftVisualStudioRpcContractsVersion>16.10.11-alpha</MicrosoftVisualStudioRpcContractsVersion>
<!--
Since the Microsoft.CodeAnalysis.Analyzers package is a public dependency of our NuGet
packages we will keep it untied to the RoslynDiagnosticsNugetPackageVersion we use for
Expand Down Expand Up @@ -116,6 +116,7 @@
<MicrosoftServiceHubClientVersion>2.7.339</MicrosoftServiceHubClientVersion>
<MicrosoftServiceHubFrameworkVersion>2.7.339</MicrosoftServiceHubFrameworkVersion>
<MicrosoftVisualBasicVersion>10.1.0</MicrosoftVisualBasicVersion>
<MicrosoftVisualStudioCacheVersion>16.10.40-alpha</MicrosoftVisualStudioCacheVersion>
<MicrosoftVisualStudioCallHierarchyPackageDefinitionsVersion>15.8.27812-alpha</MicrosoftVisualStudioCallHierarchyPackageDefinitionsVersion>
<MicrosoftVisualStudioCodeAnalysisSdkUIVersion>15.8.27812-alpha</MicrosoftVisualStudioCodeAnalysisSdkUIVersion>
<MicrosoftVisualStudioComponentModelHostVersion>16.9.184-preview</MicrosoftVisualStudioComponentModelHostVersion>
Expand Down Expand Up @@ -216,7 +217,7 @@
<SystemIOFileSystemVersion>4.3.0</SystemIOFileSystemVersion>
<SystemIOFileSystemPrimitivesVersion>4.3.0</SystemIOFileSystemPrimitivesVersion>
<SystemIOPipesAccessControlVersion>4.5.1</SystemIOPipesAccessControlVersion>
<SystemIOPipelinesVersion>5.0.0</SystemIOPipelinesVersion>
<SystemIOPipelinesVersion>5.0.1</SystemIOPipelinesVersion>
<SystemManagementVersion>5.0.0-preview.8.20407.11</SystemManagementVersion>
<SystemMemoryVersion>4.5.4</SystemMemoryVersion>
<SystemResourcesExtensionsVersion>4.7.1</SystemResourcesExtensionsVersion>
Expand Down
9 changes: 3 additions & 6 deletions src/Tools/IdeBenchmarks/SQLitePersistentStorageBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,14 @@ public void GlobalSetup()

// Explicitly choose the sqlite db to test.
_workspace.TryApplyChanges(_workspace.CurrentSolution.WithOptions(_workspace.Options
.WithChangedOption(StorageOptions.Database, StorageDatabase.SQLite)));
.WithChangedOption(StorageOptions.Database, StorageDatabase.SQLite)
.WithChangedOption(StorageOptions.DatabaseMustSucceed, true)));

var connectionPoolService = _workspace.ExportProvider.GetExportedValue<SQLiteConnectionPoolService>();
_storageService = new SQLitePersistentStorageService(connectionPoolService, new LocationService());
_storageService = new SQLitePersistentStorageService(_workspace.Options, connectionPoolService, new LocationService());

var solution = _workspace.CurrentSolution;
_storage = _storageService.GetStorageWorkerAsync(_workspace, SolutionKey.ToSolutionKey(solution), solution, CancellationToken.None).AsTask().GetAwaiter().GetResult();
if (_storage == NoOpPersistentStorage.Instance)
{
throw new InvalidOperationException("We didn't properly get the sqlite storage instance.");
}

Console.WriteLine("Storage type: " + _storage.GetType());
_document = _workspace.CurrentSolution.Projects.Single().Documents.Single();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Storage;
using Microsoft.CodeAnalysis.UnitTests.WorkspaceServices.Mocks;
using Microsoft.VisualStudio.Cache;
using Microsoft.VisualStudio.LanguageServices.Storage;
using Microsoft.VisualStudio.RpcContracts.Caching;

namespace CloudCache
{
[ExportWorkspaceService(typeof(IRoslynCloudCacheServiceProvider), ServiceLayer.Host), Shared]
internal class IdeCoreBenchmarksCloudCacheServiceProvider : AbstractMockRoslynCloudCacheServiceProvider
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public IdeCoreBenchmarksCloudCacheServiceProvider()
: base(@"C:\github\roslyn")
{
Console.WriteLine($"Instantiated {nameof(IdeCoreBenchmarksCloudCacheServiceProvider)}");
}

protected override IRoslynCloudCacheService CreateService(CacheService cacheService)
=> new IdeCoreBenchmarksCloudCacheService(cacheService);

private class IdeCoreBenchmarksCloudCacheService : AbstractCloudCacheService
{
public IdeCoreBenchmarksCloudCacheService(ICacheService cacheService) : base(cacheService)
{
}

public override void Dispose()
{
if (this.CacheService is IAsyncDisposable asyncDisposable)
{
asyncDisposable.DisposeAsync().AsTask().Wait();
}
else if (this.CacheService is IDisposable disposable)
{
disposable.Dispose();
}
}
}
}
}
149 changes: 81 additions & 68 deletions src/Tools/IdeCoreBenchmarks/FindReferencesBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
#nullable disable

using System;
Copy link
Member Author

Choose a reason for hiding this comment

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

benchmark code is effectively a way for me to quickly test things liek FindRefs and NavTo on different DBs, comparing the results. they're not really productino code, and more a scratch pad to answer questions quickly on a real world codebase.

using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using AnalyzerRunner;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnosers;
using Microsoft.Build.Locator;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.MSBuild;
using Microsoft.CodeAnalysis.Storage;

Expand All @@ -23,77 +27,86 @@ namespace IdeCoreBenchmarks
[MemoryDiagnoser]
public class FindReferencesBenchmarks
{
private readonly string _solutionPath;

private MSBuildWorkspace _workspace;

public FindReferencesBenchmarks()
{
var roslynRoot = Environment.GetEnvironmentVariable(Program.RoslynRootPathEnvVariableName);
_solutionPath = Path.Combine(roslynRoot, @"C:\github\roslyn\Roslyn.sln");

if (!File.Exists(_solutionPath))
throw new ArgumentException("Couldn't find Roslyn.sln");

Console.Write("Found roslyn.sln: " + Process.GetCurrentProcess().Id);
}

[GlobalSetup]
public void Setup()
{
_workspace = AnalyzerRunnerHelper.CreateWorkspace();
if (_workspace == null)
throw new ArgumentException("Couldn't create workspace");

_workspace.TryApplyChanges(_workspace.CurrentSolution.WithOptions(_workspace.Options
.WithChangedOption(StorageOptions.Database, StorageDatabase.SQLite)));

Console.WriteLine("Opening roslyn. Attach to: " + Process.GetCurrentProcess().Id);

var start = DateTime.Now;
_ = _workspace.OpenSolutionAsync(_solutionPath, progress: null, CancellationToken.None).Result;
Console.WriteLine("Finished opening roslyn: " + (DateTime.Now - start));

// Force a storage instance to be created. This makes it simple to go examine it prior to any operations we
// perform, including seeing how big the initial string table is.
var storageService = _workspace.Services.GetService<IPersistentStorageService>();
if (storageService == null)
throw new ArgumentException("Couldn't get storage service");

using var storage = storageService.GetStorageAsync(_workspace.CurrentSolution, CancellationToken.None).AsTask().GetAwaiter().GetResult();
}

[GlobalCleanup]
public void Cleanup()
{
_workspace?.Dispose();
_workspace = null;
}

[Benchmark]
public async Task RunFindReferences()
{
var solution = _workspace.CurrentSolution;

// There might be multiple projects with this name. That's ok. FAR goes and finds all the linked-projects
// anyways to perform the search on all the equivalent symbols from them. So the end perf cost is the
// same.
var project = solution.Projects.First(p => p.AssemblyName == "Microsoft.CodeAnalysis.CSharp");

var start = DateTime.Now;
var compilation = await project.GetCompilationAsync();
Console.WriteLine("Time to get first compilation: " + (DateTime.Now - start));
var type = compilation.GetTypeByMetadataName("Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.LanguageParser");
if (type == null)
throw new Exception("Couldn't find type");

start = DateTime.Now;
var references = await SymbolFinder.FindReferencesAsync(type, solution);
Console.WriteLine("Time to find-refs: " + (DateTime.Now - start));
var refList = references.ToList();
Console.WriteLine($"References count: {refList.Count}");
var locations = refList.SelectMany(r => r.Locations).ToList();
Console.WriteLine($"Locations count: {locations.Count}");
try
{
// QueryVisualStudioInstances returns Visual Studio installations on .NET Framework, and .NET Core SDK
// installations on .NET Core. We use the one with the most recent version.
var msBuildInstance = MSBuildLocator.QueryVisualStudioInstances().OrderByDescending(x => x.Version).First();

MSBuildLocator.RegisterInstance(msBuildInstance);

var roslynRoot = Environment.GetEnvironmentVariable(Program.RoslynRootPathEnvVariableName);
var solutionPath = Path.Combine(roslynRoot, @"C:\github\roslyn\Compilers.sln");

if (!File.Exists(solutionPath))
throw new ArgumentException("Couldn't find Compilers.sln");

Console.Write("Found Compilers.sln: " + Process.GetCurrentProcess().Id);

var assemblies = MSBuildMefHostServices.DefaultAssemblies
.Add(typeof(AnalyzerRunnerHelper).Assembly)
.Add(typeof(FindReferencesBenchmarks).Assembly);
var services = MefHostServices.Create(assemblies);

var workspace = MSBuildWorkspace.Create(new Dictionary<string, string>
{
// Use the latest language version to force the full set of available analyzers to run on the project.
{ "LangVersion", "9.0" },
}, services);

if (workspace == null)
throw new ArgumentException("Couldn't create workspace");

workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(workspace.Options
.WithChangedOption(StorageOptions.Database, StorageDatabase.SQLite)
.WithChangedOption(StorageOptions.DatabaseMustSucceed, true)));
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved

Console.WriteLine("Opening roslyn. Attach to: " + Process.GetCurrentProcess().Id);

var start = DateTime.Now;
var solution = workspace.OpenSolutionAsync(solutionPath, progress: null, CancellationToken.None).Result;
Console.WriteLine("Finished opening roslyn: " + (DateTime.Now - start));

// Force a storage instance to be created. This makes it simple to go examine it prior to any operations we
// perform, including seeing how big the initial string table is.
var storageService = workspace.Services.GetService<IPersistentStorageService>();
if (storageService == null)
throw new ArgumentException("Couldn't get storage service");

using (var storage = await storageService.GetStorageAsync(workspace.CurrentSolution, CancellationToken.None))
{
Console.WriteLine();
}

// There might be multiple projects with this name. That's ok. FAR goes and finds all the linked-projects
// anyways to perform the search on all the equivalent symbols from them. So the end perf cost is the
// same.
var project = solution.Projects.First(p => p.AssemblyName == "Microsoft.CodeAnalysis");

start = DateTime.Now;
var compilation = await project.GetCompilationAsync();
Console.WriteLine("Time to get first compilation: " + (DateTime.Now - start));
var type = compilation.GetTypeByMetadataName("Microsoft.CodeAnalysis.SyntaxToken");
if (type == null)
throw new Exception("Couldn't find type");

Console.WriteLine("Starting find-refs");
start = DateTime.Now;
var references = await SymbolFinder.FindReferencesAsync(type, solution);
Console.WriteLine("Time to find-refs: " + (DateTime.Now - start));
var refList = references.ToList();
Console.WriteLine($"References count: {refList.Count}");
var locations = refList.SelectMany(r => r.Locations).ToList();
Console.WriteLine($"Locations count: {locations.Count}");
}
catch (ReflectionTypeLoadException ex)
{
foreach (var ex2 in ex.LoaderExceptions)
Console.WriteLine(ex2);
}
}
}
}
19 changes: 19 additions & 0 deletions src/Tools/IdeCoreBenchmarks/IdeCoreBenchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,32 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<!-- Automatically generate the necessary assembly binding redirects -->
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<LangVersion>9</LangVersion>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\VisualStudio\Core\Def\Storage\AbstractCloudCacheService.cs" Link="CloudCache\AbstractCloudCacheService.cs" />
<Compile Include="..\..\VisualStudio\CSharp\Test\PersistentStorage\Mocks\AbstractMockRoslynCloudCacheServiceProvider.cs" Link="CloudCache\AbstractMockRoslynCloudCacheServiceProvider.cs" />
<Compile Include="..\..\VisualStudio\CSharp\Test\PersistentStorage\Mocks\AuthorizationServiceMock.cs" Link="CloudCache\AuthorizationServiceMock.cs" />
<Compile Include="..\..\VisualStudio\CSharp\Test\PersistentStorage\Mocks\FileSystemServiceMock.cs" Link="CloudCache\FileSystemServiceMock.cs" />
<Compile Include="..\..\VisualStudio\CSharp\Test\PersistentStorage\Mocks\ServiceBrokerMock.cs" Link="CloudCache\ServiceBrokerMock.cs" />
<Compile Include="..\..\VisualStudio\CSharp\Test\PersistentStorage\Mocks\SolutionServiceMock.cs" Link="CloudCache\SolutionServiceMock.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNetVersion)" />
<!-- This is to avoid a version conflict during build -->
<PackageReference Include="System.CodeDom" Version="$(SystemCodeDomVersion)" />
<PackageReference Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildFrameworkVersion)" ExcludeAssets="Runtime" PrivateAssets="All" />

<PackageReference Include="Microsoft.VisualStudio.Composition" Version="$(MicrosoftVisualStudioCompositionVersion)" />
<PackageReference Include="Microsoft.Build.Locator" Version="$(MicrosoftBuildLocatorVersion)" />
<PackageReference Include="System.Buffers" Version="$(SystemBuffersVersion)" />
<PackageReference Include="System.ComponentModel.Composition" Version="$(SystemComponentModelCompositionVersion)" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="$(SystemThreadingTasksDataflowVersion)" />
<PackageReference Include="Microsoft.Win32.Registry" Version="$(MicrosoftWin32RegistryVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Cache" Version="$(MicrosoftVisualStudioCacheVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading