Skip to content
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

(Context).get: speedup #154

Merged
merged 1 commit into from Sep 9, 2021
Merged

Conversation

kolyshkin
Copy link
Collaborator

fmt.Sprintf is slow. Let's use string concatenation instead, and avoid
looking up level label twice.

Benchmark shows 3x improvement in performance, and less allocations.

name          old time/op    new time/op    delta
ContextGet-4     277ns ± 1%      93ns ± 1%  -66.55%  (p=0.016 n=4+5)

name          old alloc/op   new alloc/op   delta
ContextGet-4      128B ± 0%       64B ± 0%     ~     (p=0.079 n=4+5)

name          old allocs/op  new allocs/op  delta
ContextGet-4      5.00 ± 0%      1.00 ± 0%     ~     (p=0.079 n=4+5)

Signed-off-by: Kir Kolyshkin kolyshkin@gmail.com

fmt.Sprintf is slow. Let's use string concatenation instead, and avoid
looking up level label twice.

Benchmark shows 3x improvement in performance, and less allocations.

name          old time/op    new time/op    delta
ContextGet-4     277ns ± 1%      93ns ± 1%  -66.55%  (p=0.016 n=4+5)

name          old alloc/op   new alloc/op   delta
ContextGet-4      128B ± 0%       64B ± 0%     ~     (p=0.079 n=4+5)

name          old allocs/op  new allocs/op  delta
ContextGet-4      5.00 ± 0%      1.00 ± 0%     ~     (p=0.079 n=4+5)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@rhatdan
Copy link
Collaborator

rhatdan commented Sep 9, 2021

LGTM
I am not sure this is called that often.

@kolyshkin
Copy link
Collaborator Author

I am not sure this is called that often.

It's not, but the fix is trivial, too.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah merged commit 4739804 into opencontainers:main Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants