Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion tslang/benchmarks/numeric/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,42 @@ TSLANG=<path to tslang> bash tslang/benchmarks/numeric/bench.sh
With a kernel's name as its argument a program runs only that kernel, which is how `bench.sh` times
them one by one. A JIT figure includes the compiler's start-up, about 13 ms here.

## Results 2026-11-10
## Results 2026-11-10: Windows

Release, Windows 11 x64; main d64978ed, and the same tree with the heap's release and resize
declared not to capture their block (below). `bench.sh` runs under Git Bash; the lib paths
(`TSLANG_LIB_PATH`, `GC_LIB_PATH`, `LLVM_LIB_PATH`) point at the build tree. Median of 15 runs
after a warm-up, ms; every build prints the same check values. The "after" rows are one run, in
which Rust too was about 10% slower than in the "before" run: compare a row with the Rust row of
its own run.

| Build | saxpy | triad | stencil | dot | matmul | hash |
|---|---|---|---|---|---|---|
| tslang gc | 87.3 | 112.3 | 97.3 | 96.7 | 57.3 | 66.8 |
| tslang rc | 130.9 | 150.4 | 146.7 | 94.5 | 84.9 | 157.7 |
| tslang none | 88.1 | 112.7 | 92.2 | 94.2 | 60.9 | 67.0 |
| tslang own | 88.7 | 114.2 | 93.3 | 94.7 | 59.4 | 160.0 |
| Rust | 85.9 | 98.4 | 97.1 | 95.0 | 55.5 | 66.8 |
| C++ (clang) | 133.4 | 145.9 | 143.5 | 93.3 | 75.2 | 157.8 |
| tslang rc, release does not capture | 92.3 | 117.8 | 102.2 | 103.6 | 68.5 | 75.1 |
| tslang own, release does not capture | 99.9 | 121.4 | 108.2 | 103.2 | 68.7 | 75.0 |
| Rust, the same run | 93.8 | 106.6 | 107.1 | 109.4 | 64.0 | 76.1 |

- On Windows, under every memory model but gc, `malloc`, `realloc` and `free` become the process
heap's `__tslang_heap_*` helpers (ProcessHeapPass). LLVM declares the C `free` and `realloc` not
to capture the block they are given; the helpers did not say so. A header that a function may
release on any path then counted as escaped, so a store to the elements might have written it,
and the loop loaded the elements' pointer again on every iteration. The rc executable had 8
packed floating-point and integer instructions, against 234-282 for gc, none, own and Rust, and
own's `hash` loop was not vectorized either. Linux does not run the pass. Declared `captures(none)`, rc and
own are level with Rust on every kernel.
- `noalias` on the resize's result, which LLVM also says of `realloc`, vectorizes a few more loops
under none, but crashes five array tests (0xC0000409); it is left out.
- The C++ port is about twice as slow here as on Linux (82 packed instructions): clang with the
MSVC standard library does not vectorize most of its loops. That is the port's build, not a
baseline to compare with.

## Results 2026-11-10: Linux

Release, Ubuntu 24.04 x64, a 4-core cloud VM (Xeon 2.1 GHz, AVX2); main d78c735 with the collector's
allocations declared `noalias` (below). Median of 9 runs after a warm-up, ms; every build prints
Expand Down
27 changes: 27 additions & 0 deletions tslang/benchmarks/raytrace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ pwsh tslang/benchmarks/raytrace/bench.ps1
- Rust: `opt-level=3`, `lto="fat"`, `codegen-units=1`, `panic="abort"`
- C++: `clang++ -std=c++20 -O3`, and `cl /std:c++20 /O2 /EHsc /MT`

## Results 2026-11-10: Windows

Release, Windows 11 x64, the machine of the 10-31 run; main d64978ed, and the same tree with the
heap's release and resize declared not to capture their block (see `../numeric`). `bench.ps1`,
median of 9 runs after a warm-up; every build prints the same checksum.

| Build | main | release does not capture | vs Rust idiomatic (57 ms) |
|---|---|---|---|
| tslang gc | 74.4 ms | 74.1 ms | 1.3x |
| tslang gc, `--no-stack-promotion` | 159.3 ms | 155.2 ms | |
| tslang rc | 117.5 ms | 114.2 ms | 2.0x |
| tslang none | 78.2 ms | 73.2 ms | 1.3x |
| tslang own | 77.5 ms | 76.4 ms | 1.3x |
| Rust idiomatic | 57.2 ms | 57.2 ms | 1x |
| Rust Rc-boxed | 528.7 ms | 502.6 ms | 8.8x |
| C++ idiomatic (clang) | 52.7 ms | 51.6 ms | 0.9x |
| C++ idiomatic (MSVC) | 71.6 ms | 71.2 ms | 1.2x |
| C++ shared_ptr (clang) | 858.4 ms | 844.0 ms | 14.8x |
| C++ shared_ptr (MSVC) | 911.3 ms | 910.2 ms | 16x |

- Against 10-31 (gc 71, rc 110, none 70, own 77) the four models are within a few percent; Rust
and C++ also measured 4-5% slower than then.
- gc now depends on stack promotion: without it gc takes twice as long, where on 10-24 the flag
changed it by 2% or less. Under rc and own the flag changes nothing, under none 10 ms. Not
looked into.
- The heap change is for loops over arrays; here it moves the models by no more than the noise.

## Results 2026-11-10: Linux

Release, Ubuntu 24.04 x64, a 4-core cloud VM (Xeon 2.1 GHz); main d78c735 with the collector's
Expand Down
10 changes: 9 additions & 1 deletion tslang/lib/TypeScript/ProcessHeapPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,23 @@ class ProcessHeapPass : public mlir::PassWrapper<ProcessHeapPass, ModulePass>
LLVM::ModRefInfo::NoModRef, LLVM::ModRefInfo::NoModRef);
funcOp.setMemoryEffectsAttr(memoryEffects);

// and no other pointer reaches the block, as `noalias` says of malloc's result
// and no other pointer reaches the block, as `noalias` says of malloc's and realloc's result.
// Without it on realloc, a store into a grown array's elements might have written the
// array's header, so a loop over the elements loaded their pointer again on every
// iteration and was not vectorized.
if (!takesBlock && funcOp.getNumResults() > 0)
{
funcOp.setResultAttr(0, LLVM::LLVMDialect::getNoAliasAttrName(), mlir::UnitAttr::get(context));
}

// A release or a resize does not keep the block it is given, as LLVM declares free's and
// realloc's (`captures(none)`). Without it, an object whose release is on any path of a
// function counts as escaped there, so under rc and own a header that a function may
// release was assumed reachable through its own elements, with the same effect on loops.
if (takesBlock && funcOp.getNumArguments() > 0)
{
funcOp.setArgAttr(0, LLVM::LLVMDialect::getAllocatedPointerAttrName(), mlir::UnitAttr::get(context));
funcOp.setArgAttr(0, LLVM::LLVMDialect::getNoCaptureAttrName(), mlir::UnitAttr::get(context));
}

auto entry = [&](llvm::StringRef key, llvm::StringRef value) {
Expand Down
Loading