Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimize allocations parsing Content-Type (#444)
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 <akshay@akshayshah.org>
- Loading branch information