Skip to content

Conversation

@VSadov
Copy link
Owner

@VSadov VSadov commented Nov 23, 2025

The motivation for this is described in the discussion here: dotnet/runtime#115627

There is a benchmark that demonstrates that better compaction heuristics can lead to smaller heap with the throughput staying roughly the same.

This PR:

  • Improves the ways in which we estimate/guess the amount of "useless" fragmentation in the heap as an input into deciding whether to do compaction.
  • Implements optional eager sweep for recently allocating regions (as we expect high mortality) to improve quality of compaction, when we do compaction.
  • Some improvements to reusability of free spaces for new allocations. (may help when not compacting).
  • Tweaked the heuristic that decides on Gen1 budget to ignore demoted objects. Demoting from Gen2 back to Gen1/Gen0 is not an allocation.
  • Some minor tweaks in affected places.

On the benchmark that started the discussion:
GCPerfSim.exe -tc 8 -tagb 200 -tlgb 2 -lohpi 0 -sohsi 50 -ramb 20 -rlmb 0.2 -sohpi 0

The commit size could be seen reduced from ~11Gb to ~7.5Gb (44% less) with throughput staying roughly the same.

For the real apps the heap size benefits will be smaller, since the benchmark intentionally exaggerates "useless" fragmentation, but we could still see some positive impact.

@VSadov VSadov merged commit 69c6ad8 into main Nov 23, 2025
@VSadov VSadov deleted the comp2 branch November 23, 2025 19:23
@VSadov
Copy link
Owner Author

VSadov commented Nov 23, 2025

TODO: update the net8.0 branch accordingly

VSadov added a commit that referenced this pull request Nov 23, 2025
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.

2 participants