Skip to content

Conversation

BrzVlad
Copy link
Member

@BrzVlad BrzVlad commented Oct 6, 2025

When we are in this method, major sweep hasn't yet finished so we check with some imprecise conservative values. min_heap_size is a conservative lower limit of the actual heap size. Allowance represents how much more we allow the heap to grow after the previous major collection. We were comparing the min_heap_size with the allowance by mistake, when we should have compared it with the next major trigger size (which is the heap_size after the last collection plus the allowance).

Wrong condition added in #98154, causing excessive GCs in some scenarios and regression from .net8 to .net9.

Fixes #119580

…major collection

When we are in this method, major sweep hasn't yet finished so we check with some imprecise conservative values. min_heap_size is a conservative lower limit of the actual heap size. Allowance represents how much more we allow the heap to grow after the previous major collection. We were comparing the min_heap_size with the allowance by mistake, when we should have compared it with the next major trigger size (which is the heap_size after the last collection plus the allowance).
@Copilot Copilot AI review requested due to automatic review settings October 6, 2025 09:23
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 fixes an incorrect condition in the Mono SGEN garbage collector that was causing excessive major garbage collections. The bug was introduced in a previous change and resulted in performance regression from .NET 8 to .NET 9.

Key changes:

  • Corrects the major collection trigger logic by comparing minimum heap size against the proper threshold
  • Fixes a condition that was incorrectly comparing heap size with allowance instead of total trigger size

Copy link
Contributor

Tagging subscribers to this area: @BrzVlad
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@lateralusX lateralusX left a comment

Choose a reason for hiding this comment

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

LGTM!

@BrzVlad
Copy link
Member Author

BrzVlad commented Oct 8, 2025

/ba-g wasm unrelated

@BrzVlad BrzVlad merged commit d4269d0 into dotnet:main Oct 8, 2025
69 of 72 checks passed
@BrzVlad
Copy link
Member Author

BrzVlad commented Oct 8, 2025

/backport to release/10.0

Copy link
Contributor

github-actions bot commented Oct 8, 2025

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18348341019

@BrzVlad
Copy link
Member Author

BrzVlad commented Oct 8, 2025

/backport to release/9.0-staging

Copy link
Contributor

github-actions bot commented Oct 8, 2025

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/18348346199

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS] .NET 9 System.Xml significant performance drop compared to .NET 8

2 participants