Skip to content

Commit b12efb3

Browse files
authored
Use Bun
1 parent e383e94 commit b12efb3

File tree

19 files changed

+15584
-20
lines changed

19 files changed

+15584
-20
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# We can ignore test to avoid any changes to accidently be comitted. It also avoid AIs spending time looking at it.
2+
/test/
3+
14
# Logs
25
logs
36
*.log

README.md

Lines changed: 100 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> Testing SQL compabillity for [AlaSQL](https://github.com/agershun/alasql) on the 5,047,257 tests from http://www.sqlite.org/sqllogictest
44
5-
_See the [most recent result](./results/output.md)_
5+
_See the [most recent result](./results/output-bun2.md) - also available: [Bun](./results/output-bun.md) | [Node.js](./results/output-node.md)_
66

77

88
Why?
@@ -20,17 +20,99 @@ The format of the tests are desribed here: http://www.sqlite.org/sqllogictest/do
2020
How?
2121
----
2222

23-
Install dependencies `npm install and run all the tests with:
23+
Install dependencies:
2424

25-
npm test
25+
bun install
2626

27-
The result will output to `results/output.md`
27+
To make sure you are testing the most recent version of AlaSQL please run:
2828

29-
To make sure you are testing the most recent version of AlaSQL please run the following:
29+
bun install alasql
3030

31-
npm install alasql
31+
## Running Tests
3232

33-
Please see the config section of the `run` files to run tests on local version instead of npm version.
33+
### Bun2 (Recommended) - Multi-threaded Workers
34+
Run tests with Bun2 using parallel workers across multiple threads:
35+
36+
bun run test-bun2
37+
# or run demo only
38+
bun run test-bun2-demo
39+
40+
**Results output to:** `results/output-bun2.md`
41+
42+
### Bun (Legacy) - Single-threaded
43+
Run tests with Bun (single-threaded, faster than Node.js):
44+
45+
bun run test-bun
46+
# or run demo only
47+
bun run test-bun-demo
48+
49+
**Results output to:** `results/output-bun.md`
50+
51+
### Node.js (Legacy) - Single-threaded
52+
Run tests with Node.js (single-threaded, slowest):
53+
54+
bun run test-node
55+
# or run demo only
56+
bun run test-node-demo
57+
58+
**Results output to:** `results/output-node.md`
59+
60+
### All Available Scripts
61+
62+
| Script | Command | Description |
63+
|--------|---------|-------------|
64+
| `bun test` | `bun test-bun2` | Default test command (runs Bun2) |
65+
| `bun run test-bun2` | `bun run bun2-run/run.js --light > results/output-bun2.md` | Bun2 multi-threaded tests (recommended) |
66+
| `bun run test-bun2-demo` | `bun run bun2-run/run.js --demo --light` | Bun2 demo tests only |
67+
| `bun run test-bun` | `bun run bun-run/run.js --light > results/output-bun.md` | Bun single-threaded tests |
68+
| `bun run test-bun-demo` | `bun run bun-run/run.js --demo --light` | Bun demo tests only |
69+
| `bun run test-node` | `node --expose-gc node-run/run.js --light > results/output-node.md` | Node.js single-threaded tests |
70+
| `bun run test-node-demo` | `node --expose-gc node-run/run.js --demo --light` | Node.js demo tests only |
71+
72+
**Note:** The `--light` flag means the tests will only parse the SQL and not execute the queries. This is faster and useful for identifying SQL compilation issues.
73+
74+
### Configuration Options
75+
76+
You can customize test execution by passing flags to the run scripts:
77+
78+
| Flag | Description |
79+
|------|-------------|
80+
| `--light` | Only parse SQL, don't execute queries (faster) |
81+
| `--demo` | Run demo tests only (quick validation during devleopment of test parser) |
82+
| `--concurrency=N` | Set number of worker threads (Bun2 only) |
83+
| `--include=PATTERN` | Only run test files matching regex pattern |
84+
| `--exclude=PATTERN` | Skip test files matching regex pattern |
85+
| `--printAllErrors` | Print all errors instead of sampling |
86+
| `--no-skipTests` | Don't skip previously passed tests |
87+
| `--mimic=DIALECTS` | Test against specific SQL dialects |
88+
89+
## Test Runners
90+
91+
This project includes three test runner implementations:
92+
93+
- **`bun2-run/`** - **(Recommended)** Bun implementation using persistent worker pool for true multi-threading across multiple CPU cores. Provides the best performance by utilizing all available CPU cores with parallel workers.
94+
- **`bun-run/`** - Bun-optimized implementation leveraging Bun's native file I/O and faster runtime (single-threaded, 2-3x faster than Node.js)
95+
- **`node-run/`** - Original Node.js implementation using paralleljs for multi-threading (legacy, slowest)
96+
97+
### Performance Comparison
98+
99+
| Runner | Threading | Performance | Use Case |
100+
|--------|-----------|-------------|----------|
101+
| **Bun2** | Multi-threaded workers | **Fastest** | Recommended for all testing |
102+
| Bun | Single-threaded | Fast (2-3x vs Node) | Legacy Bun support |
103+
| Node.js | Single-threaded | Baseline | Legacy Node.js support |
104+
105+
### Bun2 Architecture
106+
107+
Bun2 uses a persistent worker pool with the following advantages:
108+
- **True parallelism**: Tests run simultaneously across multiple CPU cores
109+
- **Worker reuse**: Workers are created once and reused across test files
110+
- **Isolated state**: Each worker maintains isolated AlaSQL state (reset per job)
111+
- **Shared parser**: PEG parser is generated once at startup and shared via file URL
112+
- **Buffered output**: Test output is buffered per-file to avoid interleaving
113+
- **Graceful shutdown**: Workers terminate cleanly when all jobs complete
114+
115+
Please see the config section in the respective `run.js` files to customize test execution.
34116

35117

36118

@@ -113,4 +195,14 @@ ToDo
113195

114196

115197
## Not ToDo
116-
- Implement mocha testframework (testresults does not get printed before all are done - so it fills the memory)
198+
- Implement mocha testframework (testresults does not get printed before all are done - so it fills the memory)
199+
200+
201+
## Ideas
202+
203+
Potential improvements and features for this repository:
204+
205+
- `--bail` option to stop on first error for faster turnaround during AI-driven try-and-retry sessions for fixing AlaSQL
206+
- Error categorization to automatically group and categorize errors by type (syntax, function, operator, etc.) for easier debugging
207+
- Comparison mode to compare test results between AlaSQL versions or against other SQL engines
208+
- Performance profiling to track and visualize performance metrics across test runs

bun-run/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Bun Test Runner
2+
3+
This folder contains Bun-optimized test runners for AlaSQL SQLlogictest.
4+
5+
## Performance Improvements
6+
7+
The Bun version leverages:
8+
- **Bun's native file I/O** - Faster file reading with `Bun.file()` API
9+
- **ES Modules** - Modern JavaScript module system
10+
- **Async/await** - Better async handling for test execution
11+
- **Native performance** - Bun's optimized JavaScript runtime
12+
13+
## Files
14+
15+
- `run.js` - Main test runner (async, single-threaded)
16+
- `sqllogictestparserV2.js` - Test file parser using Bun's file API
17+
18+
## Usage
19+
20+
From the project root:
21+
22+
```bash
23+
# Run all tests (outputs to results/output-bun.md)
24+
npm run test-bun
25+
26+
# Run demo test (outputs to console)
27+
npm run test-demo-bun
28+
```
29+
30+
Or directly:
31+
32+
```bash
33+
cd bun-run
34+
bun run run.js
35+
```
36+
37+
## Configuration
38+
39+
Edit the `CONFIG START` section in `run.js` to customize:
40+
41+
- `config.runOnlyDemo` - Set to `true` to run only demo.test
42+
- `config.printAllErrors` - Print all errors vs. unique errors only
43+
- Test file filters - Modify the regex patterns to select which test files to run
44+
- `mimic` array - Which database engines to mimic
45+
46+
## Why Bun?
47+
48+
Bun is significantly faster than Node.js for:
49+
- File I/O operations (reading test files)
50+
- Module resolution and loading
51+
- JavaScript execution
52+
- JSON parsing
53+
54+
Expected performance improvements: 2-3x faster test execution for large test suites.

0 commit comments

Comments
 (0)