-
Notifications
You must be signed in to change notification settings - Fork 18.4k
net/url: reduce allocs in Encode #75874
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
base: master
Are you sure you want to change the base?
Conversation
This PR (HEAD: 38a1551) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/711280. Important tips:
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/711280. |
Message from jub0bs: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/711280. |
Message from Jes Cok: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/711280. |
Message from jub0bs: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/711280. |
Message from Sean Liao: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/711280. |
38a1551
to
569f3ff
Compare
This PR (HEAD: 569f3ff) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/711280. Important tips:
|
Message from jub0bs: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/711280. |
Message from jub0bs: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/711280. |
Message from Sean Liao: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/711280. |
This change adds benchmarks for Encode and reverts what CL 617356 did in
this package. In this case, pre-sizing the slice in which we collect the
keys and then sorting it is indeed more performant than relying on a
combination of maps.Keys and slices.Sorted.
Here are some benchmark results:
goos: darwin
goarch: amd64
pkg: net/url
cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
│ old │ new │
│ sec/op │ sec/op vs base │
EncodeQuery-8 1.697µ ± 1% 1.049µ ± 1% -38.17% (p=0.000 n=20)
EncodeQuery-8 576.0 ± 0% 256.0 ± 0% -55.56% (p=0.000 n=20)
EncodeQuery-8 25.00 ± 0% 11.00 ± 0% -56.00% (p=0.000 n=20)