Skip to content

Commit 2787157

Browse files
author
John Luo
authored
Merge pull request #22294 from dotnet/johluo/migrate-more-tooling
Johluo/migrate more tooling
2 parents f76a244 + 68fea5b commit 2787157

24 files changed

+7182
-9
lines changed

.azure/pipelines/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ stages:
149149
$(_InternalRuntimeDownloadArgs)
150150
displayName: Build x86
151151

152-
# This is in a separate build step with to workaround MAX_PATH limitations - https://github.com/Microsoft/msbuild/issues/53
152+
# This is in a separate build step with -forceCoreMsbuild to workaround MAX_PATH limitations - https://github.com/Microsoft/msbuild/issues/53
153153
- script: .\src\SiteExtensions\build.cmd
154154
-ci
155155
-nobl
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[assembly: BenchmarkDotNet.Attributes.AspNetCoreBenchmark]
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.IO;
6+
using BenchmarkDotNet.Attributes;
7+
using Microsoft.AspNetCore.Mvc.Razor.Extensions;
8+
using Microsoft.AspNetCore.Razor.Language;
9+
10+
namespace Microsoft.AspNetCore.Razor.Performance
11+
{
12+
public class CodeGenerationBenchmark
13+
{
14+
public CodeGenerationBenchmark()
15+
{
16+
var current = new DirectoryInfo(AppContext.BaseDirectory);
17+
while (current != null && !File.Exists(Path.Combine(current.FullName, "MSN.cshtml")))
18+
{
19+
current = current.Parent;
20+
}
21+
22+
var root = current;
23+
var fileSystem = RazorProjectFileSystem.Create(root.FullName);
24+
25+
ProjectEngine = RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem, b => RazorExtensions.Register(b)); ;
26+
27+
MSN = fileSystem.GetItem(Path.Combine(root.FullName, "MSN.cshtml"), FileKinds.Legacy);
28+
}
29+
30+
public RazorProjectEngine ProjectEngine { get; }
31+
32+
public RazorProjectItem MSN { get; }
33+
34+
[Benchmark(Description = "Razor Design Time Code Generation of MSN.com")]
35+
public void CodeGeneration_DesignTime_LargeStaticFile()
36+
{
37+
var codeDocument = ProjectEngine.ProcessDesignTime(MSN);
38+
var generated = codeDocument.GetCSharpDocument();
39+
40+
if (generated.Diagnostics.Count != 0)
41+
{
42+
throw new Exception("Error!" + Environment.NewLine + string.Join(Environment.NewLine, generated.Diagnostics));
43+
}
44+
}
45+
46+
[Benchmark(Description = "Razor Runtime Code Generation of MSN.com")]
47+
public void CodeGeneration_Runtime_LargeStaticFile()
48+
{
49+
var codeDocument = ProjectEngine.Process(MSN);
50+
var generated = codeDocument.GetCSharpDocument();
51+
52+
if (generated.Diagnostics.Count != 0)
53+
{
54+
throw new Exception("Error!" + Environment.NewLine + string.Join(Environment.NewLine, generated.Diagnostics));
55+
}
56+
}
57+
}
58+
}

src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/MSN.cshtml

Lines changed: 3983 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
5+
<OutputType>Exe</OutputType>
6+
<ServerGarbageCollection>true</ServerGarbageCollection>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8+
<IsPackable>false</IsPackable>
9+
<ExcludeFromSourceBuild>true</ExcludeFromSourceBuild>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<Reference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions" />
14+
<Reference Include="BenchmarkDotNet" />
15+
<Reference Include="Newtonsoft.Json" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<Compile Include="$(SharedSourceRoot)BenchmarkRunner\*.cs" />
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.IO;
6+
using System.Linq;
7+
using BenchmarkDotNet.Attributes;
8+
using Microsoft.AspNetCore.Mvc.Razor.Extensions;
9+
using Microsoft.AspNetCore.Razor.Language;
10+
11+
namespace Microsoft.AspNetCore.Razor.Performance
12+
{
13+
public class SyntaxTreeGenerationBenchmark
14+
{
15+
public SyntaxTreeGenerationBenchmark()
16+
{
17+
var current = new DirectoryInfo(AppContext.BaseDirectory);
18+
while (current != null && !File.Exists(Path.Combine(current.FullName, "MSN.cshtml")))
19+
{
20+
current = current.Parent;
21+
}
22+
23+
var root = current;
24+
var fileSystem = RazorProjectFileSystem.Create(root.FullName);
25+
26+
ProjectEngine = RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem, b => RazorExtensions.Register(b)); ;
27+
28+
var projectItem = fileSystem.GetItem(Path.Combine(root.FullName, "MSN.cshtml"), FileKinds.Legacy);
29+
MSN = RazorSourceDocument.ReadFrom(projectItem);
30+
31+
var directiveFeature = ProjectEngine.EngineFeatures.OfType<IRazorDirectiveFeature>().FirstOrDefault();
32+
Directives = directiveFeature?.Directives.ToArray() ?? Array.Empty<DirectiveDescriptor>();
33+
}
34+
35+
public RazorProjectEngine ProjectEngine { get; }
36+
37+
public RazorSourceDocument MSN { get; }
38+
39+
public DirectiveDescriptor[] Directives { get; }
40+
41+
[Benchmark(Description = "Razor Design Time Syntax Tree Generation of MSN.com")]
42+
public void SyntaxTreeGeneration_DesignTime_LargeStaticFile()
43+
{
44+
var options = RazorParserOptions.CreateDesignTime(o =>
45+
{
46+
foreach (var directive in Directives)
47+
{
48+
o.Directives.Add(directive);
49+
}
50+
});
51+
var syntaxTree = RazorSyntaxTree.Parse(MSN, options);
52+
53+
if (syntaxTree.Diagnostics.Count != 0)
54+
{
55+
throw new Exception("Error!" + Environment.NewLine + string.Join(Environment.NewLine, syntaxTree.Diagnostics));
56+
}
57+
}
58+
59+
[Benchmark(Description = "Razor Runtime Syntax Tree Generation of MSN.com")]
60+
public void SyntaxTreeGeneration_Runtime_LargeStaticFile()
61+
{
62+
var options = RazorParserOptions.Create(o =>
63+
{
64+
foreach (var directive in Directives)
65+
{
66+
o.Directives.Add(directive);
67+
}
68+
});
69+
var syntaxTree = RazorSyntaxTree.Parse(MSN, options);
70+
71+
if (syntaxTree.Diagnostics.Count != 0)
72+
{
73+
throw new Exception("Error!" + Environment.NewLine + string.Join(Environment.NewLine, syntaxTree.Diagnostics));
74+
}
75+
}
76+
}
77+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Compile the solution in Release mode (so binaries are available in release)
2+
3+
To run a specific benchmark add it as parameter.
4+
```
5+
dotnet run -c Release <benchmark_name>
6+
```
7+
8+
If you run without any parameters, you'll be offered the list of all benchmarks and get to choose.
9+
```
10+
dotnet run -c Release
11+
```

src/Razor/perf/Microsoft.AspNetCore.Razor.Performance/taghelpers.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/Razor/test/Directory.Build.props

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Razor.Test.ComponentShim.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
5-
<DisablePubternalApiCheck>true</DisablePubternalApiCheck>
65
</PropertyGroup>
76

87
</Project>

0 commit comments

Comments
 (0)