Extremely slow build times when using local functions and `<AnalysisMode>All</AnalysisMode>`
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**: .NET SDK 9.0.306, Windows 10.0.26100
**Steps to Reproduce**:
1. See short repro below. Normal build time on my machine is ~0.2 seconds.
2. Building this code with `All` takes ~15 seconds on my machine.
```csharp
// This code demonstrates a problem arising from local functions and `All`.
// To observe normal build times, comment out `All` in the project file.
// This code is arbitrary; the more complex the local functions, the more the build times explode.
// My real code is far more complex, and build times are ~50x longer with AnalysisMode=All.
using System.Diagnostics;
interface INode
{
string Id();
IReadOnlyList Children();
INode Child(int index);
double[] Data();
bool Flag1();
bool Flag2();
int Property3();
int Property4();
}
class Repro
{
readonly Dictionary _tree = [];
public void ExploreTree(INode node)
{
// Call local function
GetNodeData(node, 1.0, true, 42);
// The more complex this local function (e.g. branching, recursive calls, parameters),
// the longer the build times with AnalysisMode=All.
// This code is arbitrary, giving enough complexity to observe the slow build times.
double GetNodeData(INode node, double param1, bool param2, int param3)
{
if (node.Flag1())
{
return node.Data()[1];
}
else if (node.Flag2())
{
double sum = 0;
foreach (var child in node.Children())
{
sum += GetNodeData(child, 1.0, true, 42);
}
return sum / node.Children().Count;
}
if (node.Property3() == 1)
{
string id = node.Id();
if (!_tree.TryGetValue(id, out double[]? data))
{
List nodes = [];
int prop4 = nodes[0].Property4();
double[] b = new double[prop4];
foreach (var n in nodes)
{
Debug.Assert(n.Property4() == prop4);
for (int i = 0; i < prop4; i++)
{
var child = n.Child(i);
b[i] += GetNodeData(child, 1.0, true, 42);
}
}
data = new double[prop4];
data[1] = 1;
_tree[id] = data;
}
var next = node.Child(1);
return GetNodeData(next, 1.0, true, 42);
}
else
{
string id = node.Id();
double data = 0;
double[] vals = new double[234];
foreach (var child in node.Children())
{
double val = vals[34];
data += GetNodeData(child, 1.0, true, 42) * val;
}
return data;
}
}
}
}
```
```xml
net9.0
enable
enable
All
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.