Skip to content
Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
9c8ef48
json: rewrite the parser around a SIMD structural index
Jarred-Sumner Jun 28, 2026
917a702
json: fix unterminated containers, optimize the kernel TU in debug bu…
Jarred-Sumner Jun 28, 2026
565f2ed
json: write the structural index into spare capacity; registry manife…
Jarred-Sumner Jun 29, 2026
bf70e96
json: make the scalar indexer bit-identical to the SIMD kernel
Jarred-Sumner Jun 29, 2026
b48fb56
json: index large documents through a resumable kernel in 1MB chunks
Jarred-Sumner Jun 29, 2026
a09ed0b
json: keep the duplicate-key spill map per object
Jarred-Sumner Jun 29, 2026
ad8c72f
json: give each nesting level of large objects its own duplicate-key map
Jarred-Sumner Jun 29, 2026
35bc891
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 29, 2026
54f070e
ast: compact JSON-only object/array nodes (E::ObjectSimple, E::ArrayS…
Jarred-Sumner Jun 29, 2026
4fa6d66
json: store simple-container children as arena slices
Jarred-Sumner Jun 29, 2026
9a49340
json: simple-container children live on one per-document row tape
Jarred-Sumner Jun 29, 2026
6ae2748
json: cut simple-mode stage 2 per-element overhead
Jarred-Sumner Jun 29, 2026
d19559a
highway: chunked JSON index wrapper takes the initialized dirty bitmap
Jarred-Sumner Jun 29, 2026
920dbdb
json: appease clippy (is_multiple_of, raw-pointer borrow, Copy IndexE…
Jarred-Sumner Jun 29, 2026
a9b36cb
ast: teach the generic Expr accessors about the JSON simple containers
Jarred-Sumner Jun 29, 2026
0f23ecd
install: parse npm registry manifests with the simple JSON AST
Jarred-Sumner Jun 29, 2026
3c5f026
json: document why tsconfig/package.json stay on the full AST; add wa…
Jarred-Sumner Jun 29, 2026
6b35f73
json: materialize simple trees at the boundary; recover value locatio…
Jarred-Sumner Jun 29, 2026
e8fc438
json: the simple AST's row tape owns its memory; no arena
Jarred-Sumner Jun 29, 2026
3e10b3b
json: every UTF-8 entry point parses the simple AST; classic trees ar…
Jarred-Sumner Jun 29, 2026
a663ee0
json: delete the classic half of stage 2
Jarred-Sumner Jun 29, 2026
363ec60
json: decode escapes straight to WTF-8, and convert WTF-8 to JS strin…
Jarred-Sumner Jun 29, 2026
5393062
json: read-only consumers consume the row AST directly
Jarred-Sumner Jun 29, 2026
6212c7f
json: name the immutable AST's nodes EObjectJSON/EArrayJSON; let the …
Jarred-Sumner Jun 29, 2026
03b5d1b
json: fix the issues review surfaced; record value locations in the t…
Jarred-Sumner Jun 29, 2026
da7dfd7
json: move the generic JSON helpers out of the resolver
Jarred-Sumner Jun 29, 2026
2f43770
json: address the remaining review feedback
Jarred-Sumner Jun 30, 2026
8437bdd
json: fix the criterion bench, allowlist ceilings, and the remaining …
Jarred-Sumner Jun 30, 2026
ccb26b3
json: name the row-AST entry points after their dialect; skip duplica…
Jarred-Sumner Jun 30, 2026
d267c46
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 30, 2026
573c6a3
json: delete the dead and duplicated code the rewrite left behind
Jarred-Sumner Jun 30, 2026
95a11a4
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 30, 2026
2030d1a
json: fail the parse when stage 2 logged an error; add JSON conforman…
Jarred-Sumner Jun 30, 2026
904ca8b
json: review fixes for the conformance tests and create's parse-error…
Jarred-Sumner Jun 30, 2026
4f5781e
json: fix the doc references and dead code the bots flagged
Jarred-Sumner Jun 30, 2026
cb17d8c
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 30, 2026
9ee0074
json: generate the byte-classification table for both indexers; fix t…
Jarred-Sumner Jun 30, 2026
eb91348
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 30, 2026
ae84654
json: don't emit unused items into the scalar indexer; drop the write…
Jarred-Sumner Jun 30, 2026
58914fb
json: always rebuild the bench kernel TU (it includes a generated hea…
Jarred-Sumner Jun 30, 2026
68672a5
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 30, 2026
a5e492c
json: bound the gap scan by the previous token; match the true commen…
Jarred-Sumner Jun 30, 2026
3da2046
json: never classify non-ASCII bytes as structural; drop dead ArrayIt…
Jarred-Sumner Jun 30, 2026
3de9841
json: align the loc-recovery line-comment scan with the indexer; doc …
Jarred-Sumner Jun 30, 2026
4529f03
json: auto-quoted values keep raw control characters; simplify the ne…
Jarred-Sumner Jun 30, 2026
4fe1a4e
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 30, 2026
3171f3e
json: drop a test comment describing the deleted backward comment-ope…
Jarred-Sumner Jun 30, 2026
f70de24
json: step over comments that follow exotic whitespace with no gap
Jarred-Sumner Jun 30, 2026
7d7708f
json: two stale comments (simple AST naming; the bundler's materializ…
Jarred-Sumner Jun 30, 2026
15d27fa
json: delete the dead \u{...} validation; fix a stale doc reference
Jarred-Sumner Jun 30, 2026
2482d7c
json: drop a misleading qualifier from skip_unicode_ws's docs
Jarred-Sumner Jun 30, 2026
f38148d
json: a minus may be separated from its digits by exotic whitespace o…
Jarred-Sumner Jun 30, 2026
810e11b
json: fix a stale bench comment naming callers that moved to the row API
Jarred-Sumner Jun 30, 2026
edd029e
json: report 'Expected number' at the token after the minus; doc accu…
Jarred-Sumner Jun 30, 2026
561da47
json: a separated minus is one value to the source rescanners too
Jarred-Sumner Jun 30, 2026
9093ea8
json: treat comments as whitespace in every dialect inside stage 2; p…
Jarred-Sumner Jun 30, 2026
6507e1d
[autofix.ci] apply automated fixes
autofix-ci[bot] Jun 30, 2026
4369851
json: delete the dead UTF-16 hash branch; test the minus EOF arm; doc…
Jarred-Sumner Jun 30, 2026
245df94
json: reword a misleading test comment
Jarred-Sumner Jun 30, 2026
b704369
json: escaped keywords after exotic whitespace; test comment accuracy
Jarred-Sumner Jul 1, 2026
1e8ffca
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 1, 2026
a786ad6
json: fix a stale comment on the re-dispatched scalar arms
Jarred-Sumner Jul 1, 2026
2102cf5
json: guard the materializer's recursion like the printer's
Jarred-Sumner Jul 1, 2026
98c4b9b
json: log a diagnostic at every depth-limit site
Jarred-Sumner Jul 1, 2026
f658c86
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 1, 2026
37a199a
json: delete all but the essential comments
Jarred-Sumner Jul 1, 2026
bb8208f
json: length-prefix nested containers in the row hasher, like the top…
Jarred-Sumner Jul 1, 2026
0a6a8ef
Merge remote-tracking branch 'origin/main' into worktree-bridge-cse_0…
Jarred-Sumner Jul 1, 2026
9d41a17
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 1, 2026
a6c7e3e
json: delete remaining non-essential comments
Jarred-Sumner Jul 1, 2026
e072778
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 1, 2026
818f120
json: route a whitespace-separated minus to the number parser in env …
Jarred-Sumner Jul 1, 2026
72c9ae5
json: report the earlier of a stage-2 error and an index error
Jarred-Sumner Jul 1, 2026
4db2504
json: keep pre-comment warnings; skip block comments when guessing in…
Jarred-Sumner Jul 1, 2026
c3c5087
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 1, 2026
fe58dea
json: anchor the unterminated-comment error's precedence at the /*
Jarred-Sumner Jul 1, 2026
096c1ff
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 1, 2026
1d4ce4c
json: a rejected comment before an index error wins; warnings survive…
Jarred-Sumner Jul 1, 2026
32440a9
json: drop the unused warnings snapshot; skip line comments in the in…
Jarred-Sumner Jul 1, 2026
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
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bench/json-corpus/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.json
36 changes: 36 additions & 0 deletions bench/json-corpus/fetch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Fetch the JSON benchmark fixture corpus: real package.json files plus npm registry responses
# (abbreviated install-v1 manifests and full packuments). Gitignored; only compared within a checkout.
set -euo pipefail
cd "$(dirname "$0")"

ACCEPT_ABBREV='Accept: application/vnd.npm.install-v1+json'

pkg() { curl -fsSL "https://unpkg.com/$1@$2/package.json" -o "pkgjson-$1.json"; echo "pkgjson-$1.json"; }
pkg express 4.19.2
pkg react 18.3.1
pkg typescript 5.5.4
pkg webpack 5.93.0
pkg eslint 9.8.0
pkg axios 1.7.3
pkg next 14.2.5
pkg vite 5.3.5

abbrev() { curl -fsSL -H "$ACCEPT_ABBREV" "https://registry.npmjs.org/$1" -o "manifest-abbrev-$2.json"; echo "manifest-abbrev-$2.json"; }
abbrev is-number is-number
abbrev express express
abbrev react react
abbrev lodash lodash
abbrev typescript typescript
abbrev next next
abbrev @types/node types-node
abbrev @babel/core babel-core

full() { curl -fsSL "https://registry.npmjs.org/$1" -o "packument-full-$2.json"; echo "packument-full-$2.json"; }
full express express
full axios axios

abbrev drizzle-orm drizzle-orm
abbrev drizzle-kit drizzle-kit

ls -la
47 changes: 47 additions & 0 deletions bench/json-corpus/jsonc-parse.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// End-to-end benchmark of `Bun.JSONC.parse` over the corpus in this directory, with `JSON.parse`
// as a reference. Usage: `bun bench/json-corpus/jsonc-parse.mjs [name-filter]`.
import { readdirSync, readFileSync } from "node:fs";
import { join, dirname } from "node:path";

const dir = dirname(Bun.fileURLToPath(import.meta.url));
const filter = process.argv[2] ?? "";
const files = readdirSync(dir)
.filter(f => f.endsWith(".json") && f.includes(filter))
.sort();

const runs = +(process.env.RUNS ?? 30);
function bench(label, fn) {
fn();
fn();
const times = [];
for (let i = 0; i < runs; i++) {
const t0 = Bun.nanoseconds();
fn();
times.push(Bun.nanoseconds() - t0);
}
times.sort((a, b) => a - b);
return { label, best: times[0], median: times[(times.length / 2) | 0] };
}

console.log("bun", Bun.version, Bun.revision.slice(0, 9));
console.log(
"file".padEnd(40),
"bytes".padStart(10),
"JSONC med".padStart(12),
"JSON.parse".padStart(12),
"JSONC MiB/s".padStart(11),
);
for (const f of files) {
const text = readFileSync(join(dir, f), "utf8");
const bytes = Buffer.byteLength(text);
const jsonc = bench("jsonc", () => Bun.JSONC.parse(text));
const jsonp = bench("json", () => JSON.parse(text));
const mbs = bytes / (jsonc.median / 1e9) / (1 << 20);
console.log(
f.padEnd(40),
String(bytes).padStart(10),
(jsonc.median / 1e6).toFixed(3).padStart(9) + " ms",
(jsonp.median / 1e6).toFixed(3).padStart(9) + " ms",
mbs.toFixed(0).padStart(11),
);
}
61 changes: 61 additions & 0 deletions scripts/bench-json-rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Build + run the JSON parser criterion bench (src/parsers/benches/json_parse.rs): compiles the
# native pieces the parser reaches into one archive and points RUSTFLAGS at it. Needs `bun bd` once.
set -euo pipefail
cd "$(dirname "$0")/.."

if [ ! -d vendor/mimalloc ] || [ ! -d vendor/highway ]; then
echo "error: vendor/ not populated — run \`bun bd\` (or \`bun run build\`) once first" >&2
exit 1
fi

SUP=target/bench-json-cdeps
mkdir -p "$SUP/wtf"
export BUN_CODEGEN_DIR=${BUN_CODEGEN_DIR:-$PWD/build/debug/codegen}
if [ ! -f "$BUN_CODEGEN_DIR/json_byte_class.h" ]; then
echo "error: $BUN_CODEGEN_DIR/json_byte_class.h not found — run \`bun bd\` once first" >&2
exit 1
fi
CC=${CC:-cc}
CXX=${CXX:-c++}
SIMDUTF_VERSION=v7.3.6
SIMDUTF_STAMP="$SUP/.simdutf-$SIMDUTF_VERSION"
if [ ! -f "$SIMDUTF_STAMP" ] || [ ! -f "$SUP/simdutf.cpp" ]; then
curl -fsSL -o "$SUP/simdutf.cpp" "https://github.com/simdutf/simdutf/releases/download/$SIMDUTF_VERSION/simdutf.cpp"
curl -fsSL -o "$SUP/simdutf.h" "https://github.com/simdutf/simdutf/releases/download/$SIMDUTF_VERSION/simdutf.h"
rm -f "$SUP"/simdutf*.o "$SUP"/.simdutf-*
touch "$SIMDUTF_STAMP"
fi
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
printf '#pragma once\n#include "simdutf.h"\n' > "$SUP/wtf/SIMDUTF.h"

build() {
local out=$1
shift
if [ ! -f "$out" ] || [ "${*: -1}" -nt "$out" ]; then "$@" -o "$out"; fi
}
MI_FLAGS=(-O2 -fPIC -ftls-model=initial-exec -DNDEBUG -D_GNU_SOURCE -DMI_STATIC_LIB
-DMI_SKIP_COLLECT_ON_EXIT=1 -DMI_DEFAULT_ALLOW_THP=0 -DMI_NO_SET_VMA_NAME=1)
build "$SUP/mimalloc.o" $CC "${MI_FLAGS[@]}" -Ivendor/mimalloc/include -c vendor/mimalloc/src/static.c
build "$SUP/simdutf.o" $CXX -O3 -fPIC -std=c++20 -I"$SUP" -c "$SUP/simdutf.cpp"
build "$SUP/simdutf_shim.o" $CXX -O3 -fPIC -std=c++20 -I"$SUP" -c src/parsers/benches/support/simdutf_shim.cpp
for f in abort targets per_target print timer nanobenchmark aligned_allocator; do
build "$SUP/hwy_$f.o" $CXX -O3 -fPIC -std=c++17 -Ivendor/highway -c "vendor/highway/hwy/$f.cc"
done
if [ -f src/jsc/bindings/highway_json.cpp ]; then
$CXX -O3 -fPIC -std=c++17 -Ivendor/highway -Isrc/jsc/bindings -I"$BUN_CODEGEN_DIR" -c src/jsc/bindings/highway_json.cpp -o "$SUP/highway_json.o"
fi
Comment thread
claude[bot] marked this conversation as resolved.
Resolved
rm -f "$SUP/libbun_bench_cdeps.a"
ar rcs "$SUP/libbun_bench_cdeps.a" "$SUP"/*.o
ranlib "$SUP/libbun_bench_cdeps.a"

export MIMALLOC_PURGE_DELAY=${MIMALLOC_PURGE_DELAY:-2000}
export BUN_JSON_BENCH_FIXTURES=${BUN_JSON_BENCH_FIXTURES:-$PWD/bench/json-corpus}
CXXLIB=stdc++
[ "$(uname -s)" = Darwin ] && CXXLIB=c++
export RUSTFLAGS="${RUSTFLAGS:-} -Clink-arg=$PWD/$SUP/libbun_bench_cdeps.a -Clink-arg=-l$CXXLIB -Clink-arg=-lm -Clink-arg=-ldl -Clink-arg=-lpthread -Clink-arg=-lc"

if [ "${1:-}" = "--test" ]; then
shift
exec cargo test -p bun_parsers --lib --release "$@"
fi
exec cargo bench -p bun_parsers --bench json_parse "$@"
73 changes: 37 additions & 36 deletions scripts/build/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,42 +173,43 @@ Split CI modes: `rust-only` (lolhtml+codegen+cargo → libbun_rust.a), `cpp-only

## Module inventory

| File | Owns |
| ------------------------------ | ----------------------------------------------------------------------------------------------------- |
| `build.ts` (parent dir) | CLI entry — parse args, call configure, spawn ninja, optionally exec |
| `configure.ts` | `configure()` — toolchain → config → `build.ninja` |
| `config.ts` | `Config`/`PartialConfig`/`Toolchain`/`Host` types, `resolveConfig()` |
| `profiles.ts` | Named `PartialConfig` presets + `getProfile()` |
| `tools.ts` | Tool discovery: `findTool()`, `resolveLlvmToolchain()`, version parsing |
| `flags.ts` | Flat flag tables, `computeFlags()`, `computeDepFlags()`, `computeCpuTargetFlags()` |
| `ninja.ts` | `Ninja` class — the build-file writer |
| `rules.ts` | `registerAllRules()` — calls each module's `registerXxxRules()` |
| `compile.ts` | `cc`/`cxx`/`pch`/`link`/`ar` + `registerCompileRules()` |
| `unified.ts` | WebKit-style unified-source bundling, `generateUnifiedSources()` |
| `source.ts` | `Dependency` types, `resolveDep()`, fetch/configure/build emission |
| `codegen.ts` | Code generation steps, `emitCodegen()`, `CodegenOutputs` |
| `rust.ts` | `cargo build` step, `emitRust()`, `rustLibPath()`, cross-compile matrix |
| `cargo-config.ts` | Generates the git-ignored `.cargo/config.toml` (per-target `linker` from `cfg.hostCxx`) |
| `bun.ts` | `emitBun()` — assembles deps+codegen+rust+compile+link |
| `shims.ts` | Platform/toolchain workaround dylibs, `emitShims()` |
| `workarounds.ts` | Self-obsoleting workaround registry, `checkWorkarounds()` |
| `macos-sdk.ts` | macOS SDK resolution/download for darwin cross-compiles — `resolveMacosSdkPath()`, `ensureMacosSdk()` |
| `features-json.ts` | Host-side `features.json` for cross lanes — `parsePackedFeaturesList()`, `crossFeaturesJson()` |
| `depVersionsHeader.ts` | Generates `bun_dependency_versions.h` for `process.versions` |
| `buildOptionsRs.ts` | Generates `build_options.rs` (`bun_core::build_options`) from `Config` |
| `stream.ts` | Subprocess output wrapper — FD-3 sideband, prefixed line streaming |
| `shell.ts` | `quote()`/`slash()` — shell escaping for ninja commands |
| `fs.ts` | `writeIfChanged()`, `mkdirAll()` |
| `error.ts` | `BuildError` with hint/file/cause, `assert()` |
| `download.ts` | `downloadWithRetry()`, archive extraction |
| `winsysroot.ts` | Windows MSVC CRT + SDK sysroot (xwin): validates, adds case aliases, CI fetch |
| `fetch-cli.ts` | Build-time CLI ninja invokes for downloads |
| `ci.ts` | CI integration — annotations, artifacts, log groups |
| `clean.ts` | `bun run clean` preset-based cleanup |
| `glob-sources.ts` (parent dir) | Source glob patterns + CLI to print them |
| `deps/*.ts` | One `Dependency` object per vendored dep |
| `deps/index.ts` | `allDeps` array — fetch order + link order |
| `shims/*.c` | Platform workaround sources |
| File | Owns |
| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
| `build.ts` (parent dir) | CLI entry — parse args, call configure, spawn ninja, optionally exec |
| `configure.ts` | `configure()` — toolchain → config → `build.ninja` |
| `config.ts` | `Config`/`PartialConfig`/`Toolchain`/`Host` types, `resolveConfig()` |
| `profiles.ts` | Named `PartialConfig` presets + `getProfile()` |
| `tools.ts` | Tool discovery: `findTool()`, `resolveLlvmToolchain()`, version parsing |
| `flags.ts` | Flat flag tables, `computeFlags()`, `computeDepFlags()`, `computeCpuTargetFlags()` |
| `ninja.ts` | `Ninja` class — the build-file writer |
| `rules.ts` | `registerAllRules()` — calls each module's `registerXxxRules()` |
| `compile.ts` | `cc`/`cxx`/`pch`/`link`/`ar` + `registerCompileRules()` |
| `unified.ts` | WebKit-style unified-source bundling, `generateUnifiedSources()` |
| `source.ts` | `Dependency` types, `resolveDep()`, fetch/configure/build emission |
| `codegen.ts` | Code generation steps, `emitCodegen()`, `CodegenOutputs` |
| `rust.ts` | `cargo build` step, `emitRust()`, `rustLibPath()`, cross-compile matrix |
| `cargo-config.ts` | Generates the git-ignored `.cargo/config.toml` (per-target `linker` from `cfg.hostCxx`) |
| `bun.ts` | `emitBun()` — assembles deps+codegen+rust+compile+link |
| `shims.ts` | Platform/toolchain workaround dylibs, `emitShims()` |
| `workarounds.ts` | Self-obsoleting workaround registry, `checkWorkarounds()` |
| `macos-sdk.ts` | macOS SDK resolution/download for darwin cross-compiles — `resolveMacosSdkPath()`, `ensureMacosSdk()` |
| `features-json.ts` | Host-side `features.json` for cross lanes — `parsePackedFeaturesList()`, `crossFeaturesJson()` |
| `depVersionsHeader.ts` | Generates `bun_dependency_versions.h` for `process.versions` |
| `buildOptionsRs.ts` | Generates `build_options.rs` (`bun_core::build_options`) from `Config` |
| `jsonByteClass.ts` | Generates `json_byte_class.{h,rs}` — the JSON byte classification shared by the SIMD kernel and the Rust scalar indexer |
| `stream.ts` | Subprocess output wrapper — FD-3 sideband, prefixed line streaming |
| `shell.ts` | `quote()`/`slash()` — shell escaping for ninja commands |
| `fs.ts` | `writeIfChanged()`, `mkdirAll()` |
| `error.ts` | `BuildError` with hint/file/cause, `assert()` |
| `download.ts` | `downloadWithRetry()`, archive extraction |
| `winsysroot.ts` | Windows MSVC CRT + SDK sysroot (xwin): validates, adds case aliases, CI fetch |
| `fetch-cli.ts` | Build-time CLI ninja invokes for downloads |
| `ci.ts` | CI integration — annotations, artifacts, log groups |
| `clean.ts` | `bun run clean` preset-based cleanup |
| `glob-sources.ts` (parent dir) | Source glob patterns + CLI to print them |
| `deps/*.ts` | One `Dependency` object per vendored dep |
| `deps/index.ts` | `allDeps` array — fetch order + link order |
| `shims/*.c` | Platform workaround sources |

## Key types

Expand Down
8 changes: 8 additions & 0 deletions scripts/build/bun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ export function emitBun(n: Ninja, cfg: Config, sources: Sources): BunOutput {
// force-include would lock those in before the source can speak.
const noPchSources = new Set<string>();

// highway_json.cpp is compiled -O2 even in debug profiles (see its
// fileOverrides entry in flags.ts); a TU at a different -O level than the
// PCH cannot use the PCH ("__OPTIMIZE__ ... was disabled in precompiled
// file"). It only includes highway + libc headers anyway.
if (cfg.debug) {
noPchSources.add(resolve(cfg.cwd, "src/jsc/bindings/highway_json.cpp"));
}

// Windows-only cpp sources (rescle — PE resource editor for --compile).
if (cfg.windows) {
// rescle.h does `#define UNICODE` before including ATL; with PCH the
Expand Down
8 changes: 8 additions & 0 deletions scripts/build/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { generateBuildOptionsRs } from "./buildOptionsRs.ts";
import type { Config } from "./config.ts";
import { BuildError, assert } from "./error.ts";
import { writeIfChanged } from "./fs.ts";
import { generateJsonByteClass } from "./jsonByteClass.ts";
import type { Ninja } from "./ninja.ts";
import { quote, quoteArgs } from "./shell.ts";

Expand Down Expand Up @@ -272,6 +273,13 @@ export function emitCodegen(n: Ninja, cfg: Config, sources: Sources): CodegenOut
o.all.push(buildOptionsRs);
o.rustInputs.push(buildOptionsRs);

// Same shape: the JSON byte-classification tables, consumed by both the
// Highway kernel (.h) and the Rust scalar indexer (.rs).
const jsonByteClass = generateJsonByteClass(cfg);
o.all.push(jsonByteClass.h, jsonByteClass.rs);
o.rustInputs.push(jsonByteClass.rs);
o.cppHeaders.push(jsonByteClass.h);

emitBunError(ctx);
emitStringMaps(ctx);
emitFallbackDecoder(ctx);
Expand Down
11 changes: 11 additions & 0 deletions scripts/build/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,17 @@ export const fileOverrides: FileOverride[] = [
when: c => c.windows,
desc: "Vendored electron/rcedit; VersionInfo ctor throws std::system_error caught in OnEnumResourceLanguage. Self-contained throw/catch — already excluded from PCH",
},
{
file: "src/jsc/bindings/highway_json.cpp",
extraFlags: ["-O2"],
when: c => c.debug,
desc:
"Always optimize the JSON structural-index kernel (debug builds use -O0 globally). At -O0 every " +
"highway op is an outlined call taking 64-byte vectors by value through the stack, and clang's " +
"unoptimized codegen for that pattern raises #GP on an aligned zmm stack store under the debug " +
"sanitizer set; it would also make every JSON parse in debug builds pathologically slow. " +
"Covered by test/js/bun/jsonc/jsonc.test.ts and `scripts/bench-json-rust.sh --test`.",
},
];

// ═══════════════════════════════════════════════════════════════════════════
Expand Down
Loading
Loading