Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 -v -bench '^BenchmarkCanonicalizeContentType$' -run '^$' . goos: darwin goarch: arm64 pkg: github.com/bufbuild/connect-go BenchmarkCanonicalizeContentType BenchmarkCanonicalizeContentType/simple BenchmarkCanonicalizeContentType/simple-10 7160896 157.4 ns/op 48 B/op 1 allocs/op BenchmarkCanonicalizeContentType/with_charset BenchmarkCanonicalizeContentType/with_charset-10 1780041 674.4 ns/op 424 B/op 6 allocs/op BenchmarkCanonicalizeContentType/with_other_param BenchmarkCanonicalizeContentType/with_other_param-10 2029819 592.6 ns/op 424 B/op 6 allocs/op PASS ok github.com/bufbuild/connect-go 5.129s ```
- Loading branch information