Dramatically faster package restores with .NET 9's new NuGet ...
.NET 9 introduces a significant rewrite of the NuGet Restore algorithm, aimed at dramatically improving performance and scalability for large .NET repositories. The original NuGet Restore algorithm, which had remained largely unchanged for over a decade, faced challenges with increasingly complex dependency graphs, particularly in large-scale projects. The new approach was developed to address these issues, resulting in substantial performance gains.
The rewrite was initiated after an internal Microsoft team reported that NuGet Restore times had ballooned to over 30 minutes for their large repository. This was primarily due to the recursive nature of the old algorithm, which created a full representation of the dependency graph, including duplicate nodes, leading to excessive memory allocations and long garbage collection pauses. For example, one project in the repository generated a dependency graph with 1.6 million nodes, many of which were duplicates.
The new algorithm takes a more streamlined approach by flattening the dependency graph and resolving conflicts during graph construction, rather than in multiple passes. This reduces the number of nodes significantly—from 1.6 million to just 1,200 in one test case—and cuts restore times by a factor of 16x, from 32 minutes to just 2 minutes. This improvement not only saves thousands of compute hours per day in Continuous Integration/Continuous Deployment pipelines but also enhances developer productivity.
Key benefits of the new NuGet Restore algorithm include:
The new NuGet Restore algorithm is available by default in .NET 9, requiring no additional configuration. This change represents a major step forward in the .NET ecosystem, with potential for further performance optimizations across other areas of the platform.
For more details, you can read the full story on the .NET Blog and the announcement of the new resolver.