You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 73b4e23
Browse filesBrowse the repository at this point in the historyBrowse files
Sweep dead start bits in slices instead of a full reclaim
A dead object keeps its start bit until something clears it, and its
mark id comes round again after 16 collections, so the collector runs a
full reclaim every 15. That is a stop of 5 ms on gc_pauses and 17 ms on
a million-entity heap, once in 16 cycles, in a collector built around
0.5 ms slices. The benchmarks never saw it: the harness collects between
samples, which restarts the count.
Each collection now owes a twelfth of the blocks to a sweep, which runs
as jobs on the mark queue. A block is swept every 12 collections, and an
object marked by neither this cycle nor the last has its start bit
cleared. A full reclaim is left as the fallback: if the sweep falls more
than a collection behind, on a failed cycle, for an explicit collection,
and to give memory back from a heap well over its target. Nothing else
needed the periodic one, and live bytes now come from the row count.
A job is much more work than one object, and IncrementalExpired reads
the clock once in 64 calls, so 64 sweep jobs could run past a deadline:
a first slice took 1.3 ms. A slice now looks at the clock after each
job. First slices are 0.6 ms.
Without the harness's collections, 4 interleaved runs against the
default collector, before and after: gc_frames +34% to +11%, longest
slice 3.9 to 1.2 ms; gc_pauses +78% to +5%, 5.6 to 2.5 ms, p99.9 2.8 to
0.9 ms; million-entity heap +24% to +8%, 17.0 to 3.1 ms.
Test: IncrementalGcStartSweep runs 40 cycles on a heap fragmented into
small holes, and checks no start bit outlives 14 collections and no full
reclaim ran.
for test in GcMutationRoots GcContainerMutation IncrementalGcSlices IncrementalGcContainers IncrementalGcArrayChunks IncrementalGcPacing IncrementalGcFinishBoundary GcWeakMapChain GenerationalFinalizerLifecycle GenerationalLargeBufferLifecycle; do
232
+
for test in GcMutationRoots GcContainerMutation IncrementalGcSlices IncrementalGcContainers IncrementalGcArrayChunks IncrementalGcPacing IncrementalGcStartSweep IncrementalGcFinishBoundary GcWeakMapChain GenerationalFinalizerLifecycle GenerationalLargeBufferLifecycle; do
Copy file name to clipboardExpand all lines: .github/workflows/test.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -402,7 +402,7 @@ jobs:
402
402
working-directory: test/regression
403
403
run: |
404
404
failed=""
405
-
for test in GcMutationRoots GcContainerMutation IncrementalGcSlices IncrementalGcContainers IncrementalGcArrayChunks IncrementalGcPacing IncrementalGcFinishBoundary IncrementalGcVerifier IncrementalWindowsHeaders GcWeakMapChain GenerationalFinalizerLifecycle GenerationalLargeBufferLifecycle; do
405
+
for test in GcMutationRoots GcContainerMutation IncrementalGcSlices IncrementalGcContainers IncrementalGcArrayChunks IncrementalGcPacing IncrementalGcStartSweep IncrementalGcFinishBoundary IncrementalGcVerifier IncrementalWindowsHeaders GcWeakMapChain GenerationalFinalizerLifecycle GenerationalLargeBufferLifecycle; do
406
406
echo "::group::incremental gc: $test"
407
407
# The lifecycle fixtures' hxml selects generational mode; compile
408
408
# the same Main with incremental mode here instead.
* The incremental collector no longer stops for a full reclaim every 15 collections, which took 5 ms on a 120 MB heap and 17 ms on an 800 MB one. Slices sweep a share of the blocks each collection instead, a finished cycle counts rows and leaves the sweep to the zeroing thread and the allocator, and a slice looks at the clock after each large job (libhxcpp #372)
5
6
* Fixed the incremental collector doing no incremental work for a program that allocates mostly array storage, such as Bytes: a slice was skipped inside a mutation scope and a cycle could not finish in one, so every collection was a full stop. Slices run there now, and the stop that finishes a cycle scans the holders of open scopes again (libhxcpp #372)
6
-
* The incremental collector (HXCPP_GC_INCREMENTAL) costs far less and stops for less. Each cycle is paced from the last one, starts as late as it can finish inside the free space the stop-the-world collector would spend, and spaces its slices by allocation as well as time. The collecting thread marks too, a slice no longer waits for a marker the scheduler has not run or for the zeroing thread, and an array's chunks are marked in parallel. On gc_pauses it went from 74% slower than the default collector to 5%, and the slowest 0.1% of work units from 2.7 ms to 1.4 ms (libhxcpp #372)
7
+
* The incremental collector (HXCPP_GC_INCREMENTAL) costs far less and stops for less. Each cycle is paced from the last one, starts as late as it can finish inside the free space the stop-the-world collector would spend, and spaces its slices by allocation as well as time. The collecting thread marks too, a slice no longer waits for a marker the scheduler has not run or for the zeroing thread, and an array's chunks are marked in parallel. On gc_pauses it went from 78% slower than the default collector to 9%, and the slowest 0.1% of work units from 2.8 ms to 0.9 ms (libhxcpp #372)
7
8
* Fixed a thread that throws while the process exits crashing it on musl, as one with a failing cpp.Lib.load did about once in 800 exits on Alpine: libgcc's unwinder frees the table it finds frames in when the library finalizers run, and other threads still ran Haxe code then. The exit now parks every other thread that runs Haxe code, at its next safe point or as it leaves a GC-free zone, waiting up to 100 ms for one in a loop that does not allocate. A thread let go during the exit stays parked instead of ending (libhxcpp #423)
8
9
* Fixed programs that use sys.ssl without sockets failing to link on Linux with an undefined reference to hxcpp_alloc_kind: hxcpp_std, linked a second time after hxcpp_ssl, came after the runtime's second copy. The runtime is linked once more after all the libraries linked twice, which keep their order
9
10
* Fixed closing, reading or polling a socket handle that a library made in stock hxcpp's layout, as CrossByte's accept does, reading past the handle: the runtime took its own wrapper's later fields from it, and a close wrote through what followed it in memory. Only the descriptor is read from such a handle, and the runtime's wrapper no longer shares its name, and with it its vtable, with a library's
Copy file name to clipboardExpand all lines: bench/results/incremental-gc/README.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,34 @@ All six `gc_frames` processes returned checksum 1106626610; all six `gc_pauses`
19
19
20
20
The largest budgeted collector invocation was 1.346 ms in `gc_frames` and 1.783 ms in `gc_pauses`, against a requested 0.5 ms. Cumulative unbudgeted maxima were 13.553 ms and 9.971 ms, respectively, including explicit collections outside measured frames. These results do not establish a sub-millisecond collector or eliminate synchronous interruptions.
21
21
22
+
## Pacing, sweep and slices
23
+
24
+
These results are for the pacer, the slice changes and the sweep, on main at `346c7e52` against the same source with them. Elapsed time is the median of each process's median sample, and the change is the median of its ratio to the existing collector in the same round. p99.9 is the median across processes. Maximum pause is the longest budgeted slice in any process, from the `maxSlicePauseMs` counter.
25
+
26
+
| Workload | Collector | Elapsed, ms | vs existing | p99.9, ms | Worst unit, ms | Maximum slice, ms | Peak RSS, MiB |
The harness collects between samples, and that restarts the count to the existing collector's periodic full reclaim, which comes every 15 collections. No sample reaches it, though an application that does not collect explicitly does. With those collections taken out of the harness:
36
+
37
+
| Workload | Collector | Elapsed, ms | vs existing | p99.9, ms | Worst unit, ms | Maximum slice, ms | Peak RSS, MiB |
The same changes took the longest slice from 17.0 ms to 3.1 ms on a heap of a million entities and about 800 MiB, a `gc_frames` world with 8,000 frames per sample, where a full reclaim costs most. That workload and a port of another frame loop are not in the harness.
47
+
48
+
Windows x64 as below, Haxe 4.3.7. Eight rounds of two warmups and ten samples with the harness as it is, and four rounds of two warmups and 24 samples without its collections, the order of the collectors rotating each round, on a machine 8 to 18% busy with other work. Checksums agreed in every round. The differences of a few percent between the two tables are within what a rebuild or the other load can move.
49
+
22
50
## Protocol
23
51
24
52
- Windows x64, AMD Ryzen 9 9950X, Haxe 4.3.7 and MSVC 19.44.35213.
The library macro requests the existing Haxe generator's setter barriers. It enables `HXCPP_GC_GENERATIONAL` internally for code generation, while the runtime keeps ordinary allocation headers and does not enable the nursery. No compiler or standard library patch is needed. Do not add the generational flag yourself or reuse C++ generated without the incremental flag.
16
16
17
-
Automatic collection needs no engine calls. It accounts for newly acquired allocation blocks and large buffers, and uses a 0.5 ms slice target and a preferred 1 ms interval. Each finished cycle teaches the pacer how many slices a cycle takes and how fast the app allocates during one. The next cycle then starts as late as it can still finish inside the reserve, the space the existing collector would spend before collecting: every free block, and growth up to the memory target. A later start means fewer marks for the same allocation. During a cycle a slice is due at the interval, or sooner once the app has allocated its share of the reserve, with at least 0.25 ms for the app between slices. Past three quarters of what was left at the start, slices stop waiting. A cycle the allocator cuts short counts as a longer one, so the next starts earlier, and the first cycle, with nothing to learn from, starts at half the reserve. Deadlines and pause counters use a monotonic clock. Exhausting available space can still force synchronous completion. `Gc.enable(false)` disables automatic collection as before; explicit collection and scheduling calls still work.
17
+
Automatic collection needs no engine calls. It accounts for newly acquired allocation blocks and large buffers, and uses a 0.5 ms slice target and a preferred 1 ms interval. Each finished cycle teaches the pacer how many slices a cycle takes and how fast the app allocates during one. The next cycle then starts as late as it can still finish inside the reserve, the space the existing collector would spend before collecting: the free list, leaving out holes too small to use, and growth up to the memory target. A later start means fewer marks for the same allocation. During a cycle a slice is due at the interval, or sooner once the app has allocated its share of the reserve, with at least 0.25 ms for the app between slices. Past three quarters of what was left at the start, slices stop waiting. A cycle the allocator cuts short counts as a longer one, so the next starts earlier, and the first cycle, with nothing to learn from, starts at half the reserve. Deadlines and pause counters use a monotonic clock. Exhausting available space can still force synchronous completion. `Gc.enable(false)` disables automatic collection as before; explicit collection and scheduling calls still work.
18
18
19
19
Optional engine hooks are library-owned:
20
20
@@ -45,7 +45,11 @@ Native bulk operations use a mutation scope that records the holder before and a
45
45
46
46
Arrays and maps longer than 256 elements register jobs containing a managed owner and a cursor. Each chunk reacquires current storage from that owner. Structural mutation resets the cursor. Scalar insertion shades its target without restarting the whole container. An array's chunks go onto the shared mark queue as jobs, so every marker scans them in parallel, and a job not reached in one slice waits for the next. A map keeps one cursor and is scanned by the collecting thread. Several chunks feed one marker round to avoid waking the pool for every small chunk. Traditional raw array-buffer jobs cannot survive an incremental pause.
47
47
48
-
No heap storage is reclaimed while marking is unfinished. Completed collection free ranges are materialized before starting a new partial mark, so lazy allocator reclamation cannot interpret partial row marks as a completed collection. Detached threads transfer their unread mutation entries before their contexts are pooled or destroyed.
48
+
No heap storage is reclaimed while marking is unfinished. Completed collection free ranges are materialized before starting a new partial mark, so lazy allocator reclamation cannot interpret partial row marks as a completed collection. The stop that finishes a cycle only counts rows and builds the free list. A block is reclaimed when it is first used, or before that by the zeroing thread, which has time to spare while the allocator catches up, so a cycle's first stop rarely finds any left to materialize. A block outside the free list waits for a later collection.
49
+
50
+
A dead object keeps its start bit until something clears it, and its mark id comes round again after 16 collections. The existing collector clears them in a full reclaim every 15 collections, a stop that grows with the heap. Slices sweep a twelfth of the blocks per collection instead, as jobs on the mark queue, so steady allocation needs no full reclaim. One still runs if the sweep falls more than a collection behind, for an explicit collection, and to give memory back from a heap well over its target.
51
+
52
+
Detached threads transfer their unread mutation entries before their contexts are pooled or destroyed.
49
53
50
54
If mutation metadata cannot be retained, the partial cycle is discarded before any reclamation. Recovery rewinds headers changed by the partial epoch before restarting a full mark. Advancing directly to another epoch would make unvisited objects appear marked to the alternating-bit fast path. Tests cover that failure transition. Log storage is capped at 1,048,576 entries per thread, and range registration at 1,048,576 owners per cycle. Native allocation failure requests recovery; this is not a guarantee that a process with exhausted system memory can continue.
51
55
@@ -65,6 +69,7 @@ Conventional fixtures under `test/regression` cover:
65
69
|`IncrementalGcContainers`| Resize and reorder after a partially traversed array range, with payload checks after completion |
66
70
|`IncrementalGcArrayChunks`| Array chunks still queued at a stop, through shrinking and reallocation, and dropped with a failed cycle |
67
71
|`IncrementalGcPacing`| Cycles spending the free space, and finishing when all allocation is in mutation scopes |
72
+
|`IncrementalGcStartSweep`| Dead start bits cleared before their mark id returns, and no full reclaim, on a heap fragmented into small holes |
68
73
|`IncrementalGcFinishBoundary`| New roots, descendants and container stores published between strong marking and finishing |
69
74
|`IncrementalGcVerifier`| Independent detection of an omitted descendant |
@@ -99,7 +104,7 @@ Counters include setup and explicit collections from process startup:
99
104
100
105
These counters describe the collecting thread's successful invocations. They are not a distribution of every application thread's wait. Several assists can occur in one allocation burst, and explicit APIs can finish synchronously. Measure frame or request latency as well. The benchmark executable includes `incrementalGc` counters in its JSON when built with the flag.
101
106
102
-
Development measurements must compare the same workload, source, toolchain and hardware against the existing libhxcpp collector, with verification and test controls omitted. Record checksums, frame or request distributions, throughput, RSS and reserved memory. The game frame workload has shown shorter tail frames locally, while the allocation-heavy `gc_pauses`workload still shows a material throughput cost. Do not treat either result as a universal speedup or a hard pause guarantee. The p99.9, maximum interruption, throughput and memory gates in #372 remain the acceptance criteria for promoting this mode beyond experimental use.
107
+
Development measurements must compare the same workload, source, toolchain and hardware against the existing libhxcpp collector, with verification and test controls omitted. Record checksums, frame or request distributions, throughput, RSS and reserved memory. On the development machine `gc_frames` runs 10 to 16% slower than the existing collector and `gc_pauses`5 to 9%, with the slowest 0.1% of work units under 1 ms against 5 to 8 ms, and up to 10% more peak memory. The harness's full collection between samples resets the existing collector's periodic full reclaim, so it hides that stop: compare with those collections removed as well. Do not treat either result as a universal speedup or a hard pause guarantee. The p99.9, maximum interruption, throughput and memory gates in #372 remain the acceptance criteria for promoting this mode beyond experimental use.
0 commit comments