dotnet / dotnet/msbuild

Extreme slowdowns when process memory usage is high

Open
#1,308 10 comments 0 reactions 0 assignees View on GitHub
Area: Performance backlog triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

Whenever MSBuild completes a `BuildRequest`, it [checks](https://github.com/Microsoft/msbuild/blob/4e405a802d587368581117daf3402491beea8de7/src/XMakeBuildEngine/BackEnd/Components/BuildRequestEngine/BuildRequestEngine.cs#L771) to see if the current process is using "too much" memory (defined as 80% of the virtual memory limit). If it is, the engine [attempts to free memory](https://github.com/Microsoft/msbuild/blob/4e405a802d587368581117daf3402491beea8de7/src/XMakeBuildEngine/BackEnd/Components/BuildRequestEngine/BuildRequestEngine.cs#L854-L862) by flushing build results to a file-based cache and calling for garbage collection.

This system likely worked well at some point, when process memory usage came primarily from MSBuild and flushing results to disk released a significant amount of memory. But if the bulk of the memory usage is coming from something _else_ in the process, this can cause extreme slowdowns: every build request completion does synchronous I/O _and_ a stop-the-world GC. This is especially painful if the process in question is `devenv.exe` and it's in the midst of a solution-configuration change (i.e. "do a design-time build of every project in the solution").

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.