-
-
Notifications
You must be signed in to change notification settings - Fork 484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(parser): faster line comment #2327
Conversation
Utilizes memchr to find the end of the line comment which _might_ yield performance improvements. Also, adds a new `Source::eat_until_byte3` that allows us to naturally integrate memchr-based searches into the lexer. Thankfully, memchr does not have any dependencies so this change does not add that much bloat to the binary.
CodSpeed Performance ReportMerging #2327 will improve performances by 6.03%Falling back to comparing Summary
Benchmarks breakdown
|
This was more of an experiment to see how well |
Thanks very much for coming back. Yes, the performance gain is a little underwhelming. I would have hoped for more, especially given that on CI, the SIMD lane size is probably 32 (I assume Github's runners support AVX2, but I don't think memchr supports AVX-512 to do 64-byte batches). Nonetheless, it would be worth doing, as it does provide some speedup in heavily-commented code. And many incremental gains add up. But... I'm afraid I think you're missing one edge case. It also needs to handle That means there are 5 x possible bytes to search for, which rules out memchr, as it only supports up to 3. In my opinion (and please note I am no expert on this stuff, so could be wrong), we need to use a different approach from memchr's, and use "pshufd"-based table lookups to support searching for any number of possible bytes. If you're interested, I linked to an article about this on #2296. So ultimately, I'm afraid I don't think this specific PR is viable. But that doesn't mean it was wasted time. It is always valuable to test and rule out different possibilities. The result is surprising (at least to me), so thank you for exploring this avenue. If you're willing and keen to push further down this path towards SIMD, but don't want to dig into writing SIMD assembler code line by line (what sane person does?), there is one massive thing you could help with: I find it hard to believe there is not already a crate available which does "phufd"-based byte searching, as it seems like a common need. But I can't find one! if you were able to track one down, that would basically solve how to do SIMD in OXC entirely. |
I don't believe that the oxc/crates/oxc_syntax/src/identifier.rs Lines 42 to 64 in 0f28dc8
oxc/crates/oxc_parser/src/lexer/comment.rs Lines 11 to 18 in 0f28dc8
I am looking into how we could try to implement this.
Yep, I agree.
I am not sure if it will be this simple. In many cases, we need to defer to a scalar version whenever we see non-ASCII characters which would not be possible in byte-based searches. |
I'm currently working on a a re-write of lexing identifiers. It doesn't use SIMD, but is designed to be easily convertable to SIMD later: https://github.com/overlookmotel/oxc/blob/lexer-string5/crates/oxc_parser/src/lexer/identifier.rs You're right about having to bust out to scalar if unicode chars are found, but approach I've taken is to speed through ASCII as fast as possible and then Unicode is a de-opt (and on a But, yeah, I think this is one approach to the problem you've identified. |
Utilizes memchr to find the end of the line comment which might yield performance improvements. Also, adds a new
Source::eat_until_byte3
along withSource::set_eof
that allows us to naturally integrate memchr-based searchesinto the lexer.
Thankfully, memchr does not have any dependencies so this change does not add that much bloat to the binary.