Skip to content

Commit df64e52

Browse files
committed
feat: enable simd128
1 parent c1c8c57 commit df64e52

6 files changed

Lines changed: 14 additions & 8 deletions

File tree

.oxfmtrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3-
"ignorePatterns": []
3+
"ignorePatterns": [
4+
"lib/_rg.wasm.mjs"
5+
]
46
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Absolute filesystem path to a JS shim that runs ripgrep via `ripgrep`. Drop-in r
4343

4444
## How it works
4545

46-
- ripgrep is cross-compiled to `wasm32-wasip1` via [`cargo zigbuild`](https://github.com/rust-cross/cargo-zigbuild), using Zig as the C compiler/linker.
46+
- ripgrep is cross-compiled to `wasm32-wasip1` with SIMD (`simd128`) enabled via [`cargo zigbuild`](https://github.com/rust-cross/cargo-zigbuild), using Zig as the C compiler/linker. This unlocks `memchr`'s vectorized search routines for faster byte scanning.
4747
- The resulting `.wasm` is brotli-compressed and z85-encoded into `lib/_rg.wasm.mjs`, so it ships as a plain ESM module — no `.wasm` asset resolution or postinstall needed.
4848
- On first use, the z85 blob is decoded and decompressed, then cached to the OS temp directory (`$TMPDIR/ripgrep-wasm-<hash>.wasm`). Subsequent calls (even across processes) skip decoding entirely. The z85 string itself is wrapped in a function so V8 lazy-parses it only when needed.
4949
- The compiled `WebAssembly.Module` is memoized in-process — repeated `ripgrep()` calls only pay the compilation cost once. Fresh instances are still created per-call since WASI state (memory, file descriptors) is per-instance.

build.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ fn addRipgrepBuild(b: *std.Build, rust_triple: []const u8) RipgrepBuild {
7575
const target_dir = b.pathJoin(&.{ cache_root, "cargo-target", rust_triple });
7676
cargo.setEnvironmentVariable("CARGO_TARGET_DIR", target_dir);
7777

78+
// Enable WASM SIMD for wasm targets — unlocks memchr's simd128 vectorized paths.
79+
if (std.mem.startsWith(u8, rust_triple, "wasm")) {
80+
cargo.setEnvironmentVariable("RUSTFLAGS", "-C target-feature=+simd128");
81+
}
82+
7883
const exe_name = b.fmt("rg{s}", .{binExt(rust_triple)});
7984
const rg_path_str = b.pathJoin(&.{ target_dir, rust_triple, profile, exe_name });
8085
return .{

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.{
22
.name = .ripgrep,
33
.version = "0.0.0",
4-
.fingerprint = 0x36520762f52ee133,
4+
.fingerprint = 0x89b93d7bd4e75448,
55
.minimum_zig_version = "0.15.2",
66
.paths = .{ "build.zig", "build.zig.zon" },
77
}

lib/_rg.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
44
import { join } from "node:path";
55

66
// Auto generated by build.ts
7-
const WASM_HASH = "4a7dc2d696452852";
7+
const WASM_HASH = "226bbe1107b2cfe2";
88

99
const cacheFile = join(tmpdir(), `ripgrep-wasm-${WASM_HASH}.wasm`);
1010

lib/_rg.wasm.mjs

Lines changed: 3 additions & 4 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)