Repository navigation
Declare the process-heap allocator to LLVM as LLVM declares malloc - #683
Merged
Merged
Conversation
ProcessHeapPass marked __tslang_heap_malloc/calloc/aligned_alloc as writing other memory and gave their result no `noalias`. So every allocation clobbered whatever the program had just stored: a field written into a fresh object was loaded back from the heap after the next `new` instead of reused, and the object could never be deleted. In the ray tracer every vector of `Vector.plus(Vector.times(k, d), p)` stayed on the heap although LLVM had inlined the helpers. An allocation now touches only the allocator's state (`memory(inaccessiblemem: readwrite)`) and returns a `noalias` block, as LLVM's own malloc does. Writing the allocator's state still keeps two equal allocations from merging (the GC_malloc case in GCPass). Ray tracer, 512x512, median of 7: own 597 -> 444 ms, none 642 -> 434 ms, gc unchanged (its own allocator), rc 606 -> 630 ms. The benchmark README records the numbers and what is left between own and Rust. Test: 00fresh_objects_folded.ts runs, and fresh-objects-folded.cmake checks that the optimized IR of `keep` loads no field back under none, rc and own (it fails before this change). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ProcessHeapPass::markAsAllocatordeclared__tslang_heap_malloc/calloc/aligned_allocas writing other memory (memory(write, argmem: none, inaccessiblemem: readwrite)), and their result had nonoalias. So every allocation clobbered whatever the program had just stored. A field written into a fresh object was loaded back from the heap after the nextnewinstead of being reused, and the object could never be deleted. In the ray tracer, LLVM inlinesVector.plus,Color.scaleand the rest, but every inlined copy still allocated and kept its block.Fix
An allocation now touches only the allocator's state (
memory(inaccessiblemem: readwrite)) and returns anoaliasblock, as LLVM's ownmallocdoes. Writing the allocator's state still keeps two equal allocations from merging (theGC_malloccase described in GCPass). Releases and resizes are unchanged.Results
tslang/benchmarks/raytrace, 512x512, median of 7,bench.ps1; every build prints the same checksum:rc is 4% slower in both runs I made; I have not found why. The benchmark README gets a "Results 2026-10-24" section with these numbers and an account of what still separates own from Rust (54 ms): the immortal-header check on each own release, and objects escaping into interface calls, interface literals and closures.
Tests
00fresh_objects_folded.ts(compile and JIT): a fresh object's field read after anothernew.fresh-objects-folded.cmake: the optimized IR ofkeeploads no field back, under none, rc and own. It fails on main.🤖 Generated with Claude Code