ziglang/zig
261
5.9k
Fork
You've already forked zig
764

add SafeAllocator #31991

Manually merged
andrewrk merged 4 commits from gooncreeper/zig:safe-allocator into master 2026年05月26日 03:53:33 +02:00
Contributor
Copy link

Closes #31186

Implements a thread-safe allocator with the following guarantees:

  • deinit reports all leaks and frees all backing memory.
  • All allocation mismatches result in either a panic or segmentation fault.
  • Allocations from other SafeAllocator instances cause a panic (if Options.canary differ).
  • Double frees and operation (resize, remap, and free) races panic or segmentation fault.

Given the backing allocator does not reuse memory, it does not reuse memory either and

  • Most writes after free will segmentation fault or are eventually detected and panic.

std.heap.DebugAllocator has been deprecated (I have also deprecated std.heap.Check since this was its last usage and returning a usize leak count is a much cleaner approach).

General Design

Every allocation is trailed by an AllocFooter which contains metadata for the allocation and stack traces. It is protected by a checksum to catch corruption from allocation overwrites and report canary mismatches. An allocation's memory has a minimum alignment of AllocFooter so that the footer is at a fixed offset determined from the allocation size. An allocation's memory is stored either:

  • Inside linearly-filled buckets for small allocations.
  • Inside an allocation directly from the backing allocator.

To track allocations, each thread maintains a table of backing allocations. The table may be modified by other threads in the case of a producer-consumer operation, so the table is a linked list only expanded by creating new segments. Each thread maintains a linked list of free entries, which may contain entries from other threads' tables.

In the case of producer-consumer operations, acquire/release ordering is assumed to be provided externally. This is also assumed by all other thread-safe allocators that reuse memory as otherwise there would be data races on reuse of allocated memory.

Fuzz Tests

Two fuzz tests have also been added for the allocator. They check that there is no memory reuse, that returned memory is writable, and that it is not overwritten. The multi-threaded fuzz test spawns a number of worker threads which are used for all the test runs. I have run these tests extensively under TSAN.

Performance Measurements

Building the standard library tests with a RelaseSafe compiler build and -Ddebug-allocator:

Benchmark 1 (3 runs): ./master-out/bin/zig test --zig-lib-dir lib lib/std/std.zig -femit-bin=test --test-no-exec
 measurement mean ± σ min ... max outliers delta
 wall_time 29.4s ± 157ms 29.2s ... 29.5s 0 ( 0%) 0%
 peak_rss 2.24GB ± 3.49MB 2.23GB ... 2.24GB 0 ( 0%) 0%
 cpu_cycles 143G ± 999M 142G ... 144G 0 ( 0%) 0%
 instructions 268G ± 5.22M 268G ... 268G 0 ( 0%) 0%
 cache_references 13.1G ± 88.8M 13.0G ... 13.2G 0 ( 0%) 0%
 cache_misses 2.38G ± 30.7M 2.35G ... 2.41G 0 ( 0%) 0%
 branch_misses 634M ± 6.22M 629M ... 641M 0 ( 0%) 0%
Benchmark 2 (3 runs): ./branch-out/bin/zig test --zig-lib-dir lib lib/std/std.zig -femit-bin=test --test-no-exec
 measurement mean ± σ min ... max outliers delta
 wall_time 22.1s ± 88.6ms 22.0s ... 22.2s 0 ( 0%) ⚡- 24.7% ± 1.0%
 peak_rss 1.11GB ± 799KB 1.11GB ... 1.11GB 0 ( 0%) ⚡- 50.3% ± 0.3%
 cpu_cycles 136G ± 480M 136G ... 137G 0 ( 0%) ⚡- 4.4% ± 1.2%
 instructions 273G ± 2.07M 273G ... 273G 0 ( 0%) 💩+ 1.6% ± 0.0%
 cache_references 12.3G ± 71.3M 12.2G ... 12.4G 0 ( 0%) ⚡- 6.0% ± 1.4%
 cache_misses 2.02G ± 11.5M 2.01G ... 2.03G 0 ( 0%) ⚡- 14.9% ± 2.2%
 branch_misses 569M ± 2.65M 567M ... 572M 0 ( 0%) ⚡- 10.2% ± 1.7%
Closes #31186 Implements a thread-safe allocator with the following guarantees: * `deinit` reports all leaks and frees all backing memory. * All allocation mismatches result in either a panic or segmentation fault. * Allocations from other `SafeAllocator` instances cause a panic (if `Options.canary` differ). * Double frees and operation (resize, remap, and free) races panic or segmentation fault. Given the backing allocator does not reuse memory, it does not reuse memory either and * Most writes after free will segmentation fault or are eventually detected and panic. `std.heap.DebugAllocator` has been deprecated (I have also deprecated `std.heap.Check` since this was its last usage and returning a `usize` leak count is a much cleaner approach). ## General Design Every allocation is trailed by an `AllocFooter` which contains metadata for the allocation and stack traces. It is protected by a checksum to catch corruption from allocation overwrites and report canary mismatches. An allocation's memory has a minimum alignment of `AllocFooter` so that the footer is at a fixed offset determined from the allocation size. An allocation's memory is stored either: * Inside linearly-filled buckets for small allocations. * Inside an allocation directly from the backing allocator. To track allocations, each thread maintains a table of backing allocations. The table may be modified by other threads in the case of a producer-consumer operation, so the table is a linked list only expanded by creating new segments. Each thread maintains a linked list of free entries, which may contain entries from other threads' tables. In the case of producer-consumer operations, acquire/release ordering is assumed to be provided externally. This is also assumed by all other thread-safe allocators that reuse memory as otherwise there would be data races on reuse of allocated memory. ## Fuzz Tests Two fuzz tests have also been added for the allocator. They check that there is no memory reuse, that returned memory is writable, and that it is not overwritten. The multi-threaded fuzz test spawns a number of worker threads which are used for all the test runs. I have run these tests extensively under TSAN. ## Performance Measurements Building the standard library tests with a RelaseSafe compiler build and `-Ddebug-allocator`: ``` Benchmark 1 (3 runs): ./master-out/bin/zig test --zig-lib-dir lib lib/std/std.zig -femit-bin=test --test-no-exec measurement mean ± σ min ... max outliers delta wall_time 29.4s ± 157ms 29.2s ... 29.5s 0 ( 0%) 0% peak_rss 2.24GB ± 3.49MB 2.23GB ... 2.24GB 0 ( 0%) 0% cpu_cycles 143G ± 999M 142G ... 144G 0 ( 0%) 0% instructions 268G ± 5.22M 268G ... 268G 0 ( 0%) 0% cache_references 13.1G ± 88.8M 13.0G ... 13.2G 0 ( 0%) 0% cache_misses 2.38G ± 30.7M 2.35G ... 2.41G 0 ( 0%) 0% branch_misses 634M ± 6.22M 629M ... 641M 0 ( 0%) 0% Benchmark 2 (3 runs): ./branch-out/bin/zig test --zig-lib-dir lib lib/std/std.zig -femit-bin=test --test-no-exec measurement mean ± σ min ... max outliers delta wall_time 22.1s ± 88.6ms 22.0s ... 22.2s 0 ( 0%) ⚡- 24.7% ± 1.0% peak_rss 1.11GB ± 799KB 1.11GB ... 1.11GB 0 ( 0%) ⚡- 50.3% ± 0.3% cpu_cycles 136G ± 480M 136G ... 137G 0 ( 0%) ⚡- 4.4% ± 1.2% instructions 273G ± 2.07M 273G ... 273G 0 ( 0%) 💩+ 1.6% ± 0.0% cache_references 12.3G ± 71.3M 12.2G ... 12.4G 0 ( 0%) ⚡- 6.0% ± 1.4% cache_misses 2.02G ± 11.5M 2.01G ... 2.03G 0 ( 0%) ⚡- 14.9% ± 2.2% branch_misses 569M ± 2.65M 567M ... 572M 0 ( 0%) ⚡- 10.2% ± 1.7% ```

