Skip to content

Remove unnecessary GC.Collect calls #11671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Remove unnecessary GC.Collect calls #11671

wants to merge 1 commit into from

Conversation

AR-May
Copy link
Member

@AR-May AR-May commented Apr 3, 2025

Fixes #11373

Context

Builds on MSBuild nodes forcing a GC immediately after the build is done. At its worst case, this burned 3 cores for 3 seconds at a time that VS and the user think the build is done and VS is likely launching the app or user back to typing, so not really a good time to consume CPU.

Changes Made

  • Remove GC call at the end of the build.
  • Do not check for memory usage on a 64 bit machine.

Testing

Correctness: unit tests & exp insertion.
Perf: exp VS insertion, local measurements and perfstar does not show any noticeable impact.

@Copilot Copilot AI review requested due to automatic review settings April 3, 2025 11:55
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes unnecessary GC.Collect calls to avoid excessive CPU consumption during build completion.

  • Removed a direct call to GC.Collect by commenting it out in OutOfProcNode.cs
  • Updated the memory usage check in BuildRequestEngine.cs to bypass the GC call on 64-bit operating systems

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Build/BackEnd/Node/OutOfProcNode.cs Removed the GC.Collect call by commenting it out, preventing synchronous GC at build completion.
src/Build/BackEnd/Components/BuildRequestEngine/BuildRequestEngine.cs Extended the condition to skip manual GC triggering on 64-bit systems.

@JanProvaznik
Copy link
Member

do the tests rely on some finalizer to run caused by the gc collect 🤔

@AR-May
Copy link
Member Author

AR-May commented Apr 7, 2025

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@yuehuang010
Copy link
Contributor

Are these "node" part of Node Reuse? If so, then it is good to clean up the memory after work is done to minimize footprint while idle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate the need and impact of GC.Collect calls
4 participants