Skip to content

SIMD Optimizations and can_error checks#2270

Merged
stephenberry merged 14 commits intomainfrom
skip_ws_benchmark
Jan 27, 2026
Merged

SIMD Optimizations and can_error checks#2270
stephenberry merged 14 commits intomainfrom
skip_ws_benchmark

Conversation

@stephenberry
Copy link
Owner

@stephenberry stephenberry commented Jan 26, 2026

SIMD String Escape Refactoring

  • Extracted SIMD detection macros into simd/simd.hpp, with per-ISA headers: avx.hpp, sse.hpp, neon.hpp.
  • Added SSE2 (16-byte) and NEON (16-byte + 64-byte wide) string escape paths alongside the existing AVX2 (32-byte) path.
  • Rewrote AVX2 escape detection to use direct cmpeq/movemask instead of the previous SWAR-in-YMM approach.
  • Deduplicated the escape-handling logic into a single write_escape lambda shared across all SIMD and SWAR paths.

Write Optimization (can_error)

  • Added static constexpr bool can_error to to<JSON, T> specializations for types that cannot fail during writing (bool, numbers, strings, enums, bitset, flags, null, nullable).
  • Object serialization now skips ctx.error checks and ensure_space calls when all fields are known to be error-free at compile time.
  • Extended array_padding_known to also cover arrays of objects with computable fixed_padding.

New Utility Header

  • Created util/bit.hpp consolidating countr_zero, countl_zero, and int_log2 (previously scattered across parse.hpp and dtoa.hpp).
  • SIMD headers now include bit.hpp directly rather than relying on transitive includes through write.hpp.
  • Fixed __has_builtin checks to match the actual builtin being called.

Documentation

  • Updated README, installation.md, and optimizing-performance.md to document SSE2, NEON, and the GLZ_DISABLE_SIMD option.

@stephenberry stephenberry changed the title skip_ws benchmark SIMD Optimizations Jan 27, 2026
@stephenberry stephenberry changed the title SIMD Optimizations SIMD Optimizations and can_error checks Jan 27, 2026
@packit-as-a-service
Copy link

One of the tests failed for 478165c. @admin check logs None, packit dashboard https://dashboard.packit.dev/jobs/copr/3194546 and external service dashboard https://copr.fedorainfracloud.org/coprs/build/10068861/

@packit-as-a-service
Copy link

One of the tests failed for 4f31e24. @admin check logs None, packit dashboard https://dashboard.packit.dev/jobs/copr/3194728 and external service dashboard https://copr.fedorainfracloud.org/coprs/build/10069004/

@wilkolbrzym-coder
Copy link

I’ve finished the portable SWAR implementation for skip_ws including comprehensive benchmarks (which show great results).
I see you’re moving bit utilities to util/bit.hpp. My implementation currently uses a custom countr_zero in parse.hpp, so it will be very easy to swap it for your new centralized version once your PR lands.
Everything is tested and ready on my side. Let me know if you want me to rebase on top of your changes once you're done, or if you'd like to take a look at the SWAR logic now.

@stephenberry
Copy link
Owner Author

@wilkolbrzym-coder, I'm going to benchmark your pull request as soon as I'm able. And, I'll make sure I get things merged together. I'm still making adjustments and doing more benchmarking for these changes.

@packit-as-a-service
Copy link

One of the tests failed for 532c83b. @admin check logs None, packit dashboard https://dashboard.packit.dev/jobs/copr/3195125 and external service dashboard https://copr.fedorainfracloud.org/coprs/build/10069231/

@packit-as-a-service
Copy link

One of the tests failed for 532c83b. @admin check logs None, packit dashboard https://dashboard.packit.dev/jobs/copr/3195124 and external service dashboard https://copr.fedorainfracloud.org/coprs/build/10069231/

@wilkolbrzym-coder
Copy link

Impressive work on the SIMD refactoring, @stephenberry! The new structure is really clean. I was curious—is AVX-512 support on your roadmap, or are you sticking with AVX2 for now to avoid the complexity/throttling trade-offs? 64-byte processing would be a beastly addition!

@stephenberry stephenberry merged commit 85629bc into main Jan 27, 2026
42 of 44 checks passed
@stephenberry stephenberry deleted the skip_ws_benchmark branch January 27, 2026 22:03
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.

2 participants