Improve Crossgen2 performance via sorting improvements (#35870)
authorDavid Wrighton <davidwr@microsoft.com>
Wed, 6 May 2020 17:35:48 +0000 (10:35 -0700)
committerGitHub <noreply@github.com>
Wed, 6 May 2020 17:35:48 +0000 (10:35 -0700)
commit038f3623b18360d1b903206bf97e544447eebabd
treea3bd4f52145bf57fd6beb285b1182e5161c86b76
parent22087dba80acbb5cf7342e496d5729b45dd2a495
Improve Crossgen2 performance via sorting improvements (#35870)

* Improve Crossgen2 performance
- Crossgen2 makes extensive use of sorting to achieve determinism
- Replace most signifcant sort operations with a parallel mergesort
  - These sorts use rather expensive comparison functions and as such the standard sort algorithm which is tuned more to reduce memory usage than reduce comparisons is not ideal, and merge sort works better
  - Primarily sorting is performed during the previously single threaded portions of the product. Adding parallelism yields easy wins
  - In a large benchmark overall compilation performance improved from 106 seconds to 82 seconds
- Implementation makes extensive use of generics to share the implementation across the various apis that are used for sorting in crossgen2
- Add Detection on of duplicates in sort algorithm
- Perf result compiling a large set of assemblies
  - Using standard sorts 121.6 seconds
  - Using parallel merge sort 96.9 seconds
15 files changed:
src/coreclr/src/tools/Common/Sorting/ArrayAccessor.cs [new file with mode: 0644]
src/coreclr/src/tools/Common/Sorting/ICompareAsEqualAction.cs [new file with mode: 0644]
src/coreclr/src/tools/Common/Sorting/ISortableDataStructureAccessor.cs [new file with mode: 0644]
src/coreclr/src/tools/Common/Sorting/ListAccessor.cs [new file with mode: 0644]
src/coreclr/src/tools/Common/Sorting/MergeSort.cs [new file with mode: 0644]
src/coreclr/src/tools/Common/Sorting/MergeSortCore.cs [new file with mode: 0644]
src/coreclr/src/tools/crossgen2/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs
src/coreclr/src/tools/crossgen2/ILCompiler.DependencyAnalysisFramework/ILCompiler.DependencyAnalysisFramework.csproj
src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ArrayOfEmbeddedDataNode.cs
src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/GCRefMapNode.cs
src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/HeaderNode.cs
src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/InliningInfoNode.cs
src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs
src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/ReadyToRunTableManager.cs
src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/ObjectWriter/SectionBuilder.cs