From 68fea5b9c2f817b37499e915404533b5aa3c2031 Mon Sep 17 00:00:00 2001 From: John Luo Date: Wed, 27 May 2020 16:05:14 -0700 Subject: [PATCH] Remove files that should stay in aspnetcore-tooling Also address some lingering feedback --- .azure/pipelines/ci.yml | 2 +- ...rosoft.AspNetCore.Razor.Performance.csproj | 27 +-- .../BackgroundCodeGenerationBenchmark.cs | 53 ------ .../ProjectSystem/ProjectLoadBenchmark.cs | 30 ---- .../ProjectSnapshotManagerBenchmarkBase.cs | 155 ------------------ .../TagHelperSerializationBenchmark.cs | 55 ------- src/Razor/test/Directory.Build.props | 7 - ...AspNetCore.Razor.Test.ComponentShim.csproj | 1 - 8 files changed, 5 insertions(+), 325 deletions(-) delete mode 100644 src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/BackgroundCodeGenerationBenchmark.cs delete mode 100644 src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/ProjectLoadBenchmark.cs delete mode 100644 src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs delete mode 100644 src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/TagHelperSerializationBenchmark.cs delete mode 100644 src/Razor/test/Directory.Build.props diff --git a/.azure/pipelines/ci.yml b/.azure/pipelines/ci.yml index c728558302..2f171d5b4c 100644 --- a/.azure/pipelines/ci.yml +++ b/.azure/pipelines/ci.yml @@ -149,7 +149,7 @@ stages: $(_InternalRuntimeDownloadArgs) displayName: Build x86 - # This is in a separate build step with to workaround MAX_PATH limitations - https://github.com/Microsoft/msbuild/issues/53 + # This is in a separate build step with -forceCoreMsbuild to workaround MAX_PATH limitations - https://github.com/Microsoft/msbuild/issues/53 - script: .\src\SiteExtensions\build.cmd -ci -nobl diff --git a/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/Microsoft.AspNetCore.Razor.Performance.csproj b/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/Microsoft.AspNetCore.Razor.Performance.csproj index e38908b067..0310ef63a2 100644 --- a/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/Microsoft.AspNetCore.Razor.Performance.csproj +++ b/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/Microsoft.AspNetCore.Razor.Performance.csproj @@ -10,32 +10,13 @@ - - + + + - - Serialization\%(FileName)%(Extension) - - - TestServices\%(FileName)%(Extension) - - - TestServices\%(FileName)%(Extension) - - - TestServices\%(FileName)%(Extension) - - - TestServices\%(FileName)%(Extension) - - - - - - - + diff --git a/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/BackgroundCodeGenerationBenchmark.cs b/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/BackgroundCodeGenerationBenchmark.cs deleted file mode 100644 index db9c09aa4a..0000000000 --- a/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/BackgroundCodeGenerationBenchmark.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Threading.Tasks; -using BenchmarkDotNet.Attributes; -using Microsoft.CodeAnalysis.Razor.ProjectSystem; - -namespace Microsoft.AspNetCore.Razor.Performance -{ - public class BackgroundCodeGenerationBenchmark : ProjectSnapshotManagerBenchmarkBase - { - [IterationSetup] - public void Setup() - { - SnapshotManager = CreateProjectSnapshotManager(); - SnapshotManager.ProjectAdded(HostProject); - SnapshotManager.Changed += SnapshotManager_Changed; - } - - [IterationCleanup] - public void Cleanup() - { - SnapshotManager.Changed -= SnapshotManager_Changed; - - Tasks.Clear(); - } - - private List Tasks { get; } = new List(); - - private DefaultProjectSnapshotManager SnapshotManager { get; set; } - - [Benchmark(Description = "Generates the code for 100 files", OperationsPerInvoke = 100)] - public async Task BackgroundCodeGeneration_Generate100Files() - { - for (var i = 0; i < Documents.Length; i++) - { - SnapshotManager.DocumentAdded(HostProject, Documents[i], TextLoaders[i % 4]); - } - - await Task.WhenAll(Tasks); - } - - private void SnapshotManager_Changed(object sender, ProjectChangeEventArgs e) - { - // The real work happens here. - var project = SnapshotManager.GetLoadedProject(e.ProjectFilePath); - var document = project.GetDocument(e.DocumentFilePath); - - Tasks.Add(document.GetGeneratedOutputAsync()); - } - } -} diff --git a/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/ProjectLoadBenchmark.cs b/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/ProjectLoadBenchmark.cs deleted file mode 100644 index 73403ed515..0000000000 --- a/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/ProjectLoadBenchmark.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using BenchmarkDotNet.Attributes; -using Microsoft.CodeAnalysis.Razor.ProjectSystem; - -namespace Microsoft.AspNetCore.Razor.Performance -{ - public class ProjectLoadBenchmark : ProjectSnapshotManagerBenchmarkBase - { - [IterationSetup] - public void Setup() - { - SnapshotManager = CreateProjectSnapshotManager(); - } - - private DefaultProjectSnapshotManager SnapshotManager { get; set; } - - [Benchmark(Description = "Initializes a project and 100 files", OperationsPerInvoke = 100)] - public void ProjectLoad_AddProjectAnd100Files() - { - SnapshotManager.ProjectAdded(HostProject); - - for (var i= 0; i < Documents.Length; i++) - { - SnapshotManager.DocumentAdded(HostProject, Documents[i], TextLoaders[i % 4]); - } - } - } -} diff --git a/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs b/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs deleted file mode 100644 index ff1fcee00d..0000000000 --- a/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Razor.Extensions; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Razor; -using Microsoft.CodeAnalysis.Razor.ProjectSystem; -using Microsoft.CodeAnalysis.Razor.Serialization; -using Microsoft.CodeAnalysis.Text; -using Microsoft.VisualStudio.LanguageServices.Razor.Serialization; -using Newtonsoft.Json; - -namespace Microsoft.AspNetCore.Razor.Performance -{ - public class ProjectSnapshotManagerBenchmarkBase - { - public ProjectSnapshotManagerBenchmarkBase() - { - var current = new DirectoryInfo(AppContext.BaseDirectory); - while (current != null && !File.Exists(Path.Combine(current.FullName, "Razor.sln"))) - { - current = current.Parent; - } - - var root = current; - var projectRoot = Path.Combine(root.FullName, "test", "testapps", "LargeProject"); - - HostProject = new HostProject(Path.Combine(projectRoot, "LargeProject.csproj"), FallbackRazorConfiguration.MVC_2_1, rootNamespace: null); - - TextLoaders = new TextLoader[4]; - for (var i = 0; i < 4; i++) - { - var filePath = Path.Combine(projectRoot, "Views", "Home", $"View00{i % 4}.cshtml"); - var text = SourceText.From(filePath, encoding: null); - TextLoaders[i] = TextLoader.From(TextAndVersion.Create(text, VersionStamp.Create())); - } - - Documents = new HostDocument[100]; - for (var i = 0; i < Documents.Length; i++) - { - var filePath = Path.Combine(projectRoot, "Views", "Home", $"View00{i % 4}.cshtml"); - Documents[i] = new HostDocument(filePath, $"/Views/Home/View00{i}.cshtml", FileKinds.Legacy); - } - - var tagHelpers = Path.Combine(root.FullName, "benchmarks", "Microsoft.AspNetCore.Razor.Performance", "taghelpers.json"); - TagHelperResolver = new StaticTagHelperResolver(ReadTagHelpers(tagHelpers)); - } - - internal HostProject HostProject { get; } - - internal HostDocument[] Documents { get; } - - internal TextLoader[] TextLoaders { get; } - - internal TagHelperResolver TagHelperResolver { get; } - - internal DefaultProjectSnapshotManager CreateProjectSnapshotManager() - { - var services = TestServices.Create( - new IWorkspaceService[] - { - TagHelperResolver, - new StaticProjectSnapshotProjectEngineFactory(), - }, - new ILanguageService[] - { - }); - - return new DefaultProjectSnapshotManager( - new TestForegroundDispatcher(), - new TestErrorReporter(), - Array.Empty(), - new AdhocWorkspace(services)); - } - - private static IReadOnlyList ReadTagHelpers(string filePath) - { - var serializer = new JsonSerializer(); - serializer.Converters.Add(new RazorDiagnosticJsonConverter()); - serializer.Converters.Add(new TagHelperDescriptorJsonConverter()); - - using (var reader = new JsonTextReader(File.OpenText(filePath))) - { - return serializer.Deserialize>(reader); - } - } - - private class TestForegroundDispatcher : ForegroundDispatcher - { - public override bool IsForegroundThread => true; - - public override TaskScheduler ForegroundScheduler => TaskScheduler.Default; - - public override TaskScheduler BackgroundScheduler => TaskScheduler.Default; - } - - private class TestErrorReporter : ErrorReporter - { - public override void ReportError(Exception exception) - { - } - - public override void ReportError(Exception exception, ProjectSnapshot project) - { - } - - public override void ReportError(Exception exception, Project workspaceProject) - { - } - } - - private class StaticTagHelperResolver : TagHelperResolver - { - private readonly IReadOnlyList _tagHelpers; - - public StaticTagHelperResolver(IReadOnlyList tagHelpers) - { - this._tagHelpers = tagHelpers; - } - - public override Task GetTagHelpersAsync(Project project, ProjectSnapshot projectSnapshot, CancellationToken cancellationToken = default) - { - return Task.FromResult(new TagHelperResolutionResult(_tagHelpers, Array.Empty())); - } - } - - private class StaticProjectSnapshotProjectEngineFactory : ProjectSnapshotProjectEngineFactory - { - public override IProjectEngineFactory FindFactory(ProjectSnapshot project) - { - throw new NotImplementedException(); - } - - public override IProjectEngineFactory FindSerializableFactory(ProjectSnapshot project) - { - throw new NotImplementedException(); - } - - public override RazorProjectEngine Create(RazorConfiguration configuration, RazorProjectFileSystem fileSystem, Action configure) - { - return RazorProjectEngine.Create(configuration, fileSystem, b => - { - RazorExtensions.Register(b); - }); - } - } - } -} diff --git a/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/TagHelperSerializationBenchmark.cs b/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/TagHelperSerializationBenchmark.cs deleted file mode 100644 index 220f3ca172..0000000000 --- a/src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/TagHelperSerializationBenchmark.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.CodeAnalysis.Razor.Serialization; -using Microsoft.VisualStudio.LanguageServices.Razor.Serialization; -using Newtonsoft.Json; - -namespace Microsoft.AspNetCore.Razor.Performance -{ - public class TagHelperSerializationBenchmark - { - private readonly byte[] _tagHelperBuffer; - - public TagHelperSerializationBenchmark() - { - var current = new DirectoryInfo(AppContext.BaseDirectory); - while (current != null && !File.Exists(Path.Combine(current.FullName, "taghelpers.json"))) - { - current = current.Parent; - } - - var tagHelperFilePath = Path.Combine(current.FullName, "taghelpers.json"); - _tagHelperBuffer = File.ReadAllBytes(tagHelperFilePath); - } - - [Benchmark(Description = "Razor TagHelper Serialization")] - public void TagHelper_Serialization_RoundTrip() - { - var serializer = new JsonSerializer(); - serializer.Converters.Add(new RazorDiagnosticJsonConverter()); - serializer.Converters.Add(new TagHelperDescriptorJsonConverter()); - - // Deserialize from json file. - IReadOnlyList tagHelpers; - using (var stream = new MemoryStream(_tagHelperBuffer)) - using (var reader = new JsonTextReader(new StreamReader(stream))) - { - tagHelpers = serializer.Deserialize>(reader); - } - - // Serialize back to json. - using (var stream = new MemoryStream()) - using (var writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 4096)) - { - serializer.Serialize(writer, tagHelpers); - } - } - } -} diff --git a/src/Razor/test/Directory.Build.props b/src/Razor/test/Directory.Build.props deleted file mode 100644 index dce1b5bf03..0000000000 --- a/src/Razor/test/Directory.Build.props +++ /dev/null @@ -1,7 +0,0 @@ - - - - - true - - diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Razor.Test.ComponentShim.csproj b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Razor.Test.ComponentShim.csproj index b7df50da77..756371e76d 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Razor.Test.ComponentShim.csproj +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Razor.Test.ComponentShim.csproj @@ -2,7 +2,6 @@ netstandard2.0;net461 - true