Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Optimize short string parsing #76

Merged
merged 2 commits into from
Mar 22, 2021
Merged

Optimize short string parsing #76

merged 2 commits into from
Mar 22, 2021

Conversation

chriso
Copy link
Contributor

@chriso chriso commented Mar 22, 2021

We use the same SWAR technique used elsewhere in the repo to check 8 bytes for the end quote in a string, before falling back to bytes.IndexByte:

name           old time/op    new time/op    delta
CodeDecoder-4    5.30ms ± 3%    5.08ms ± 2%  -4.19%  (p=0.000 n=9+10)

name           old speed      new speed      delta
CodeDecoder-4   366MB/s ± 2%   382MB/s ± 2%  +4.36%  (p=0.000 n=9+10)

IndexByte is pretty quick, but it still has to load the input byte into an XMM register and shuffle it around before starting the routine, and then it also has various length and CPU checks to see whether to engage AVX2 or SSE. You also have the function call overhead to consider.

I think it's worth always checking the first chunk of bytes and paying the minor penalty each time you parse a string — it's common to see short strings in object keys, for example.

@chriso chriso requested a review from achille-roussel March 22, 2021 04:49
@chriso chriso merged commit 1e9a692 into master Mar 22, 2021
@chriso chriso deleted the short-string-parsing branch March 22, 2021 04:58
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants