perf(lexer): use portable-SIMD to speed up whitespace scanning#26
perf(lexer): use portable-SIMD to speed up whitespace scanning#26
Conversation
Parser Benchmark Results |
178c0ed to
d8df5bb
Compare
| fn check_chunk(&mut self, chunk: &[u8]) { | ||
| let s = SimdVec::from_slice(chunk); | ||
|
|
||
| let any_newline = s.simd_eq(self.lf) | s.simd_eq(self.cr); |
There was a problem hiding this comment.
This doesn't seem to handle non-ASCII newlines (U+2028 and U+2029). Is that handled elsewhere?
There was a problem hiding this comment.
These two are so rare so I left them in the scalar version
Otherwise it'll drag down this simd version.
| } | ||
|
|
||
| if !remainder.is_empty() { | ||
| // Align the last chunk for avoiding the use of a scalar version |
There was a problem hiding this comment.
If you ensure that the input data is padded (e.g. suffixed with 64 0x00 bytes), then you don't need this special case.
There was a problem hiding this comment.
remainder isn't aligned, it's a slice of the bytes input.
There was a problem hiding this comment.
If the input is 20 bytes, then the first 16 bytes are handled in the for chunk in chunks loop, and the remaining 4 bytes are handled by this code (which adds 12 zero bytes at the end). I assume this is what you mean when you say "remainder isn't aligned".
You can guarantee that remainder is always empty or unimportant (thus you don't need to check for it) if you add enough zeros at the end of bytes. I do this in quick-lint-js when I load the file from the filesystem, so everything can safely assume that the extra bytes are present. (I have a dedicated type for this called padded_string_view which doesn't allow breaking this invariant.)
There was a problem hiding this comment.
This is clever! I'll try it out.
No description provided.