forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix quadratic algorithm in CompilerGeneratedState (dotnet/linker#3150)
The way this code was supposed to work was that it would scan the compiler- generated type and all its descendants, record each generated type it found, then fill in information for all of the found types. The way it actually worked was that it would scan the descendants, record each generated type, then try to fill in information *for all generated types found in the program*. This is quadratic as you start adding types, as you rescan everything you've added before. The fix is to record just the types from the current pass, and then add them to the larger bag when everything's complete. Commit migrated from dotnet/linker@27ce032
- Loading branch information
Showing
2 changed files
with
103 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/tools/illink/test/Mono.Linker.Tests/Tests/PerfTestGeneratorForCompilerGeneratedCode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.IO; | ||
using System.Linq; | ||
|
||
/// <summary> | ||
/// This class generates a test that can be used to test perf of analyzing | ||
/// compiler-generated code. Run it by copying this file into a console app and | ||
/// calling <see cref="PerfTestGeneratorForCompilerGeneratedCode.Run"/>. A file | ||
/// will be generated in the current directory named GeneratedLinkerTests.cs. | ||
/// Copy this file into another Console app and trim the app to measure the | ||
/// perf. | ||
/// </summary> | ||
static class PerfTestGeneratorForCompilerGeneratedCode | ||
{ | ||
const int FuncNumber = 10000; | ||
public static void Run () | ||
{ | ||
using var fstream = File.Create ("GeneratedLinkerTests.cs"); | ||
using var writer = new StreamWriter (fstream); | ||
writer.WriteLine ($$""" | ||
class C { | ||
public static async void Main() | ||
{ | ||
int x = 0; | ||
{{string.Join (@" | ||
", Enumerable.Range (0, FuncNumber).Select (i => $"x += await N{i}<int>.M();"))}} | ||
Console.WriteLine(x); | ||
} | ||
} | ||
"""); | ||
for (int i = 0; i < FuncNumber; i++) { | ||
writer.WriteLine ($$""" | ||
public static class N{{i}}<T> | ||
{ | ||
public static async ValueTask<int> M() | ||
{ | ||
Func<int> a = () => 1; | ||
await Task.Delay(0); | ||
return a(); | ||
} | ||
} | ||
"""); | ||
} | ||
} | ||
} |