-
Notifications
You must be signed in to change notification settings - Fork 10
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
Speed-up html-escaping using jetscii (waiting for portable-simd) #93
base: master
Are you sure you want to change the base?
Conversation
let mut last = 0; | ||
|
||
for (index, byte) in string.bytes().enumerate() { | ||
let escaped = match byte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a bit test in here makes the benchmarks run slower. It could be that the benchmarks outline an unrealistic scenario, though: They consist of comparatively long strings.
Bit testing is slower than a table lookup, if the table is already loaded into the CPU cache, but loading the table takes quite some time _once_, too. If the strings are mostly short, and mostly contain no characters that need escaping, then a bit test solution would win.
I guess the current solution is good enough for now. Just something we need to keep in mind, that we might need to revise the benchmark text corpus. Even the "short" string is 27 characters long.
I'll take a look once rebased. ;) |
7eb1fe3
to
85f68d0
Compare
Rebased. For now, that's the last one in my "let's make it speedy" series. :) |
85f68d0
to
fe8750f
Compare
```text $ cargo bench --bench escape Before the PR: [3.6464 µs 3.6512 µs 3.6564 µs] Impl. without `jetscii`: [3.4837 µs 3.4899 µs 3.4968 µs] Impl with `jetscii`: [2.0264 µs 2.0335 µs 2.0418 µs] ``` Until portable SIMD gets stabilized, I don't think we can do much for non-X86 platforms. And even after it is stabilized, I guess any optimizations should be implemented upstream in memchr and/or jetscii.
fe8750f
to
2cb24d5
Compare
I excluded x86 (32bit). That makes the code a bit more readable, and if you still use a 32bit x86 system in 2024, then yeah, chances are that you run your code on some aching VIA processor without SSE 4.2 support. |
Until portable SIMD gets stabilized, I don't think we can do much for non-X86 platforms. And even after it is stabilized, I guess any optimizations should be implemented upstream in memchr and/or jetscii.