Skip to content

jit: accelerate Bun JSON and gzip with NEON integer lowering - #10

Merged
losfair merged 1 commit into
mainfrom
fix/bun-json-gzip-neon
Oct 28, 2026
Merged

losfair merged 1 commit into
mainfrom
fix/bun-json-gzip-neon

Conversation

@losfair

@losfair losfair commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Bun 1.4.4's JSON parser and zlib compression loop were repeatedly entering the kernel instruction interpreter. Lower their hot NEON operations in T1: CMTST, UMINV, SSHLL/USHLL (including UXTL), byte/halfword UQSUB, and 32/64-bit USHL.

UQSUB preserves sticky FPSR.QC and uses recovery metadata to commit the vector result and FPSR together when interrupted, including aliased operands. USHL implements ARM's signed low-byte shift counts. Add differential coverage, a saturation recovery regression, and a reproducible Bun benchmark.

Measured inside QEMU/KVM on an x86_64 i7-13700H host (nested virtualization), 2 vCPUs, 4 GiB, -cpu host, pinned to host CPUs 2 and 4. Both architectures use Bun 1.4.4 revision 38afee6c84fcf48c0edb2466aa4b27d287a59c30 and glibc 2.41. Baseline is 7e8de37.

Workload Native x64, baseline → patched kernel kemu before kemu after Speedup
JSON round trips 38.62 → 38.00 ms 545.16 ms 122.44 ms 4.45×
gzip 61.31 → 60.16 ms 643.10 ms 122.69 ms 5.24×

Medians of 14 samples per workload/architecture/kernel: two processes, each with three untimed warmups and seven measured samples. Boot order was baseline/patched/patched/baseline; architecture order was reversed in the second pair. Profiling was disabled for timings. JSON performs 20 parse/stringify round trips over 10,000 objects; gzip performs eight level-6 compressions of a deterministic 1 MiB buffer, then decompresses and verifies SHA-256. Startup is excluded. All checksums match. Patched kemu is 3.22× native for JSON and 2.04× for gzip.

Separate diagnostic helper profiles (one warmup plus three batches, including process setup) confirm the identified hot instruction sites disappear:

Workload Helper calls before Helper calls after Reduction
JSON 8,444,374 1,527 99.982%
gzip 12,529,756 286,604 97.713%

The profiling instrumentation is confined to the local diagnostic kernel and is not part of this change. Remaining gzip helpers are mostly FP conversions outside the zlib saturation loop.

Validation:

  • Rust 1.88.0 core tests: 37 passed.
  • INTR=10 RELOC=1 jit-test 30000 14 12, with and without NO_VCACHE=1: 60,000 cases, zero failures, exact FPCR/FPSR/NZCV, only the terminating BRK uses a helper; 2,887 asynchronous interruptions recovered.
  • QEMU interpreter oracle: all 57 added instruction encodings × 100 randomized states match.
  • Linux 6.18 kernel build and KVM scripts/vm-smoke.sh: all passed, including vector state, syscall state, FP status, ABI, TBI and multithread stress.
  • Four benchmark VM boots: successful exits, matching checksums, no kernel warnings or faults.

Reproduction: tests/bench/bun.mjs and the commands in README.

@losfair
losfair merged commit e738d0e into main Oct 28, 2026
2 checks passed
@losfair
losfair deleted the fix/bun-json-gzip-neon branch October 28, 2026 08:14
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