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 (part 2) #113

Merged
merged 1 commit into from
Dec 8, 2021
Merged

Optimize short string parsing (part 2) #113

merged 1 commit into from
Dec 8, 2021

Conversation

chriso
Copy link
Contributor

@chriso chriso commented Dec 8, 2021

This PR extends #76 so that we check an extra 8 bytes. With #76 we only take the fast path for strings <= 7 bytes (where the quote is in the 8th byte). The fast path now covers strings of up to 15 bytes.

Parsing longer strings takes a bit of a hit, but I think overall it's a net win given the prevalence of short strings in object keys. I'm also finding that bytes.IndexByte is comparatively slower on arm64, so if we can avoid that with some extra bitwise operations then it's a win for our use cases.

amd64:

name                             old time/op   new time/op   delta
Unmarshal/*json.codeResponse2-4   4.91ms ± 1%   4.89ms ± 1%  -0.48%  (p=0.002 n=20+18)

name                             old speed     new speed     delta
Unmarshal/*json.codeResponse2-4  395MB/s ± 1%  397MB/s ± 1%  +0.48%  (p=0.002 n=20+18)

arm64:

name                              old time/op   new time/op   delta
Unmarshal/*json.codeResponse2-10   4.43ms ± 0%   4.29ms ± 0%  -3.16%  (p=0.000 n=19+19)

name                              old speed     new speed     delta
Unmarshal/*json.codeResponse2-10  438MB/s ± 0%  452MB/s ± 0%  +3.27%  (p=0.000 n=19+19)

@chriso chriso merged commit 853eaa1 into master Dec 8, 2021
@chriso chriso deleted the short-str-opt-2 branch December 8, 2021 05:20
# 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