Commit 0a24555
http/httpguts: speed up ValidHeaderFieldName
Eliminate bounds checks and eschews UTF-8 decoding in ValidHeaderFieldName,
thereby doubling its speed without introducing any allocations.
Also eliminate bounds checks in IsTokenRune.
Add tests and benchmarks for both ValidHeaderFieldName and IsTokenRune.
goos: darwin
goarch: amd64
pkg: golang.org/x/net/http/httpguts
cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
│ before │ after │
│ sec/op │ sec/op vs base │
IsTokenRune-8 315.2n ± 0% 316.2n ± 1% ~ (p=0.245 n=20)
ValidHeaderFieldName-8 62.77n ± 0% 29.16n ± 0% -53.55% (p=0.000 n=20)
geomean 140.7n 96.02n -31.73%
│ before │ after │
│ B/op │ B/op vs base │
IsTokenRune-8 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20)
ValidHeaderFieldName-8 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20)
geomean ² +0.00%
│ before │ after │
│ allocs/op │ allocs/op vs base │
IsTokenRune-8 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20)
ValidHeaderFieldName-8 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=20)
geomean ² +0.00%
Fixes golang/go#66700
Change-Id: Ia3ea80e5f0d173e3a69eb7429023587fd7bc5933
GitHub-Last-Rev: 1f1d25d
GitHub-Pull-Request: #207
Reviewed-on: https://go-review.googlesource.com/c/net/+/578075
Run-TryBot: Emmanuel Odeke <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>1 parent ec05fdc commit 0a24555
2 files changed
+52
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 96 | + | |
102 | 97 | | |
103 | 98 | | |
104 | 99 | | |
| |||
202 | 197 | | |
203 | 198 | | |
204 | 199 | | |
205 | | - | |
206 | | - | |
| 200 | + | |
| 201 | + | |
207 | 202 | | |
208 | 203 | | |
209 | 204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
33 | 42 | | |
34 | 43 | | |
35 | 44 | | |
| |||
100 | 109 | | |
101 | 110 | | |
102 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
103 | 150 | | |
104 | 151 | | |
105 | 152 | | |
| |||
0 commit comments