NHacker Next on Rails
  • top
  • new
  • best
  • ask
  • show
  • jobs
login
GuidelinesFAQListsAPISecurityLegalApply to YCContact

Hacker News on Rails, powered by React on Rails Pro. Open the source on GitHub by ShakaCode.

Commit 06fc0df

Rendered at 09:05:21 GMT+0000 (Coordinated Universal Time) with Rails + React on Rails RSC.

ASCII Validation from 2.5 to 114 GB/s with SIMD (modulovalue.com)

9 points by modulovalue 6h ago | 4 comments

Panzerschrek 3h ago
> Instead of testing every byte, OR every byte into an accumulator and check the high bit once at the end.

It's not an optimization, in many cases it's a pessimization if a large string has non-ASCII characters right at the start (or close to it). Iterating only a small fraction of the given string with branching is faster than iterating it all without branching.

modulovalue 3h ago
That's a fair point and I agree. I've added your point to the addendum. The solution that I see is iterating in blocks and have an early exit per block.
perching_aix 2h ago
> These ten steps are as far as I could take this loop in Dart today. There is still some performance left. The good news is that I already know what it takes to get there, and I'm working on the compiler and library changes it needs. I hope they land soon, and that a future version of this post can end at full speed.

That sounds interesting. I quickly looked up the peak read of the L1D cache to be 192 GB/s, is that what's meant here? Or some other, more fundamental microarchitectural limit?

Is it possible to saturate that throughput and still have optimality to gain in some other aspect?

modulovalue 1h ago
My goal is to safely reach native speeds on 128-bit wide SIMD registers and for that we need: - better bounds check elimination so we don't need the unsafe bounds pragma - dedicated loads so we can extract a SIMD value type directly from bytes with no overhead (Dart doesn't support slices like Rust, for example, and it's not that easy to retrofit them from what I've seen.) - a dedicated Uint8x16 type so the SWAR techniques over 32-bit wide integers are no longer needed - plus a few other minor optimizations

With that we should be pretty much be as fast as Rust, see: https://www.reddit.com/r/rust/comments/1yamcov/looking_for_f...

I don't think I'll be able to reach 192 GB/s if that's the limit of the M3 Air, but even if, unfortunately, validation is slowed down by any subsequent conversion to a String.

I should write about this because all languages suffer from this. I imagine that one day we will have languages that provide more extensive static ownership guarantees where we can have zero cost wrappers over regions of memory that we can easily treat as Strings instead of having to allocate memory and copy the bytes over to a materialized String.