A nice followup here would be modifying lib/c/malloc.zig to choose this allocator in Debug and ReleaseSafe modes as the backing allocator for malloc, free, etc.

A nice followup here would be modifying `lib/c/malloc.zig` to choose this allocator in Debug and ReleaseSafe modes as the backing allocator for `malloc`, `free`, etc.
gooncreeper force-pushed safe-allocator from 312cb718bd
Some checks failed
ci / aarch64-macos-release (pull_request) Failing after 46m31s
ci / x86_64-freebsd-release (pull_request) Failing after 34m49s
ci / x86_64-netbsd-release (pull_request) Failing after 40m50s
ci / x86_64-netbsd-debug (pull_request) Failing after 47m49s
ci / x86_64-freebsd-debug (pull_request) Failing after 50m6s
ci / powerpc64le-linux-release (pull_request) Failing after 1h31m10s
ci / aarch64-macos-debug (pull_request) Failing after 1h40m20s
ci / aarch64-linux-release (pull_request) Failing after 1h16m16s
ci / aarch64-linux-debug (pull_request) Failing after 1h52m59s
ci / powerpc64le-linux-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
ci / s390x-linux-debug (pull_request) Has been cancelled
ci / s390x-linux-release (pull_request) Has been cancelled
ci / x86_64-linux-debug (pull_request) Has been cancelled
ci / x86_64-linux-debug-llvm (pull_request) Has been cancelled
ci / x86_64-linux-release (pull_request) Has been cancelled
ci / x86_64-openbsd-debug (pull_request) Has been cancelled
ci / x86_64-openbsd-release (pull_request) Has been cancelled
ci / x86_64-windows-debug (pull_request) Has been cancelled
ci / x86_64-windows-release (pull_request) Has been cancelled
to c169de4fd9
Some checks failed
ci / x86_64-netbsd-release (pull_request) Successful in 45m22s
ci / x86_64-netbsd-debug (pull_request) Successful in 57m11s
ci / x86_64-freebsd-release (pull_request) Successful in 35m13s
ci / x86_64-freebsd-debug (pull_request) Successful in 58m9s
ci / aarch64-macos-release (pull_request) Successful in 1h13m32s
ci / aarch64-macos-debug (pull_request) Successful in 1h21m52s
ci / powerpc64le-linux-release (pull_request) Successful in 1h56m25s
ci / aarch64-linux-release (pull_request) Successful in 1h26m36s
ci / aarch64-linux-debug (pull_request) Successful in 2h26m23s
ci / powerpc64le-linux-debug (pull_request) Successful in 4h6m37s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h30m45s
ci / x86_64-openbsd-release (pull_request) Successful in 1h13m50s
ci / x86_64-linux-debug (pull_request) Successful in 44m12s
ci / s390x-linux-release (pull_request) Successful in 1h49m41s
ci / s390x-linux-debug (pull_request) Successful in 3h2m26s
ci / x86_64-linux-debug-llvm (pull_request) Has been cancelled
ci / x86_64-linux-release (pull_request) Has been cancelled
ci / x86_64-windows-debug (pull_request) Has been cancelled
ci / x86_64-windows-release (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Waiting to run
ci / aarch64-freebsd-release (pull_request) Waiting to run
ci / aarch64-netbsd-debug (pull_request) Waiting to run
ci / aarch64-netbsd-release (pull_request) Waiting to run
ci / loongarch64-linux-debug (pull_request) Waiting to run
ci / loongarch64-linux-release (pull_request) Waiting to run
ci / riscv64-linux-debug (pull_request) Waiting to run
ci / riscv64-linux-release (pull_request) Waiting to run
2026年04月21日 04:06:31 +02:00
Compare
gooncreeper force-pushed safe-allocator from c169de4fd9
Some checks failed
ci / x86_64-netbsd-release (pull_request) Successful in 45m22s
ci / x86_64-netbsd-debug (pull_request) Successful in 57m11s
ci / x86_64-freebsd-release (pull_request) Successful in 35m13s
ci / x86_64-freebsd-debug (pull_request) Successful in 58m9s
ci / aarch64-macos-release (pull_request) Successful in 1h13m32s
ci / aarch64-macos-debug (pull_request) Successful in 1h21m52s
ci / powerpc64le-linux-release (pull_request) Successful in 1h56m25s
ci / aarch64-linux-release (pull_request) Successful in 1h26m36s
ci / aarch64-linux-debug (pull_request) Successful in 2h26m23s
ci / powerpc64le-linux-debug (pull_request) Successful in 4h6m37s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h30m45s
ci / x86_64-openbsd-release (pull_request) Successful in 1h13m50s
ci / x86_64-linux-debug (pull_request) Successful in 44m12s
ci / s390x-linux-release (pull_request) Successful in 1h49m41s
ci / s390x-linux-debug (pull_request) Successful in 3h2m26s
ci / x86_64-linux-debug-llvm (pull_request) Has been cancelled
ci / x86_64-linux-release (pull_request) Has been cancelled
ci / x86_64-windows-debug (pull_request) Has been cancelled
ci / x86_64-windows-release (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Waiting to run
ci / aarch64-freebsd-release (pull_request) Waiting to run
ci / aarch64-netbsd-debug (pull_request) Waiting to run
ci / aarch64-netbsd-release (pull_request) Waiting to run
ci / loongarch64-linux-debug (pull_request) Waiting to run
ci / loongarch64-linux-release (pull_request) Waiting to run
ci / riscv64-linux-debug (pull_request) Waiting to run
ci / riscv64-linux-release (pull_request) Waiting to run
to f327e2a8e2
Some checks failed
ci / x86_64-freebsd-release (pull_request) Successful in 36m11s
ci / x86_64-netbsd-release (pull_request) Successful in 36m34s
ci / x86_64-netbsd-debug (pull_request) Successful in 43m43s
ci / x86_64-freebsd-debug (pull_request) Successful in 55m1s
ci / aarch64-macos-release (pull_request) Successful in 1h4m25s
ci / powerpc64le-linux-release (pull_request) Failing after 1h11m6s
ci / aarch64-linux-release (pull_request) Failing after 1h11m52s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h28m12s
ci / aarch64-macos-debug (pull_request) Successful in 1h35m31s
ci / x86_64-openbsd-release (pull_request) Successful in 1h16m28s
ci / x86_64-windows-debug (pull_request) Successful in 1h19m14s
ci / x86_64-windows-release (pull_request) Successful in 1h12m1s
ci / x86_64-linux-debug (pull_request) Failing after 3h0m23s
ci / powerpc64le-linux-debug (pull_request) Failing after 3h1m47s
ci / x86_64-linux-release (pull_request) Failing after 3h7m40s
ci / aarch64-linux-debug (pull_request) Failing after 3h17m54s
ci / x86_64-linux-debug-llvm (pull_request) Failing after 4h51m28s
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
ci / s390x-linux-debug (pull_request) Has been cancelled
ci / s390x-linux-release (pull_request) Has been cancelled
2026年04月23日 02:38:58 +02:00
Compare
Author
Contributor
Copy link

Made a small change to the design: the bucket and allocation list sizes are now runtime configurable and use std.heap.pageSize for their defaults. The main motivation was to decrease the memory usage and amount of work for the fuzz tests by using a small value, though this should also be useful elsewhere. The performance hit was only about 1% overall.

Also updated libzigc to now use SafeAllocator when applicable.

Made a small change to the design: the bucket and allocation list sizes are now runtime configurable and use `std.heap.pageSize` for their defaults. The main motivation was to decrease the memory usage and amount of work for the fuzz tests by using a small value, though this should also be useful elsewhere. The performance hit was only about 1% overall. Also updated libzigc to now use `SafeAllocator` when applicable.
gooncreeper force-pushed safe-allocator from f327e2a8e2
Some checks failed
ci / x86_64-freebsd-release (pull_request) Successful in 36m11s
ci / x86_64-netbsd-release (pull_request) Successful in 36m34s
ci / x86_64-netbsd-debug (pull_request) Successful in 43m43s
ci / x86_64-freebsd-debug (pull_request) Successful in 55m1s
ci / aarch64-macos-release (pull_request) Successful in 1h4m25s
ci / powerpc64le-linux-release (pull_request) Failing after 1h11m6s
ci / aarch64-linux-release (pull_request) Failing after 1h11m52s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h28m12s
ci / aarch64-macos-debug (pull_request) Successful in 1h35m31s
ci / x86_64-openbsd-release (pull_request) Successful in 1h16m28s
ci / x86_64-windows-debug (pull_request) Successful in 1h19m14s
ci / x86_64-windows-release (pull_request) Successful in 1h12m1s
ci / x86_64-linux-debug (pull_request) Failing after 3h0m23s
ci / powerpc64le-linux-debug (pull_request) Failing after 3h1m47s
ci / x86_64-linux-release (pull_request) Failing after 3h7m40s
ci / aarch64-linux-debug (pull_request) Failing after 3h17m54s
ci / x86_64-linux-debug-llvm (pull_request) Failing after 4h51m28s
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
ci / s390x-linux-debug (pull_request) Has been cancelled
ci / s390x-linux-release (pull_request) Has been cancelled
to 8e89f3aaa9
Some checks failed
ci / x86_64-netbsd-release (pull_request) Successful in 34m34s
ci / x86_64-freebsd-release (pull_request) Successful in 39m21s
ci / x86_64-netbsd-debug (pull_request) Successful in 44m43s
ci / x86_64-freebsd-debug (pull_request) Successful in 50m29s
ci / x86_64-openbsd-release (pull_request) Successful in 53m58s
ci / x86_64-openbsd-debug (pull_request) Successful in 58m25s
ci / aarch64-macos-release (pull_request) Successful in 1h2m18s
ci / x86_64-windows-release (pull_request) Successful in 1h8m49s
ci / x86_64-windows-debug (pull_request) Successful in 1h11m24s
ci / aarch64-macos-debug (pull_request) Successful in 1h12m56s
ci / aarch64-linux-release (pull_request) Successful in 1h28m39s
ci / powerpc64le-linux-release (pull_request) Successful in 1h57m29s
ci / x86_64-linux-release (pull_request) Failing after 2h52m1s
ci / x86_64-linux-debug (pull_request) Failing after 3h0m41s
ci / loongarch64-linux-release (pull_request) Successful in 2h3m39s
ci / aarch64-linux-debug (pull_request) Failing after 3h41m59s
ci / s390x-linux-release (pull_request) Successful in 2h23m41s
ci / powerpc64le-linux-debug (pull_request) Failing after 4h39m48s
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / x86_64-linux-debug-llvm (pull_request) Has been cancelled
ci / s390x-linux-debug (pull_request) Has been cancelled
2026年04月24日 03:42:39 +02:00
Compare

I canceled the current CI run on this because the OOMs are causing other jobs on the same machines to fail.

I'm not sure if it's a bug in this PR or you just need to bump some max_rss values.

I canceled the current CI run on this because the OOMs are causing other jobs on the same machines to fail. I'm not sure if it's a bug in this PR or you just need to bump some `max_rss` values.
gooncreeper force-pushed safe-allocator from 8e89f3aaa9
Some checks failed
ci / x86_64-netbsd-release (pull_request) Successful in 34m34s
ci / x86_64-freebsd-release (pull_request) Successful in 39m21s
ci / x86_64-netbsd-debug (pull_request) Successful in 44m43s
ci / x86_64-freebsd-debug (pull_request) Successful in 50m29s
ci / x86_64-openbsd-release (pull_request) Successful in 53m58s
ci / x86_64-openbsd-debug (pull_request) Successful in 58m25s
ci / aarch64-macos-release (pull_request) Successful in 1h2m18s
ci / x86_64-windows-release (pull_request) Successful in 1h8m49s
ci / x86_64-windows-debug (pull_request) Successful in 1h11m24s
ci / aarch64-macos-debug (pull_request) Successful in 1h12m56s
ci / aarch64-linux-release (pull_request) Successful in 1h28m39s
ci / powerpc64le-linux-release (pull_request) Successful in 1h57m29s
ci / x86_64-linux-release (pull_request) Failing after 2h52m1s
ci / x86_64-linux-debug (pull_request) Failing after 3h0m41s
ci / loongarch64-linux-release (pull_request) Successful in 2h3m39s
ci / aarch64-linux-debug (pull_request) Failing after 3h41m59s
ci / s390x-linux-release (pull_request) Successful in 2h23m41s
ci / powerpc64le-linux-debug (pull_request) Failing after 4h39m48s
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / x86_64-linux-debug-llvm (pull_request) Has been cancelled
ci / s390x-linux-debug (pull_request) Has been cancelled
to c16a0e43cb
Some checks failed
ci / x86_64-netbsd-release (pull_request) Failing after 33m55s
ci / x86_64-freebsd-release (pull_request) Failing after 35m49s
ci / x86_64-netbsd-debug (pull_request) Failing after 42m22s
ci / x86_64-freebsd-debug (pull_request) Failing after 47m56s
ci / x86_64-windows-release (pull_request) Failing after 56m3s
ci / x86_64-openbsd-release (pull_request) Failing after 56m32s
ci / x86_64-openbsd-debug (pull_request) Failing after 58m58s
ci / x86_64-windows-debug (pull_request) Failing after 1h11m20s
ci / aarch64-linux-release (pull_request) Successful in 1h33m4s
ci / aarch64-linux-debug (pull_request) Has been cancelled
ci / aarch64-macos-debug (pull_request) Has been cancelled
ci / aarch64-macos-release (pull_request) Has been cancelled
ci / x86_64-linux-release (pull_request) Has been cancelled
ci / x86_64-linux-debug-llvm (pull_request) Has been cancelled
ci / powerpc64le-linux-debug (pull_request) Has been cancelled
ci / s390x-linux-debug (pull_request) Has been cancelled
ci / x86_64-linux-debug (pull_request) Has been cancelled
ci / powerpc64le-linux-release (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
ci / s390x-linux-release (pull_request) Has been cancelled
2026年04月26日 19:04:06 +02:00
Compare
Author
Contributor
Copy link

Just pushed an update that decreases memory usage by ~15%. For libzigc I disabled storing stack traces since they are usually unreachable, so memory usage should be even less. The increased memory usage was certainly from the libzigc upgrade since the compiler uses it when linking libc, so hopefully this reduces memory usage enough. Feel free to cancel the CI if it OOMs again.

Just pushed an update that decreases memory usage by ~15%. For libzigc I disabled storing stack traces since they are usually unreachable, so memory usage should be even less. The increased memory usage was certainly from the libzigc upgrade since the compiler uses it when linking libc, so hopefully this reduces memory usage enough. Feel free to cancel the CI if it OOMs again.
Author
Contributor
Copy link

The memory usage was much better, but still higher then the current max rss values. I am going to omit the libzigc upgrade for now and leave it as a followup to reduce the scope of this PR.

The memory usage was much better, but still higher then the current max rss values. I am going to omit the libzigc upgrade for now and leave it as a followup to reduce the scope of this PR.
gooncreeper force-pushed safe-allocator from c16a0e43cb
Some checks failed
ci / x86_64-netbsd-release (pull_request) Failing after 33m55s
ci / x86_64-freebsd-release (pull_request) Failing after 35m49s
ci / x86_64-netbsd-debug (pull_request) Failing after 42m22s
ci / x86_64-freebsd-debug (pull_request) Failing after 47m56s
ci / x86_64-windows-release (pull_request) Failing after 56m3s
ci / x86_64-openbsd-release (pull_request) Failing after 56m32s
ci / x86_64-openbsd-debug (pull_request) Failing after 58m58s
ci / x86_64-windows-debug (pull_request) Failing after 1h11m20s
ci / aarch64-linux-release (pull_request) Successful in 1h33m4s
ci / aarch64-linux-debug (pull_request) Has been cancelled
ci / aarch64-macos-debug (pull_request) Has been cancelled
ci / aarch64-macos-release (pull_request) Has been cancelled
ci / x86_64-linux-release (pull_request) Has been cancelled
ci / x86_64-linux-debug-llvm (pull_request) Has been cancelled
ci / powerpc64le-linux-debug (pull_request) Has been cancelled
ci / s390x-linux-debug (pull_request) Has been cancelled
ci / x86_64-linux-debug (pull_request) Has been cancelled
ci / powerpc64le-linux-release (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
ci / s390x-linux-release (pull_request) Has been cancelled
to 136051d3ef
Some checks failed
ci / x86_64-netbsd-release (pull_request) Successful in 37m34s
ci / x86_64-netbsd-debug (pull_request) Successful in 48m8s
ci / x86_64-freebsd-release (pull_request) Successful in 51m15s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h4m29s
ci / x86_64-openbsd-release (pull_request) Successful in 1h3m27s
ci / powerpc64le-linux-release (pull_request) Failing after 1h31m21s
ci / x86_64-windows-release (pull_request) Successful in 1h2m10s
ci / x86_64-windows-debug (pull_request) Successful in 1h14m33s
ci / aarch64-linux-release (pull_request) Successful in 1h36m38s
ci / aarch64-linux-debug (pull_request) Successful in 2h23m59s
ci / x86_64-linux-debug (pull_request) Failing after 1h14m59s
ci / powerpc64le-linux-debug (pull_request) Successful in 3h25m56s
ci / aarch64-macos-release (pull_request) Successful in 1h30m43s
ci / aarch64-macos-debug (pull_request) Successful in 1h45m53s
ci / s390x-linux-release (pull_request) Successful in 1h29m38s
ci / x86_64-linux-debug-llvm (pull_request) Failing after 2h34m56s
ci / x86_64-linux-release (pull_request) Failing after 2h39m54s
ci / s390x-linux-debug (pull_request) Successful in 2h47m47s
ci / x86_64-freebsd-debug (pull_request) Successful in 58m26s
ci / loongarch64-linux-release (pull_request) Successful in 1h49m12s
ci / loongarch64-linux-debug (pull_request) Successful in 3h4m14s
ci / aarch64-freebsd-debug (pull_request) Successful in 3h58m0s
ci / aarch64-freebsd-release (pull_request) Successful in 3h9m33s
ci / aarch64-netbsd-release (pull_request) Successful in 3h9m3s
ci / aarch64-netbsd-debug (pull_request) Successful in 4h27m57s
ci / riscv64-linux-debug (pull_request) Has been skipped
ci / riscv64-linux-release (pull_request) Has been skipped
2026年04月26日 20:51:04 +02:00
Compare

Good plan.

Good plan.

It's not obvious the connection between the CI failure and this patchset, but I do think it is being caused by it or at least a latent bug being exposed:

mq test-modules
 mq test-std
 mq run test std-wasm32-wasi-none-lime1-Debug-selfhosted-no-lld 3003 pass, 120 skip, 1 fail (3124 total)
error: 'fmt.float.test.format f80' failed:
 expected 604462909807314587353088, found 226854911280625440821279802516316356608
failed command: wasmtime --dir=. -Sinherit-env /home/ci/.cache/act/9bcf39a5166eb613/hostexecutor/zig-local-cache/o/8d2d81fd7af81bb3bb380ba47b5ae273/test.wasm --cache-dir=/home/ci/.cache/act/9bcf39a5166eb613/hostexecutor/zig-local-cache --seed=0x77916c54 --listen=-

note that:

>>> hex(604462909807314587353088)
'0x80000000000000000000'
>>> hex(226854911280625440821279802516316356608)
'0xaaaaaaaaaaaa80000000000000000000'
It's not obvious the connection between the CI failure and this patchset, but I do think it is being caused by it or at least a latent bug being exposed: ``` mq test-modules mq test-std mq run test std-wasm32-wasi-none-lime1-Debug-selfhosted-no-lld 3003 pass, 120 skip, 1 fail (3124 total) error: 'fmt.float.test.format f80' failed: expected 604462909807314587353088, found 226854911280625440821279802516316356608 failed command: wasmtime --dir=. -Sinherit-env /home/ci/.cache/act/9bcf39a5166eb613/hostexecutor/zig-local-cache/o/8d2d81fd7af81bb3bb380ba47b5ae273/test.wasm --cache-dir=/home/ci/.cache/act/9bcf39a5166eb613/hostexecutor/zig-local-cache --seed=0x77916c54 --listen=- ``` note that: ``` >>> hex(604462909807314587353088) '0x80000000000000000000' >>> hex(226854911280625440821279802516316356608) '0xaaaaaaaaaaaa80000000000000000000' ```

You can skip failing test using if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; or wait until #35192 merged and do rebase.

You can skip failing test using `if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;` or wait until #35192 merged and do rebase.
Author
Contributor
Copy link

Thanks, that is my plan. However, more troublesome is the powerpc failure / regression. I seem to be able to reproduce it; I just need to find some more time to debug it and come up with a solution or workaround. Its not really possible to just skip certain tests for that since it affects everything.

Thanks, that is my plan. However, more troublesome is the powerpc failure / regression. I seem to be able to reproduce it; I just need to find some more time to debug it and come up with a solution or workaround. Its not really possible to just skip certain tests for that since it affects everything.

@alexrp can you help out with this powerpc64 failure? It looks like a bug in LLVM powerpc backend.

Personally, I would rather remove powerpc from our CI than block this PR on an LLVM bug.

@alexrp can you help out with this powerpc64 failure? It looks like a bug in LLVM powerpc backend. Personally, I would rather remove powerpc from our CI than block this PR on an LLVM bug.

Seems like you're really not getting along with LLVM's PowerPC backend today.

Reduction: https://github.com/llvm/llvm-project/issues/195561

Workaround:

diff --git a/test/tests.zig b/test/tests.zig
index 28cb147cf8..bdf3e596d8 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -2614,6 +2614,10 @@ fn addOneModuleTest(
 if (mem.eql(u8, options.name, "compiler-rt") or mem.eql(u8, options.name, "libc")) {
 these_tests.root_module.stack_protector = false;
 }
+ // https://github.com/llvm/llvm-project/issues/195561
+ if (target.cpu.arch.isPowerPC()) {
+ these_tests.root_module.stack_protector = false;
+ }
 if (options.build_options) |build_options| {
 these_tests.root_module.addOptions("build_options", build_options);
 }

However, after that we run into this: https://github.com/llvm/llvm-project/issues/195562

Workaround:

diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig
index 777730345e..987941798c 100644
--- a/test/behavior/vector.zig
+++ b/test/behavior/vector.zig
@@ -748,6 +748,7 @@ test "vector reduce operation" {
 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
 if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArm()) return error.SkipZigTest;
 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isPowerPC()) return error.SkipZigTest; // https://github.com/llvm/llvm-project/issues/195562
 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isSPARC()) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23719
 
 const S = struct {
Seems like you're really not getting along with LLVM's PowerPC backend today. Reduction: https://github.com/llvm/llvm-project/issues/195561 Workaround: ```diff diff --git a/test/tests.zig b/test/tests.zig index 28cb147cf8..bdf3e596d8 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -2614,6 +2614,10 @@ fn addOneModuleTest( if (mem.eql(u8, options.name, "compiler-rt") or mem.eql(u8, options.name, "libc")) { these_tests.root_module.stack_protector = false; } + // https://github.com/llvm/llvm-project/issues/195561 + if (target.cpu.arch.isPowerPC()) { + these_tests.root_module.stack_protector = false; + } if (options.build_options) |build_options| { these_tests.root_module.addOptions("build_options", build_options); } ``` However, after that we run into this: https://github.com/llvm/llvm-project/issues/195562 Workaround: ```diff diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig index 777730345e..987941798c 100644 --- a/test/behavior/vector.zig +++ b/test/behavior/vector.zig @@ -748,6 +748,7 @@ test "vector reduce operation" { if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArm()) return error.SkipZigTest; if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isPowerPC()) return error.SkipZigTest; // https://github.com/llvm/llvm-project/issues/195562 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isSPARC()) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23719 const S = struct { ```
gooncreeper force-pushed safe-allocator from 136051d3ef
Some checks failed
ci / x86_64-netbsd-release (pull_request) Successful in 37m34s
ci / x86_64-netbsd-debug (pull_request) Successful in 48m8s
ci / x86_64-freebsd-release (pull_request) Successful in 51m15s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h4m29s
ci / x86_64-openbsd-release (pull_request) Successful in 1h3m27s
ci / powerpc64le-linux-release (pull_request) Failing after 1h31m21s
ci / x86_64-windows-release (pull_request) Successful in 1h2m10s
ci / x86_64-windows-debug (pull_request) Successful in 1h14m33s
ci / aarch64-linux-release (pull_request) Successful in 1h36m38s
ci / aarch64-linux-debug (pull_request) Successful in 2h23m59s
ci / x86_64-linux-debug (pull_request) Failing after 1h14m59s
ci / powerpc64le-linux-debug (pull_request) Successful in 3h25m56s
ci / aarch64-macos-release (pull_request) Successful in 1h30m43s
ci / aarch64-macos-debug (pull_request) Successful in 1h45m53s
ci / s390x-linux-release (pull_request) Successful in 1h29m38s
ci / x86_64-linux-debug-llvm (pull_request) Failing after 2h34m56s
ci / x86_64-linux-release (pull_request) Failing after 2h39m54s
ci / s390x-linux-debug (pull_request) Successful in 2h47m47s
ci / x86_64-freebsd-debug (pull_request) Successful in 58m26s
ci / loongarch64-linux-release (pull_request) Successful in 1h49m12s
ci / loongarch64-linux-debug (pull_request) Successful in 3h4m14s
ci / aarch64-freebsd-debug (pull_request) Successful in 3h58m0s
ci / aarch64-freebsd-release (pull_request) Successful in 3h9m33s
ci / aarch64-netbsd-release (pull_request) Successful in 3h9m3s
ci / aarch64-netbsd-debug (pull_request) Successful in 4h27m57s
ci / riscv64-linux-debug (pull_request) Has been skipped
ci / riscv64-linux-release (pull_request) Has been skipped
to 6e3a812b64
Some checks failed
ci / x86_64-netbsd-release (pull_request) Successful in 34m56s
ci / x86_64-freebsd-release (pull_request) Successful in 36m11s
ci / x86_64-netbsd-debug (pull_request) Successful in 44m36s
ci / x86_64-freebsd-debug (pull_request) Successful in 44m41s
ci / x86_64-openbsd-release (pull_request) Successful in 48m1s
ci / x86_64-openbsd-debug (pull_request) Successful in 49m42s
ci / aarch64-macos-release (pull_request) Successful in 53m24s
ci / aarch64-macos-debug (pull_request) Successful in 1h3m32s
ci / x86_64-linux-debug (pull_request) Successful in 1h14m9s
ci / s390x-linux-release (pull_request) Successful in 1h26m56s
ci / aarch64-linux-release (pull_request) Successful in 1h35m16s
ci / s390x-linux-debug (pull_request) Successful in 2h20m4s
ci / aarch64-linux-debug (pull_request) Successful in 2h36m49s
ci / x86_64-linux-debug-llvm (pull_request) Successful in 3h0m14s
ci / x86_64-linux-release (pull_request) Successful in 3h5m12s
ci / x86_64-windows-release (pull_request) Successful in 1h7m18s
ci / x86_64-windows-debug (pull_request) Successful in 1h21m11s
ci / loongarch64-linux-debug (pull_request) Successful in 3h20m16s
ci / loongarch64-linux-release (pull_request) Successful in 2h2m33s
ci / riscv64-linux-debug (pull_request) Has been skipped
ci / riscv64-linux-release (pull_request) Has been skipped
ci / powerpc64le-linux-release (pull_request) Failing after 1h43m47s
ci / powerpc64le-linux-debug (pull_request) Failing after 3h29m56s
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
2026年05月04日 03:58:48 +02:00
Compare
Author
Contributor
Copy link

Thanks so much for the help; you reduced those magnitudes faster than I would have.

Thanks so much for the help; you reduced those magnitudes faster than I would have.

For the latest failure:

diff --git a/test/tests.zig b/test/tests.zig
index 28cb147cf8..983f434d37 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -2855,6 +2855,11 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
 .max_rss = options.max_rss,
 });
 
+ // https://github.com/llvm/llvm-project/issues/195561
+ if (target.cpu.arch.isPowerPC()) {
+ test_step.root_module.stack_protector = false;
+ }
+
 // This test is intentionally trying to check if the external ABI is
 // done properly. LTO would be a hindrance to this.
 test_step.lto = .none;

Hopefully that gets this PR across the finish line.

For the latest failure: ```diff diff --git a/test/tests.zig b/test/tests.zig index 28cb147cf8..983f434d37 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -2855,6 +2855,11 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { .max_rss = options.max_rss, }); + // https://github.com/llvm/llvm-project/issues/195561 + if (target.cpu.arch.isPowerPC()) { + test_step.root_module.stack_protector = false; + } + // This test is intentionally trying to check if the external ABI is // done properly. LTO would be a hindrance to this. test_step.lto = .none; ``` Hopefully that gets this PR across the finish line.
gooncreeper force-pushed safe-allocator from 6e3a812b64
Some checks failed
ci / x86_64-netbsd-release (pull_request) Successful in 34m56s
ci / x86_64-freebsd-release (pull_request) Successful in 36m11s
ci / x86_64-netbsd-debug (pull_request) Successful in 44m36s
ci / x86_64-freebsd-debug (pull_request) Successful in 44m41s
ci / x86_64-openbsd-release (pull_request) Successful in 48m1s
ci / x86_64-openbsd-debug (pull_request) Successful in 49m42s
ci / aarch64-macos-release (pull_request) Successful in 53m24s
ci / aarch64-macos-debug (pull_request) Successful in 1h3m32s
ci / x86_64-linux-debug (pull_request) Successful in 1h14m9s
ci / s390x-linux-release (pull_request) Successful in 1h26m56s
ci / aarch64-linux-release (pull_request) Successful in 1h35m16s
ci / s390x-linux-debug (pull_request) Successful in 2h20m4s
ci / aarch64-linux-debug (pull_request) Successful in 2h36m49s
ci / x86_64-linux-debug-llvm (pull_request) Successful in 3h0m14s
ci / x86_64-linux-release (pull_request) Successful in 3h5m12s
ci / x86_64-windows-release (pull_request) Successful in 1h7m18s
ci / x86_64-windows-debug (pull_request) Successful in 1h21m11s
ci / loongarch64-linux-debug (pull_request) Successful in 3h20m16s
ci / loongarch64-linux-release (pull_request) Successful in 2h2m33s
ci / riscv64-linux-debug (pull_request) Has been skipped
ci / riscv64-linux-release (pull_request) Has been skipped
ci / powerpc64le-linux-release (pull_request) Failing after 1h43m47s
ci / powerpc64le-linux-debug (pull_request) Failing after 3h29m56s
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
to d0b654af0e
All checks were successful
ci / riscv64-linux-debug (pull_request) Has been skipped
ci / riscv64-linux-release (pull_request) Has been skipped
ci / x86_64-netbsd-release (pull_request) Successful in 42m48s
ci / x86_64-netbsd-debug (pull_request) Successful in 52m34s
ci / x86_64-freebsd-release (pull_request) Successful in 46m28s
ci / x86_64-freebsd-debug (pull_request) Successful in 1h0m25s
ci / aarch64-macos-release (pull_request) Successful in 1h58m58s
ci / aarch64-macos-debug (pull_request) Successful in 2h16m42s
ci / aarch64-linux-release (pull_request) Successful in 1h33m38s
ci / x86_64-openbsd-release (pull_request) Successful in 1h2m44s
ci / powerpc64le-linux-release (pull_request) Successful in 2h9m44s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h11m29s
ci / aarch64-linux-debug (pull_request) Successful in 2h22m51s
ci / x86_64-windows-release (pull_request) Successful in 1h3m5s
ci / x86_64-windows-debug (pull_request) Successful in 1h11m57s
ci / powerpc64le-linux-debug (pull_request) Successful in 4h45m35s
ci / x86_64-linux-debug (pull_request) Successful in 1h7m51s
ci / x86_64-linux-release (pull_request) Successful in 3h27m11s
ci / x86_64-linux-debug-llvm (pull_request) Successful in 3h36m39s
ci / s390x-linux-release (pull_request) Successful in 2h5m6s
ci / s390x-linux-debug (pull_request) Successful in 2h58m50s
ci / loongarch64-linux-release (pull_request) Successful in 2h15m51s
ci / loongarch64-linux-debug (pull_request) Successful in 3h38m26s
ci / aarch64-freebsd-debug (pull_request) Successful in 4h26m15s
ci / aarch64-freebsd-release (pull_request) Successful in 2h49m14s
ci / aarch64-netbsd-release (pull_request) Successful in 3h9m17s
ci / aarch64-netbsd-debug (pull_request) Successful in 4h27m42s
2026年05月05日 22:33:46 +02:00
Compare
andrewrk left a comment
Copy link

Nice work!

Nice work!
andrewrk manually merged commit 4001724b4d into master 2026年05月26日 03:53:33 +02:00
@ -3012,3 +3012,3 @@
=>target_util.defaultFunctionAlignment(target),
.ReleaseSmall=>target_util.minFunctionAlignment(target),
},
}.maxStrict(Type.fromInterned(nav.resolved.?.type).abiAlignment(zcu)),
Owner
Copy link

