You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For context, this function is run on every request within ServeHTTP, and
the mime parsing and now lowercasing, is a marginal, but non trivial
amount of memory allocations.
The expensive bit is hitting the mime.FormatMediaType path, when we
already have a canonical form.
This removes the most expensive part over arguable the most common cases
where there are no additional parameters on the Content-Type.
```
$ go test -bench '^BenchmarkCanonicalizeContentType$' -run '^$' .
goos: darwin
goarch: arm64
pkg: github.com/bufbuild/connect-go
BenchmarkCanonicalizeContentType/simple-10 92344741 12.85 ns/op 0 B/op 0 allocs/op
BenchmarkCanonicalizeContentType/with_charset-10 1744219 693.8 ns/op 424 B/op 6 allocs/op
BenchmarkCanonicalizeContentType/with_other_param-10 1969113 614.4 ns/op 424 B/op 6 allocs/op
PASS
ok github.com/bufbuild/connect-go 5.800s
```
---------
Co-authored-by: Akshay Shah <[email protected]>
0 commit comments