Skip to content

perf(core): check bytes with SIMD where memchr does not fit - #863

Merged
Brooooooklyn merged 2 commits into
feat/watch-modefrom
perf/simd-byte-checks
Oct 20, 2026
Merged

Brooooooklyn merged 2 commits into
feat/watch-modefrom
perf/simd-byte-checks

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Follow-up to #860. An audit of every byte and string scan left in src/, keeping only the changes a benchmark shows are faster.

Changed

Where Before After Speed (aarch64, M-series)
TryAsStr::try_as_str: every CommonJS source the load hook checks, up to twice per file std::str::from_utf8 simdutf8 (compat where the error text is shown) 2.0x–3.3x on ASCII 2 KB–200 KB, 6.7x on a 300 KB non-ASCII file
encode_file_url_path: "does this path need %XX?", on every resolved file URL bytes().any(encoded) any_byte(file_url_encoded) 5x–5.8x on 34–117 byte paths
is_bare_specifier: "any byte ≤ space?" bytes().any(..) any_byte(..) 2.5x–12x on 18–96 byte specifiers

any_byte checks 16 bytes at a time with no early exit inside a chunk, so LLVM emits vector compares (NEON, SSE2). The encode set is rewritten as ranges and compares joined by |: the old matches! compiles to a bit test per byte, which does not vectorize (that form measured 0.8x, slower than any).

Looked at, left as is

Where Why
contains("/node_modules/") (5 places) memmem with a static Finder measured 0.5x–1.3x against str::contains on 34–117 byte paths: no win
windows_file_url.rs host and segment checks Windows-only, short UNC hosts and segments, rare
line and column counting for error frames only on a syntax error
the remaining replace / split with one char already guarded by a memchr check, or run once at startup

Tests

  • file_url_encoded_is_the_path_to_file_url_set: the compare form matches the old matches! set for all 256 bytes.
  • any_byte_is_iterator_any: same answer as Iterator::any for lengths 0–40, with the hit at every position.
  • cargo test --all-features (49), clippy with warnings denied, and vp run test (272 passed, 7 skipped) all pass.

The numbers come from a standalone micro-benchmark (release, LTO, codegen-units = 1) on Apple Silicon. They are not measured on x86_64.

🤖 Generated with Claude Code

- Validate loaded CommonJS sources with simdutf8 (2x-6.7x faster than
  std::str::from_utf8 on 2 KB-300 KB files).
- Find bytes to percent-encode in file URL paths, and spaces or controls
  in specifiers, 16 bytes at a time with vector compares (3x-12x faster
  on typical paths than Iterator::any).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T09:14:28.671273Z c731278 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Brooooooklyn
Brooooooklyn force-pushed the perf/simd-byte-checks branch from af76f2b to 952ebf4 Compare October 18, 2026 15:03
@Brooooooklyn
Brooooooklyn changed the base branch from main to feat/watch-mode October 18, 2026 15:03
@Brooooooklyn
Brooooooklyn added this pull request to stack #864 October 18, 2026 15:03
@Brooooooklyn
Brooooooklyn force-pushed the perf/simd-byte-checks branch 10 times, most recently from c5bd0b6 to 347aae6 Compare October 19, 2026 04:18
@Brooooooklyn
Brooooooklyn force-pushed the perf/simd-byte-checks branch 3 times, most recently from e1d318b to 74050d3 Compare October 19, 2026 06:58
@Brooooooklyn
Brooooooklyn removed this pull request from stack #864 October 19, 2026 07:02
@Brooooooklyn
Brooooooklyn force-pushed the perf/simd-byte-checks branch from 74050d3 to fda7487 Compare October 19, 2026 07:03
@Brooooooklyn
Brooooooklyn added this pull request to stack #867 October 19, 2026 07:05
@Brooooooklyn
Brooooooklyn force-pushed the perf/simd-byte-checks branch 7 times, most recently from ee6c3eb to 6b92f9b Compare October 19, 2026 08:07
@Brooooooklyn
Brooooooklyn force-pushed the perf/simd-byte-checks branch from 6b92f9b to de14e41 Compare October 19, 2026 08:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de14e4142a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lib.rs Resolved
simdutf8's basic validator checks the whole input before it reports an
error, so a large binary was scanned in full, twice. The compat
validator stops at the first bad block, as std did.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Brooooooklyn
Brooooooklyn force-pushed the perf/simd-byte-checks branch 3 times, most recently from df6b70b to 7635a37 Compare October 19, 2026 08:44
@Brooooooklyn
Brooooooklyn force-pushed the perf/simd-byte-checks branch from 7635a37 to c731278 Compare October 19, 2026 09:13
@Brooooooklyn
Brooooooklyn merged commit 6f1f943 into main Oct 20, 2026
67 checks passed
@Brooooooklyn
Brooooooklyn deleted the perf/simd-byte-checks branch October 20, 2026 04:47
Brooooooklyn added a commit that referenced this pull request Oct 20, 2026
Bottom of stack #867: #861 and #863 build on it, so their CI gets
working emnapi versions.

#865 on main moved `emnapi` and `@emnapi/runtime` to `2.0.0-beta.2` but
left `@emnapi/core` at `2.0.0-alpha.6`. `@napi-rs/cli` refuses the
mismatch, so `stable - wasm32-wasip1-threads - node@24` fails on main,
and the 5 test jobs after it are skipped:

```
Internal Error: emnapi version mismatch: emnapi@2.0.0-beta.2, @emnapi/core@2.0.0-alpha.6, @emnapi/runtime@2.0.0-beta.2.
```

Moving all three to beta.2 is not the fix: `@emnapi/core` beta.2 breaks
`@napi-rs/wasm-runtime` 1.2.5, the latest, and `Test WASI target` fails
to load the binding (`Cannot set properties of undefined (setting
'initWorker')`).

So this pins all three to exactly `2.0.0-alpha.6`, the versions main
used before #865 (where both wasm jobs passed). Move them together once
`@napi-rs/wasm-runtime` supports emnapi beta.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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