Repository navigation
gc: allocations are noalias, so array loops are vectorized; a numeric benchmark; parser: no copies of the line table - #805
Merged
Conversation
Six kernels over flat arrays (saxpy, triad, stencil, dot, matmul and an integer hash), each ending in a check value every build prints. bench.sh builds nbench.ts under every memory model, optionally under the JIT, and the two ports, and times each kernel by itself. The README has the first results, the JIT before and after the optimizer was given the host's CPU, and the finding that the gc build's loops are not vectorized. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J8KRfVk4FT2FALW47Ux2Fp
… vectorized An array is a header holding the pointer to its elements. GC_malloc and GC_realloc were declared without noalias, which LLVM gives malloc's and realloc's results by name, so a store to an element might have written the header: every loop loaded the elements' pointer again on each iteration and none was vectorized. The numeric benchmark ran 2 to 5 times slower under gc than under the other memory models; it is now level with them. The README's Performance section has the numeric benchmark's table, and the benchmarks' READMEs the results on Linux. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J8KRfVk4FT2FALW47Ux2Fp
…no regex over a whole file for a shebang - getLineStarts returned the file's table of line starts by value, and computeLineAndCharacterOfPosition and computeLineOfPosition took it by value again: three copies of the table for every source location. They now pass a reference. Compiling a small program with the default library executed 983M instructions, a quarter of them these copies; it is 725M. - '^#!.*' can only match at the start of the text, but regex_search tried it at every position of every file (3% of the same compile). The first two characters are tested before the regex is used. - getDirectiveFromComment took its regex by value, a copy per comment; it takes a reference, and a comment with no '@' is not searched. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J8KRfVk4FT2FALW47Ux2Fp
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.
Adds a benchmark of tight numeric loops over arrays, fixes what it found (under
-mm=gcnone of the loops was vectorized), and removes two hot spots from the parser that a profile of compile time showed.The gc fix
An array is a header holding the pointer to its elements. Under rc, none and own both come from
malloc/realloc, whose results LLVM knows by name to benoalias. Under gc they come fromGC_malloc/GC_realloc, which were declared without it, so a store to an element might have written the header: every loop loaded the elements' pointer again on each iteration, and the vectorizer gave up.GCPassnow declares the results ofGC_malloc,GC_malloc_atomic,GC_malloc_uncollectable,GC_memalignandGC_reallocnoalias.gc executable, median ms, before → after (Ubuntu 24.04 x64, 4-core cloud VM):
gc is now level with the other three memory models. The ray tracer benchmark is unchanged by it.
The benchmark
tslang/benchmarks/numeric/:nbench.ts: six kernels over flat 4096-element arrays (saxpy, triad, a 3-point stencil, dot, 64x64 matmul, an integer hash), each ending in a check value.rust/,cpp/: ports of the same kernels; every build prints the same six values.bench.sh: builds under every memory model (and under the JIT withJIT_LIB), checks the values, times each kernel by itself.README.md: results, gc before and after, and the JIT before and after Optimizer: code generator's CPU for the cost model, --size_level at every level, inlining of functions with a try off Windows #804 (saxpy, triad, matmul and hash about 20-26% faster under-mm=none, now vectorized for the host's AVX2).READMEs
benchmarks/raytrace/README.md: results on Linux, including that the baseline-x86-64 Rust port is unexpectedly slow there (not looked into).The parser (compile time)
From a callgrind profile of compiling a small program that uses the default library:
getLineStartsreturned the file's table of line starts by value, andcomputeLineAndCharacterOfPositionandcomputeLineOfPositiontook it by value again: three copies of the table per source location. They pass a reference now. Instructions executed for that compile: 983M → 725M.^#!.*can only match at the start of the text, butregex_searchtried it at every position of every file (3% of the same compile). The first two characters are tested before the regex is used.getDirectiveFromCommenttook its regex by value, a copy per comment; it takes a reference, and a comment with no@is not searched.Testing
Built on Ubuntu 24.04 against the prebuilt LLVM 22.1.8, release test programs, before the parser commit:
ctest -E '^test-jit'): 3955 of 3955 passedctest -R '^test-jit'): 2951 of 2951 passedThe parser commit: its first change was built and profiled; the other two had not been built when it was pushed, so this PR's CI is their first build.
Not run locally: the debug test programs, and anything on Windows.
🤖 Generated with Claude Code
https://claude.ai/code/session_01J8KRfVk4FT2FALW47Ux2Fp