Repository navigation
Conversation
In MethodBodyScanner.HandleCall, create the ValueNodeList directly instead of building an intermediate List<T> and copying it. Apply the same change to MethodBodyScanner in src\tools\illink\src\linker\Linker.Dataflow to keep the two in sync. Also specify the initial capacity when creating a List<T> in ILCompiler and ILCompiler.Compiler where the number of elements is known up front. This avoids reallocating the backing array as the list grows. In single-method mode, fill the generic argument array directly instead of going through a List<T> and ToArray().
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
There was a problem hiding this comment.
🟡 Changes recommended
Performance measurements are missing, and the removed call sites leave dead synchronized constructors.
2 open findings
What changed in this PR
Reduces allocations in NativeAOT and ILLink compiler paths.
Changes:
- Builds
ValueNodeListdirectly in synchronized dataflow scanners. - Preallocates lists with known capacities.
- Fills generic argument arrays directly.
| File | Description |
|---|---|
src/tools/illink/src/linker/Linker.Dataflow/MethodBodyScanner.cs |
Removes an intermediate list allocation. |
src/coreclr/tools/Common/Compiler/Win32Resources/ResourceData.cs |
Preallocates resource-type storage. |
src/coreclr/tools/aot/ILCompiler/Program.cs |
Preallocates lists and directly fills generic arguments. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs |
Preallocates serialized field values. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs |
Preallocates generic metadata arguments. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NativeLayoutVertexNode.cs |
Preallocates layout collections. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/MethodBodyScanner.cs |
Removes an intermediate list allocation. |
🧠 Review effort: Balanced
|
I only skimmed this, but I'm not sure if any of this is worth it, sorry. Just as an example, the TypePreinit change makes it look like we care about perf here because we want to correctly size things. But if we care about perf, this should be an array not a list. And we shouldn't process it as IEnumerable down the line. But the truth is we don't care about the perf here and go for simplicity. Perf fixes should come with perf measurements. We care about wall clock time. Making source code lines longer and perturbing |
|
@MichalStrehovsky I measured the build times and memory allocation for |

In
MethodBodyScanner.HandleCall, create theValueNodeListdirectly instead of building an intermediateList<T>and copying it. Apply the same change toMethodBodyScannerinsrc\tools\illink\src\linker\Linker.Dataflowto keep the two in sync.Also specify the initial capacity when creating a
List<T>in ILCompiler and ILCompiler.Compiler where the number of elements is known up front. This avoids reallocating the backing array as the list grows.In single-method mode, fill the generic argument array directly instead of going through a
List<T>andToArray().I ran the NativeAOT smoketests and
ILCompiler.*.Tests/Mono.Linker.Testsusing the following commands and confirmed that they all passed in local.