Skip to content

Commit ecf7aee

Browse files
committed
Document heapy diff limitations
Heapy diff can yield both false positives and false negatives due to keying on heap pointers. This is difficult to fix, so we're just documenting this for now. Refs zombocom#31
1 parent 2d083cf commit ecf7aee

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ Allocated STRING 9991 objects of size 399640/491264 (in bytes) at: scratch.rb:24
4747
Writing heap dump diff to output.json
4848
```
4949

50+
#### Limitations
51+
52+
Due to how the garbage collector in MRI manages objects on the Ruby heap, `heapy diff` may produce incomplete
53+
or incorrect diffs under the following circumstances:
54+
55+
1. **Heap compaction.** When compacting the Ruby heap either manually via `GC.compact` or with auto-compaction
56+
enabled, heapy cannot produce accurate diffs, because objects may move into different heap slots and will appear as
57+
newly allocated even if they weren't. In general, any mechanism that moves existing objects from one heap slot to
58+
another will invalidate diff reports. Always turn off compaction before taking the `<after>` heap dump.
59+
1. **Temporary allocations.** Diffs might omit objects from an `<after>` dump if Ruby allocated them into heap slots that were
60+
previously occupied by different objects in the `<before>` dump, and which were then deallocated between both dumps.
61+
To minimize the chance of this happening, triggering a major GC three or more times between heap dumps can help
62+
tenuring survivors and thus stabilizing the heap prior to taking a diff.
63+
5064
### Read a Heap Dump
5165

5266
Step 1) Generate a heap dump. You could [do this manually](http://samsaffron.com/archive/2015/03/31/debugging-memory-leaks-in-ruby). Or you can use a tool like [derailed_benchmarks](https://github.com/schneems/derailed_benchmarks)

0 commit comments

Comments
 (0)