Andy Pan has uploaded this change for review.
net/http: reduce calls to append() in hexEscapeNonASCII() to gain a slight performance boost
name old time/op new time/op delta
HexEscapeNonASCII-10 223ns ± 0% 211ns ± 0% -5.34% (p=0.000 n=10+9)
name old alloc/op new alloc/op delta
HexEscapeNonASCII-10 192B ± 0% 192B ± 0% ~ (all equal)
name old allocs/op new allocs/op delta
HexEscapeNonASCII-10 2.00 ± 0% 2.00 ± 0% ~ (all equal)
Change-Id: Ic8d2b3ddcf2cf724dec3f51a2aba205f2c6e4fe6
---
M src/net/http/http.go
M src/net/http/http_test.go
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/src/net/http/http.go b/src/net/http/http.go
index 101799f..b52d500 100644
--- a/src/net/http/http.go
+++ b/src/net/http/http.go
@@ -7,13 +7,12 @@
package http
import (
+ "golang.org/x/net/http/httpguts"
"io"
"strconv"
"strings"
"time"
"unicode/utf8"
-
- "golang.org/x/net/http/httpguts"
)
// incomparable is a zero-width, non-comparable type. Adding it to a struct
@@ -86,14 +85,20 @@
return s
}
b := make([]byte, 0, newLen)
+ var pos int
for i := 0; i < len(s); i++ {
if s[i] >= utf8.RuneSelf {
+ if pos < i {
+ b = append(b, s[pos:i]...)
+ }
b = append(b, '%')
b = strconv.AppendInt(b, int64(s[i]), 16)
- } else {
- b = append(b, s[i])
+ pos = i + 1
}
}
+ if pos < len(s) {
+ b = append(b, s[pos:]...)
+ }
return string(b)
}
diff --git a/src/net/http/http_test.go b/src/net/http/http_test.go
index 0d92fe5..1c9fb33 100644
--- a/src/net/http/http_test.go
+++ b/src/net/http/http_test.go
@@ -218,3 +218,13 @@
t.Fatal(err)
}
}
+
+const redirectURL = "/thisaredirect细雪withasciilettersのけぶabcdefghijk.html"
+
+func BenchmarkHexEscapeNonASCII(b *testing.B) {
+ b.ReportAllocs()
+
+ for i := 0; i < b.N; i++ {
+ hexEscapeNonASCII(redirectURL)
+ }
+}
To view, visit change 425786. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor.
Patch set 1:Run-TryBot +1
Attention is currently required from: Andy Pan, Ian Lance Taylor.
Andy Pan uploaded patch set #2 to this change.
The following approvals got outdated and were removed: Run-TryBot+1 by Andy Pan, TryBot-Result+1 by Gopher Robot
net/http: reduce calls to append() in hexEscapeNonASCII() to gain a slight performance boost
goos: linux
goarch: amd64
pkg: net/http
cpu: DO-Premium-Intel
│ old │ new │
│ sec/op │ sec/op vs base │
HexEscapeNonASCII-4 469.6n ± 20% 371.1n ± 9% -20.98% (p=0.000 n=10)
│ old │ new │
│ B/op │ B/op vs base │
HexEscapeNonASCII-4 192.0 ± 0% 192.0 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
│ old │ new │
│ allocs/op │ allocs/op vs base │
HexEscapeNonASCII-4 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
Change-Id: Ic8d2b3ddcf2cf724dec3f51a2aba205f2c6e4fe6
---
M src/net/http/http.go
M src/net/http/http_test.go
2 files changed, 46 insertions(+), 4 deletions(-)
To view, visit change 425786. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor.
Patch set 2:Run-TryBot +1
Attention is currently required from: Ian Lance Taylor.
Andy Pan uploaded patch set #3 to this change.
net/http: reduce calls to append() in hexEscapeNonASCII() to gain a slight performance boost
goos: linux
goarch: amd64
pkg: net/http
cpu: DO-Premium-Intel
│ old │ new │
│ sec/op │ sec/op vs base │
HexEscapeNonASCII-4 469.6n ± 20% 371.1n ± 9% -20.98% (p=0.000 n=10)
│ old │ new │
│ B/op │ B/op vs base │
HexEscapeNonASCII-4 192.0 ± 0% 192.0 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
│ old │ new │
│ allocs/op │ allocs/op vs base │
HexEscapeNonASCII-4 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
[fdfd](https://github.com/golang/go/commit/5a6e511c614a158cb58150fb62bfbc207a33922d#diff-e754f9fc8eaf878714250cfc03844eb3b58185ac806a8c1c4f9fbabd86cda921L3972)
Change-Id: Ic8d2b3ddcf2cf724dec3f51a2aba205f2c6e4fe6
---
M src/net/http/http.go
M src/net/http/http_test.go
2 files changed, 48 insertions(+), 4 deletions(-)
To view, visit change 425786. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor.
Andy Pan uploaded patch set #4 to this change.
net/http: reduce calls to append() in hexEscapeNonASCII() to gain a slight performance boost
goos: linux
goarch: amd64
pkg: net/http
cpu: DO-Premium-Intel
│ old │ new │
│ sec/op │ sec/op vs base │
HexEscapeNonASCII-4 469.6n ± 20% 371.1n ± 9% -20.98% (p=0.000 n=10)
│ old │ new │
│ B/op │ B/op vs base │
HexEscapeNonASCII-4 192.0 ± 0% 192.0 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
│ old │ new │
│ allocs/op │ allocs/op vs base │
HexEscapeNonASCII-4 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
Change-Id: Ic8d2b3ddcf2cf724dec3f51a2aba205f2c6e4fe6
---
M src/net/http/http.go
M src/net/http/http_test.go
2 files changed, 46 insertions(+), 4 deletions(-)
To view, visit change 425786. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Andy Pan.
3 comments:
Commit Message:
Patch Set #4, Line 7: net/http: reduce calls to append() in hexEscapeNonASCII() to gain a slight performance boost
Minor but we don't use parentheses after functions, since pkg.go.dev doesn't recognize them.
Patchset:
Does this really matter much? It seems to only be called by Redirect.
File src/net/http/http.go:
Patch Set #4, Line 10: "golang.org/x/net/http/httpguts"
Keep this import in a separate group, as before.
To view, visit change 425786. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Andy Pan.
Andy Pan uploaded patch set #5 to this change.
The following approvals got outdated and were removed: Run-TryBot+1 by Andy Pan, TryBot-Result+1 by Gopher Robot
net/http: reduce calls to append in hexEscapeNonASCII to gain a slight performance boost
goos: linux
goarch: amd64
pkg: net/http
cpu: DO-Premium-Intel
│ old │ new │
│ sec/op │ sec/op vs base │
HexEscapeNonASCII-4 469.6n ± 20% 371.1n ± 9% -20.98% (p=0.000 n=10)
│ old │ new │
│ B/op │ B/op vs base │
HexEscapeNonASCII-4 192.0 ± 0% 192.0 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
│ old │ new │
│ allocs/op │ allocs/op vs base │
HexEscapeNonASCII-4 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
Change-Id: Ic8d2b3ddcf2cf724dec3f51a2aba205f2c6e4fe6
---
M src/net/http/http.go
M src/net/http/http_test.go
2 files changed, 45 insertions(+), 2 deletions(-)
To view, visit change 425786. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor.
Patch set 5:Run-TryBot +1
2 comments:
Commit Message:
Patch Set #4, Line 7: net/http: reduce calls to append() in hexEscapeNonASCII() to gain a slight performance boost
Minor but we don't use parentheses after functions, since pkg.go.dev doesn't recognize them.
Done
File src/net/http/http.go:
Patch Set #4, Line 10: "golang.org/x/net/http/httpguts"
Keep this import in a separate group, as before.
Done
To view, visit change 425786. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Andy Pan.
Patch set 5:Code-Review +2
1 comment:
Patchset:
Thanks.
To view, visit change 425786. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Andy Pan, Damien Neil.
Patch set 5:Code-Review +1
Attention is currently required from: Andy Pan, Damien Neil.
Patch set 5:Code-Review +1
To view, visit change 425786. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Andy Pan, Damien Neil.
Patch set 5:Auto-Submit +1
Gopher Robot submitted this change.
net/http: reduce calls to append in hexEscapeNonASCII to gain a slight performance boost
goos: linux
goarch: amd64
pkg: net/http
cpu: DO-Premium-Intel
│ old │ new │
│ sec/op │ sec/op vs base │
HexEscapeNonASCII-4 469.6n ± 20% 371.1n ± 9% -20.98% (p=0.000 n=10)
│ old │ new │
│ B/op │ B/op vs base │
HexEscapeNonASCII-4 192.0 ± 0% 192.0 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
│ old │ new │
│ allocs/op │ allocs/op vs base │
HexEscapeNonASCII-4 2.000 ± 0% 2.000 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
Change-Id: Ic8d2b3ddcf2cf724dec3f51a2aba205f2c6e4fe6
Reviewed-on: https://go-review.googlesource.com/c/go/+/425786
Reviewed-by: Than McIntosh <th...@google.com>
Auto-Submit: Ian Lance Taylor <ia...@golang.org>
Run-TryBot: Andy Pan <panj...@gmail.com>
TryBot-Result: Gopher Robot <go...@golang.org>
Reviewed-by: Ian Lance Taylor <ia...@golang.org>
Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
---
M src/net/http/http.go
M src/net/http/http_test.go
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/net/http/http.go b/src/net/http/http.go
index 101799f..9b81654 100644
--- a/src/net/http/http.go
+++ b/src/net/http/http.go
@@ -86,14 +86,20 @@
To view, visit change 425786. To unsubscribe, or for help writing mail filters, visit settings.