Skip to content

boolean[] backed by i8: 30% sieve speedup#493

Merged
cs01 merged 6 commits intomainfrom
feat/boolean-array-i8
Mar 21, 2026
Merged

boolean[] backed by i8: 30% sieve speedup#493
cs01 merged 6 commits intomainfrom
feat/boolean-array-i8

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 21, 2026

Summary

boolean[] now uses 1-byte i8 elements (via %Uint8Array struct) instead of 8-byte double elements. For a 1M-element boolean array, this reduces the working set from 8MB to 1MB — fitting in L2 cache instead of spilling to L3.

Measured: 30% speedup on prime sieve benchmark (174ms → 247ms baseline, 100 iterations of 1M-element sieve)

Changes

  • Compiler internals first: converted 6 compiler-internal boolean[] uses (outputIsTerminator, isConst, isDemoted) to number[] so the optimization doesn't affect self-hosting
  • Type system: boolean[] maps to %Uint8Array* instead of %Array*
  • Type inference: isUint8ArrayExpression detects boolean[] variables; isArrayExpression no longer matches boolean[]
  • Variable allocator: boolean[] allocates as SymbolKind_Uint8Array
  • Array literals: boolean array literals create %Uint8Array structs with i8 data
  • Array push: boolean push stores i8 (0/1) instead of double (0.0/1.0)
  • Index read/write: reuses existing Uint8Array paths (i8↔double conversion already works)

Test plan

  • npm run verify:quick passes (tests + self-hosting Stage 1)
  • All 4 boolean array test fixtures pass (basic, push, index-assign, prime sieve)
  • Self-hosting unaffected (compiler internals use number[] now)
  • 30% sieve speedup measured locally

@github-actions
Copy link
Contributor

github-actions bot commented Mar 21, 2026

Benchmark Results (Linux x86-64)

Benchmark C ChadScript Go Node Bun Place
Binary Trees 1.475s 1.180s 2.676s 1.161s 0.968s 🥉
Cold Start 0.8ms 0.8ms 1.2ms 23.0ms 8.8ms 🥇
Fibonacci 0.814s 1.473s 1.560s 3.162s 1.946s 🥈
File I/O 0.116s 0.091s 0.087s 0.200s 0.173s 🥈
JSON Parse/Stringify 0.004s 0.005s 0.017s 0.015s 0.007s 🥈
Matrix Multiply 0.487s 0.695s 0.618s 0.362s 0.351s #5
Monte Carlo Pi 0.388s 0.408s 0.404s 2.242s 6.030s 🥉
N-Body Simulation 1.665s 2.120s 2.205s 2.395s 3.255s 🥈
Quicksort 0.213s 0.245s 0.213s 0.261s 0.226s #4
SQLite 0.342s 0.400s 0.419s 0.401s 🥈
Sieve of Eratosthenes 0.015s 0.028s 0.020s 0.039s 0.036s 🥉
String Manipulation 0.008s 0.044s 0.016s 0.035s 0.027s #5

CLI Tool Benchmarks

Benchmark ChadScript grep node xxd Place
Hex Dump 0.422s 0.918s 0.128s 🥈
Recursive Grep 0.018s 0.009s 0.093s 🥈

@cs01 cs01 merged commit e1e77d7 into main Mar 21, 2026
13 checks passed
@cs01 cs01 deleted the feat/boolean-array-i8 branch March 21, 2026 07:31
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