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

Speed up integer parsing #112

Merged
merged 1 commit into from
Dec 8, 2021
Merged

Speed up integer parsing #112

merged 1 commit into from
Dec 8, 2021

Conversation

chriso
Copy link
Contributor

@chriso chriso commented Dec 8, 2021

There's no need to check for possible overflow before we handle each byte of input. We can just handle the next byte and then check whether overflow occurred. This shrinks the overflow checks in half.

amd64:

name                             old time/op   new time/op   delta
Unmarshal/*json.codeResponse2-4   4.94ms ± 2%   4.74ms ± 1%  -4.11%  (p=0.008 n=5+5)

name                             old speed     new speed     delta
Unmarshal/*json.codeResponse2-4  393MB/s ± 2%  409MB/s ± 1%  +4.27%  (p=0.008 n=5+5)

arm64:

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

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

There's no need to check for possible overflow before we handle each
byte of input. We can just handle the next byte and then check whether
overflow occurred.
Copy link
Contributor

@achille-roussel achille-roussel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@chriso chriso merged commit d2e2596 into master Dec 8, 2021
@chriso chriso deleted the improve-parse-uint branch December 8, 2021 05:11
# 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