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 AI review requested due to automatic review settings October 6, 2025 09:23
Copy link
Contributor

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

@dotnet-policy-service
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

@github-actions
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

@github-actions
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

steveisok pushed a commit that referenced this pull request Nov 4, 2025
…we should do a major collection (#120532)

Backport of #120432 to release/10.0

/cc @BrzVlad

## Customer Impact

- [x] Customer reported
- [ ] Found internally

This impacts all platforms using mono. A customer reported a 40x
regression on an XML Serialization benchmark when moving from .NET8 to
.NET9. This regression is caused by the runtime triggering excessive GCs
due to a bug in the heuristic. This is more likely to happen if the GC
concurrent sweep phase takes longer and the application allocates large
objects frequently. This likely impacts many applications, but with less
noticeable performance impact.

## Regression

- [x] Yes
- [ ] No

This regressed in .NET9

## Testing

Tested the fix on sample benchmark that it works correctly.

## Risk

Low risk. The fix is localized and the previous condition was blatantly
wrong by mistake.

Co-authored-by: Vlad Brezae <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Nov 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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