News

.NET 9 Introduces Major NuGet Restore Algorithm Rewrite for Enhanced Performance

.NET 9 Introduces Major NuGet Restore Algorithm Rewrite for Enhanced Performance

April 09, 2025
.NET 9 NuGet Restore Performance Optimization Dependency Graph Scalability Developer Productivity Continuous Integration Memory Efficiency
.NET 9 introduces a significant rewrite of the NuGet Restore algorithm, dramatically improving performance, scalability, and memory efficiency for large .NET repositories.

.NET 9 Introduces Major NuGet Restore Algorithm Rewrite for Enhanced Performance

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:

  • Scalability: The algorithm can now handle tens of thousands of projects with near-linear performance scaling, making it suitable for large repositories.
  • Performance: Restore times have been drastically reduced, with some cases seeing a 16x improvement.
  • Memory Efficiency: By eliminating duplicate nodes and optimizing graph construction, the new algorithm significantly reduces memory usage and garbage collection overhead.
  • Developer Experience: Faster restores mean less waiting time for developers, enabling them to focus more on coding and less on build processes.

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.

Sources

How we ended up rewriting NuGet Restore in .NET 9 This is the story of how team members across NuGet, Visual Studio, and .NET embarked on a journey to fully rewrite the NuGet Restore ...
Dramatically faster package restores with .NET 9's new NuGet resolver A new NuGet dependency graph resolver built to dramatically improve performance. If you've struggled with slow package restores in complex builds, this is the ...
[.NET 9 Preview 3] no-op restore is no longer a no-op #13269 - GitHub The thing that determines whether a restore should happen is a nuget.dgspec.json file in the obj folder, before and after.