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

perf: avoid unnecessary byteslice->string before fmt %s verb #10364

Merged
merged 1 commit into from
Oct 14, 2021
Merged

perf: avoid unnecessary byteslice->string before fmt %s verb #10364

merged 1 commit into from
Oct 14, 2021

Conversation

odeke-em
Copy link
Collaborator

fmt.Printf or fmt.Sprintf already know how to convert a
byteslice into a string when building the output; we shouldn't
incur the unnecessary string(byteslice) conversion.
Using Bencher, we can see improvements such as
https://dashboard.github.orijtech.com/benchmark/3245b8e4bbbd44a597480319aaa4b9fe
which in independent experiments show:

  • time/op (ns/op)
    FormatIt-8 1.2µs ± 2% 1.1µs ± 10% -11.77% (p=0.000 n=10+9)

  • speed (MB/s)
    FormatIt-8 0.71GB/s ± 2% 0.80GB/s ± 9% +13.59% (p=0.000 n=10+9)

  • allocs/op (B/op)
    FormatIt-8 2.0kB ± 0% 1.1kB ± 0% -45.62% (p=0.000 n=10+10)

  • allocs/op (count/op)
    FormatIt-8 11 ± 0% 9.0 ± 0% -18.18% (p=0.000 n=10+10)

Fixes #10363

@odeke-em odeke-em requested a review from aaronc as a code owner October 14, 2021 04:35
@odeke-em odeke-em changed the title all: avoid unnecessary byteslice->string before fmt %s verb fix! all: avoid unnecessary byteslice->string before fmt %s verb Oct 14, 2021
@codecov
Copy link

codecov bot commented Oct 14, 2021

Codecov Report

Merging #10364 (239e6c6) into master (f00e7a4) will decrease coverage by 0.03%.
The diff coverage is 60.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10364      +/-   ##
==========================================
- Coverage   64.27%   64.24%   -0.04%     
==========================================
  Files         572      572              
  Lines       54158    54158              
==========================================
- Hits        34811    34793      -18     
- Misses      17366    17385      +19     
+ Partials     1981     1980       -1     
Impacted Files Coverage Δ
x/params/types/subspace.go 81.81% <33.33%> (ø)
x/capability/simulation/decoder.go 100.00% <100.00%> (ø)
x/genutil/client/cli/init.go 67.27% <100.00%> (ø)
x/distribution/simulation/operations.go 80.54% <0.00%> (-9.73%) ⬇️

fmt.Printf or fmt.Sprintf already know how to convert a
byteslice into a string when building the output; we shouldn't
incur the unnecessary string(byteslice) conversion.
Using Bencher, we can see improvements such as
https://dashboard.github.orijtech.com/benchmark/3245b8e4bbbd44a597480319aaa4b9fe
which in independent experiments show:

* time/op (ns/op)
FormatIt-8	1.2µs ± 2%	1.1µs ± 10%	-11.77%	(p=0.000 n=10+9)

* speed (MB/s)
FormatIt-8	0.71GB/s ± 2%	0.80GB/s ± 9%	+13.59%	(p=0.000 n=10+9)

* allocs/op (B/op)
FormatIt-8	2.0kB ± 0%	1.1kB ± 0%	-45.62%	(p=0.000 n=10+10)

* allocs/op (count/op)
FormatIt-8	11 ± 0%	        9.0 ± 0%	-18.18%	(p=0.000 n=10+10)

Fixes #10363
@odeke-em odeke-em changed the title fix! all: avoid unnecessary byteslice->string before fmt %s verb perf: avoid unnecessary byteslice->string before fmt %s verb Oct 14, 2021
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

LGTM thank you

@tac0turtle tac0turtle added the A:automerge Automatically merge PR once all prerequisites pass. label Oct 14, 2021
@tac0turtle tac0turtle requested a review from amaury1093 October 14, 2021 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:CLI C:Keys Keybase, KMS and HSMs C:Simulations C:x/capability C:x/genutil genutil module issues C:x/params C:x/upgrade
Projects
None yet
Development

Successfully merging this pull request may close these issues.

all: avoid string(byteslice) conversion before passing arguments to fmt.*rintf with "%s" verb
3 participants