Skip to content

SIMD-accelerate JSON string scanning in JSONLexer#1984

Open
lavenzg wants to merge 1 commit intofacebook:static_hfrom
lavenzg:export-D93549305
Open

SIMD-accelerate JSON string scanning in JSONLexer#1984
lavenzg wants to merge 1 commit intofacebook:static_hfrom
lavenzg:export-D93549305

Conversation

@lavenzg
Copy link
Copy Markdown
Contributor

@lavenzg lavenzg commented Apr 14, 2026

Summary:
Add SIMD-optimized character scanning functions (scanSpecialCharU8, scanSpecialCharU16) that find the first byte/char16_t that is '"', '\', or <= 0x1F. Use these in JSONLexer::scanString() to skip over runs of normal characters in bulk during the escape-free hot loop.

The SIMD scan applies only to ASCII and UTF16 encodings (where UsesRawPtr is true and we have a contiguous buffer with known bounds). UTF8 uses UTF16Stream which is not a raw pointer and is unaffected.

Jenkins hash is handled separately: after SIMD skips a range of normal characters, the hash is computed over that range in a scalar loop, keeping the SIMD scan free of data dependencies.

Implementation tiers:

  • NEON (aarch64): 16 bytes / 8 char16_t per iteration
  • SSE2 (x86-64): 16 bytes / 8 char16_t per iteration
  • Scalar fallback for all other platforms

Differential Revision: D93549305

Summary:
Add SIMD-optimized character scanning functions (scanSpecialCharU8, scanSpecialCharU16) that find the first byte/char16_t that is '"', '\\', or <= 0x1F. Use these in JSONLexer::scanString() to skip over runs of normal characters in bulk during the escape-free hot loop.

The SIMD scan applies only to ASCII and UTF16 encodings (where UsesRawPtr is true and we have a contiguous buffer with known bounds). UTF8 uses UTF16Stream which is not a raw pointer and is unaffected.

Jenkins hash is handled separately: after SIMD skips a range of normal characters, the hash is computed over that range in a scalar loop, keeping the SIMD scan free of data dependencies.

Implementation tiers:
- NEON (aarch64): 16 bytes / 8 char16_t per iteration
- SSE2 (x86-64): 16 bytes / 8 char16_t per iteration
- Scalar fallback for all other platforms

Differential Revision: D93549305
@meta-cla meta-cla bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Apr 14, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Apr 14, 2026

@lavenzg has exported this pull request. If you are a Meta employee, you can view the originating Diff in D93549305.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant