Skip to content

perf(decode): SIMD-accelerated backslash search in decode_string fast path #20

@membphis

Description

@membphis

Background

decode_string currently scans for backslash escape sequences byte-by-byte in its inner loop. The structural scanner already uses SIMD to skip over long string interiors at the Phase 1 level, but Phase 2 decode_string pays the linear byte scan cost every time an escaped string is accessed.

Proposal

Add a SIMD probe inside decode_string (src/decode/string.rs) that searches for \ using AVX2 / NEON intrinsics (or falls back to memchr on scalar builds), jumping past unescaped runs in bulk rather than one byte at a time.

This mirrors the in-string fast path already present in the structural scanners (src/scan/avx2.rs, src/scan/neon.rs).

Expected impact

Meaningful win on payloads with many long escaped strings (e.g. embedded JSON, long base64 with \/ escapes). No effect on strings without backslashes (those already take the borrow-slice fast path and never enter the escape loop).

Notes

  • Gate behind the same feature flags (avx2, neon) used by the structural scanners, or use memchr as a portable alternative that the compiler may auto-vectorize.
  • Add a bench fixture or micro-benchmark with a string-escape-heavy payload to measure before/after.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions