Skip to content

Commit 1ccf87d

Browse files
committed
feat(heap): retain multi-age nursery survivors (#37)
1 parent 5883b02 commit 1ccf87d

2 files changed

Lines changed: 233 additions & 31 deletions

File tree

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ const gc = @import("gc");
178178
var rt = MyRuntime{}; // holds your roots + finalizer state
179179
var heap = gc.Heap(MyRuntime).init(allocator, &rt);
180180
defer heap.deinit(); // frees + finalizes everything left
181+
heap.setNurseryTenuringAge(3); // retain survivors for three minor cycles
182+
heap.setNurseryEnabled(true);
181183
182184
const obj = try heap.create(MyObject, .object); // uninitialized payload
183185
obj.* = .{ ... }; // initialize before the next safepoint
@@ -189,7 +191,7 @@ for (objects[0..count]) |item| item.* = .{ ... }; // initialize before a safepoi
189191
heap.maybeCollect(); // call at safepoints; collects past a threshold
190192
heap.collect(); // or force a full stop-the-world cycle
191193
const compacted = heap.collectAndCompact(); // opt-in binding: collect + relocate
192-
const stats = heap.accounting(); // race-safe live/last-full byte snapshot
194+
const stats = heap.accounting(); // race-safe generation + heap telemetry
193195
```
194196

195197
`create` and `createBatch` return uninitialized payloads — initialize them
@@ -202,18 +204,21 @@ batch reports its successfully published prefix so the caller can commit that
202204
work before the next allocation performs recovery or reports OOM, preserving
203205
sequential failure ordering.
204206

205-
`accounting()` snapshots live cell/byte totals, collection counts, and the
206-
post-sweep byte size of the last completed full collection. Parallel and
207-
concurrent-metadata heaps take the collector's allocation lock for the snapshot;
208-
nursery-only cycles deliberately leave `last_full_collection_bytes` unchanged.
207+
`accounting()` snapshots live/young/promoted totals, collection counts, the
208+
configured tenuring age, the latest minor survivor/reclamation/promotion bytes,
209+
and the post-sweep byte size of the last full collection. Old-container and
210+
conservative-target cards persist while survivors remain young, so an unchanged
211+
old-to-young edge stays sound across repeated minors. Full collection or nursery
212+
disable explicitly tenures the remaining young prefix.
209213

210214
## Status
211215

212216
The collector supports stop-the-world, incremental, concurrent, parallel, and
213-
one-cycle nursery paths, plus opt-in stop-the-world relocation. The default
214-
remains non-moving. Unit and TSan gates cover cycles, weak/finalization
215-
semantics, allocation/publication races, relocation rollback, pinned/moved
216-
graphs, and exact accounting.
217+
configurable multi-age nursery paths, plus opt-in stop-the-world relocation. The
218+
default remains non-moving with one-cycle tenuring until an embedder selects a
219+
higher age. Unit and TSan gates cover cycles, weak/finalization semantics,
220+
allocation/publication races, relocation rollback, pinned/moved graphs, and
221+
exact accounting.
217222

218223
## License
219224

0 commit comments

Comments
 (0)