Hi @gooncreeper, this diff is a bit confusing. The ABI alignment of a function type is always equal to target_util.minFunctionAlignment(target) anyway (see the .func_type case in Type.abiAlignment), so this maxStrict call should be a no-op.

I think this diff actually was required in the old linker code (src/link/Elf/ZigObject.zig), because it seems like updateNavCode is used for non-function NAVs too. My guess, then, is that after making the change there, you also applied it here to what you figured was the equivalent logic, without actually having hit an issue in Elf2. Is that accurate? To be clear, not a problem at all if so (I'll quickly revert this change at some point), I just want to be sure!

Hi @gooncreeper, this diff is a bit confusing. The ABI alignment of a function type is always equal to `target_util.minFunctionAlignment(target)` anyway (see the `.func_type` case in `Type.abiAlignment`), so this `maxStrict` call should be a no-op. I think this diff actually *was* required in the old linker code (`src/link/Elf/ZigObject.zig`), because it seems like `updateNavCode` is used for non-function NAVs too. My guess, then, is that after making the change there, you also applied it here to what you figured was the equivalent logic, without actually having hit an issue in Elf2. Is that accurate? To be clear, not a problem at all if so (I'll quickly revert this change at some point), I just want to be sure!
Author
Contributor
Copy link

That is exactly what happened; apologies for the confusion. There is no problem with reverting this.

That is exactly what happened; apologies for the confusion. There is no problem with reverting this.
First-time contributor
Copy link

Some time ago I did a similar thing for FPC, and for stack traces I used a structure (heaptrc.pp:StackTracesRegistry; which relies on StackTrace; which relies on VarInt) that stores them compressed and deduplicated. Perhaps you’d like to do the same? :)

Compression is achieved by delta encoding the code pointers within each stack trace, then storing them as zigzag-encoded varints. Functions that call one another are often physically close, resulting in small, often 2-byte differences, and even when they are not, they rarely require the full 8 bytes. This saves ×ばつ on average.

Deduplication is complex and requires heavy synchronization, but saves another ×ばつ (for FPC compiling itself), stacking with compression for a total of ×ばつ. In absolute numbers, this reduces 1.2 GB of stack traces (or 10 GB when naively allocating the maximum trace size, which was 64 pointers) to 80 MB.

Come to think of it, such a StackTracesRegistry could in principle be thread-local, but that would reduce the effectiveness of deduplication depending on the workload.

Some time ago I did a [similar thing](https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/1278) for FPC, and for stack traces I used a structure ([`heaptrc.pp:StackTracesRegistry`](https://gitlab.com/freepascal.org/fpc/source/-/blob/3989b8927cf67a516a4ab309c124577e40036ded/rtl/inc/heaptrc.pp#L746); which relies on [`StackTrace`](https://gitlab.com/freepascal.org/fpc/source/-/blob/3989b8927cf67a516a4ab309c124577e40036ded/rtl/inc/heaptrc.pp#L678); which relies on [`VarInt`](https://gitlab.com/freepascal.org/fpc/source/-/blob/3989b8927cf67a516a4ab309c124577e40036ded/rtl/inc/heaptrc.pp#L529)) that stores them compressed and deduplicated. Perhaps you’d like to do the same? :) Compression is achieved by delta encoding the code pointers within each stack trace, then storing them as zigzag-encoded varints. Functions that call one another are often physically close, resulting in small, often 2-byte differences, and even when they are not, they rarely require the full 8 bytes. This saves ×ばつ on average. Deduplication is complex and requires heavy synchronization, but saves another ×ばつ (for FPC compiling itself), stacking with compression for a total of ×ばつ. In absolute numbers, this reduces 1.2 GB of stack traces (or 10 GB when naively allocating the maximum trace size, which was 64 pointers) to 80 MB. Come to think of it, such a `StackTracesRegistry` could in principle be thread-local, but that would reduce the effectiveness of deduplication depending on the workload.
Sign in to join this conversation.
No reviewers
Labels
Clear labels
abi/f32
abi/ilp32
abi/sf
accepted
This proposal is planned.
arch/21k
arch/6502
arch/aarch64
arch/alpha
arch/amdgcn
arch/arc
arch/arc32
arch/arc64
arch/arm
arch/avr
arch/bfin
arch/bpf
arch/colossus
arch/cris
arch/csky
arch/dlx
arch/epiphany
arch/fr30
arch/frv
arch/hexagon
arch/hppa
arch/hppa64
arch/ia64
arch/kalimba
arch/kvx
arch/lanai
arch/lm32
arch/loongarch32
arch/loongarch64
arch/m32r
arch/m68k
arch/m88k
arch/mcore
arch/microblaze
arch/mips
arch/mips64
arch/mmix
arch/moxie
arch/mrisc32
arch/msp430
arch/nds32
arch/ns32k
arch/nvptx
arch/or1k
arch/powerpc
arch/powerpc64
arch/propeller
arch/riscv32
arch/riscv64
arch/rl78
arch/rx
arch/s390x
arch/sh
arch/sparc
arch/sparc64
arch/spirv
arch/spu
arch/tricore
arch/v850
arch/vax
arch/vc4
arch/ve
arch/wasm
arch/x86
arch/x86_64
arch/xcore
arch/xtensa
autodoc
The web application for interactive documentation and generation of its assets.
backend/c
The C backend outputs C source code.
backend/llvm
The LLVM backend outputs an LLVM bitcode module.
backend/self-hosted
The self-hosted backends produce machine code directly.
binutils
Zig's included binary utilities: zig ar, zig dlltool, zig lib, zig ranlib, zig objcopy, and zig rc.
breaking
Implementing this issue could cause existing code to no longer compile or have different behavior.
build system
The Zig build system - zig build, std.Build, the build runner, and package management.
debug info
An issue related to debug information (e.g. DWARF) produced by the Zig compiler.
docs
An issue with documentation, e.g. the language reference or standard library doc comments.
error message
This issue points out an error message that is unhelpful and should be improved.
frontend
Tokenization, parsing, AstGen, ZonGen, Sema, Legalize, and Liveness.
fuzzing
An issue related to Zig's integrated fuzz testing.
incremental
Reuse of internal compiler state for faster compilation.
lib/c
This issue relates to Zig's libc implementation and/or vendored libcs.
lib/compiler-rt
This issue relates to Zig's compiler-rt library.
lib/cxx
This issue relates to Zig's vendored libc++ and/or libc++abi.
lib/std
This issue relates to Zig's standard library.
lib/tsan
This issue relates to Zig's vendored libtsan.
lib/ubsan-rt
This issue relates to Zig's ubsan-rt library.
lib/unwind
This issue relates to Zig's vendored libunwind.
linking
Zig's integrated object file and incremental linker.
miscompilation
The compiler reports success but produces semantically incorrect code.
os/android
os/contiki
os/dragonfly
os/driverkit
os/emscripten
os/freebsd
os/fuchsia
os/haiku
os/hermit
os/hurd
os/illumos
os/ios
os/linux
os/maccatalyst
os/macos
os/managarm
os/netbsd
os/ohos
os/openbsd
os/plan9
os/redox
os/rtems
os/serenity
os/tvos
os/uefi
os/visionos
os/wasi
os/watchos
os/windows
proposal
This issue suggests language modifications. If it also has the "accepted" label then it is planned.
release notes
This issue or pull request should be mentioned in the release notes.
testing
This issue is related to testing the compiler, standard library, or other parts of Zig.
zig cc
Zig as a drop-in C-family compiler.
zig fmt
The Zig source code formatter.
zig reduce
The Zig source code reduction tool.
bounty
https://ziglang.org/news/announcing-donor-bounties
bug
Observed behavior contradicts documented or intended behavior.
contributor-friendly
This issue is limited in scope and/or knowledge of project internals.
downstream
An issue with a third-party project that uses this project.
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
infra
An issue related to project infrastructure, e.g. continuous integration.
optimization
A task to improve performance and/or resource usage.
question
No questions on the issue tracker; use a community space instead.
regression
Something that used to work in a previous version stopped working
upstream
An issue with a third-party project that this project uses.
use case
Describes a real use case that is difficult or impossible, but does not propose a solution.
No labels
abi/f32
abi/ilp32
abi/sf
accepted
arch/21k
arch/6502
arch/aarch64
arch/alpha
arch/amdgcn
arch/arc
arch/arc32
arch/arc64
arch/arm
arch/avr
arch/bfin
arch/bpf
arch/colossus
arch/cris
arch/csky
arch/dlx
arch/epiphany
arch/fr30
arch/frv
arch/hexagon
arch/hppa
arch/hppa64
arch/ia64
arch/kalimba
arch/kvx
arch/lanai
arch/lm32
arch/loongarch32
arch/loongarch64
arch/m32r
arch/m68k
arch/m88k
arch/mcore
arch/microblaze
arch/mips
arch/mips64
arch/mmix
arch/moxie
arch/mrisc32
arch/msp430
arch/nds32
arch/ns32k
arch/nvptx
arch/or1k
arch/powerpc
arch/powerpc64
arch/propeller
arch/riscv32
arch/riscv64
arch/rl78
arch/rx
arch/s390x
arch/sh
arch/sparc
arch/sparc64
arch/spirv
arch/spu
arch/tricore
arch/v850
arch/vax
arch/vc4
arch/ve
arch/wasm
arch/x86
arch/x86_64
arch/xcore
arch/xtensa
autodoc
backend/c
backend/llvm
backend/self-hosted
binutils
breaking
build system
debug info
docs
error message
frontend
fuzzing
incremental
lib/c
lib/compiler-rt
lib/cxx
lib/std
lib/tsan
lib/ubsan-rt
lib/unwind
linking
miscompilation
os/android
os/contiki
os/dragonfly
os/driverkit
os/emscripten
os/freebsd
os/fuchsia
os/haiku
os/hermit
os/hurd
os/illumos
os/ios
os/linux
os/maccatalyst
os/macos
os/managarm
os/netbsd
os/ohos
os/openbsd
os/plan9
os/redox
os/rtems
os/serenity
os/tvos
os/uefi
os/visionos
os/wasi
os/watchos
os/windows
proposal
release notes
testing
zig cc
zig fmt
zig reduce
bounty
bug
contributor-friendly
downstream
enhancement
infra
optimization
question
regression
upstream
use case
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
6 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/zig!31991
Reference in a new issue
ziglang/zig
No description provided.
Delete branch "gooncreeper/zig:safe-allocator"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?