Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 4, 2026

Adds a view to identify objects preventing heap compaction by correlating Free objects (memory gaps) with their predecessors.

Implementation

Core Algorithm (FragmentationBlameStackSource.cs)

  • Sorts heap objects by address O(n log n)
  • Maps each Free object to its immediate predecessor in memory
  • Aggregates Free object sizes as "fragmentation cost" per blamed object
  • Delegates path-to-root queries to MemoryGraphStackSource for consistency

UI Integration (PerfViewData.cs)

  • Adds view under Advanced Group for .gcDump files
  • Configures CallTree tab as default (matches Generation views)
  • Displays diagnostic stats: Free object count, total fragmentation MB

Usage

MyDump.gcDump
└── Advanced Group
    └── Fragmentation Blame  ← Shows blamed objects with paths to root

Metric column shows fragmentation cost (bytes), not object size. Helps identify:

  • Pinned buffers preventing compaction
  • Long-lived Gen2 objects fragmenting younger generations
  • Static field references blocking collection

Edge Cases

  • Consecutive Free objects: Only blames first real object, avoids double-counting
  • No Free objects: Logs warning, returns empty view
  • No predecessor: Logs warning for Free at heap start

Documentation

  • User guide: documentation/FragmentationBlameView.md
  • Conceptual tests: src/PerfView.Tests/FragmentationBlameStackSourceTests.cs

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Created FragmentationBlameStackSource class to identify objects causing heap fragmentation
- Added new view to HeapDumpPerfViewFile that appears under Advanced Group
- View shows objects and their paths to root with fragmentation costs
- Fragmentation cost is the sum of Free object sizes that follow each object in memory
- Includes comprehensive documentation and conceptual tests
- Uses efficient O(n log n) algorithm for finding blamed objects

Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
Copilot AI changed the title [WIP] Add fragmentation blame view for gcdump files Add Fragmentation Blame view for GC dump analysis Feb 4, 2026
Copilot AI requested a review from brianrob February 4, 2026 00:20
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