Skip to content

Windows heap allocator attributes and inline rc interface counts: rc/own loops vectorized, rc ray tracer 13% faster - #806

Merged
ASDAlexander77 merged 2 commits into
mainfrom
process-heap-nocapture
Nov 10, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
process-heap-nocapture

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Problem

On Windows, ProcessHeapPass renames malloc/realloc/free to the __tslang_heap_* helpers. LLVM declares the C functions' block argument captures(none); the helpers had allocptr but not that. Under rc and own, an array header that a function may release on any path counted as escaped, so a store to the array's elements might have written the header: every loop reloaded the elements' pointer on each iteration ("cannot identify array bounds") and was not vectorized. Linux does not run the pass, so it was not affected.

Found with tslang/benchmarks/numeric on Windows: the rc executable had 8 packed SIMD instructions against ~270 for gc/none/own/Rust, and own's hash kernel took 160 ms against 67.

Change

llvm.nocapture on argument 0 of __tslang_heap_free and __tslang_heap_realloc.

noalias on realloc's result too, as LLVM says of realloc, and its allockind is "realloc" alone: it was "realloc,uninitialized", which claims the grown block's contents are undefined. With the result fresh, LLVM then read a grown array's old elements as undefined (00array_splice: b[0] after a splice), and that broke five array tests until the flag was dropped. LLVM declares realloc the same way.

Results (Windows 11 x64, Release, median of 15, ms)

Build saxpy triad stencil dot matmul hash
rc, main 130.9 150.4 146.7 94.5 84.9 157.7
rc, this PR 92.3 117.8 102.2 103.6 68.5 75.1
own, main 88.7 114.2 93.3 94.7 59.4 160.0
own, this PR 99.9 121.4 108.2 103.2 68.7 75.0
Rust, same run as this PR 93.8 106.6 107.1 109.4 64.0 76.1

The machine ran ~10% slower during the "this PR" run (Rust moved by the same amount); rc and own are now level with Rust on every kernel. Raytrace (median of 9): rc 117.5 → 114.2, none 78.2 → 73.2, own 77.5 → 76.4, gc 74.4 → 74.1; all checksums match.

Later, quieter run with both changes (ms): gc 87.8/107.9/92.5/91.6/53.8/64.6, rc 86.2/114.4/93.9/94.8/56.7/65.5, none 88.1/112.6/95.1/92.6/53.4/62.7, own 85.6/111.8/94.1/91.2/53.8/62.3, Rust 77.0/93.5/94.7/93.5/52.0/65.4 (saxpy/triad/stencil/dot/matmul/hash). Raytrace: gc 71.0, rc 110.1, none 70.7, own 72.8, Rust 54.3.

rc: an interface's count changed inline

A sampling profile of the rc ray tracer put most of rc's extra time against none in retains and releases of interfaces: an interface value is counted through the type descriptor its vtable names (vtable, tag, descriptor, indirect call), which LLVM can neither inline nor pair. Sphere.intersect retained its Intersection's thing that way on every hit and spilled the 80-byte result to the stack.

Every type whose value references a plainly counted block (class/object instances, strings, any boxes, Shared<T>) now shares one retain routine (__tslang_retain_block_slot, same body as before). Under rc, a retain through an interface whose descriptor names that routine increments inline; a release decrements inline unless it is the last reference or the block is shared/immortal, and otherwise calls the descriptor's routine with a slot of its own. --atomic-rc keeps the call for releases. gc, none and own are untouched.

Ray tracer, rc: 110-114 ms -> 95.9 ms (gc 73.1, none 73.3, own 75.8, Rust 56.3).

New test 00rc_interface_count_inline.ts (gc/rc/none, exe/jit): copies of interface values in @value records, last references dropped through the interface, object literals, immortal globals. With the inline release taking off two references instead of one it segfaults (checked).

The mm differential fuzzer (1220 programs) found one rc crash; it reproduces with the fast path disabled too (an assignment to a global's field inside a call argument, in try/finally: the known arg-assign shape), so it is not from this change.

Testing

ctest -C Release: 100% passed, 6943 tests.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits November 10, 2026 19:01
…n array loops are vectorized

ProcessHeapPass renames malloc/realloc/free to the __tslang_heap_* helpers on Windows. LLVM
declares the C functions' block argument captures(none); the helpers lacked it, so under rc and
own an array header released on any path of a function counted as escaped, a store to the
elements might have written the header, and every loop reloaded the elements' pointer and was
not vectorized (numeric benchmark: rc 8 packed instructions against ~270, own's hash 2.4x slower).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s release does not capture

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit e08d6ee into main Nov 10, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the process-heap-nocapture branch November 10, 2026 19:41
@ASDAlexander77 ASDAlexander77 changed the title Windows heap: free and realloc do not capture the block, so rc and own array loops are vectorized Windows heap allocator attributes and inline rc interface counts: rc/own loops vectorized, rc ray tracer 13% faster Nov 10, 2026
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.

1 participant