fmt: fmt.Fprintf("%+q", large byte string) allocates quite a lot #31472
Labels
FrozenDueToAge
help wanted
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
I maintain a program called go-bindata which allows users to embed static assets (images, CSS, Javascript) in a Go program. The performance is not great, as this benchmark indicates: https://github.com/kevinburke/go-bindata/blob/master/benchmark_test.go#L24-L50
When we embed a large image into the binary, we call this to ensure it can be embedded in Go source code - I'm eliding some of the details but this is the meat of it.
Fprintf in turn ends up calling
fmtQ
, which callsstrconv.AppendQuoteToASCII
. The latter has a high number of very smallappend
calls which per pprof get called quite a bit. I think the "grow by 25%" threshold gets triggered quite a lot when you start with an empty buffer and have a large format string. Some samples:It would be great if we could improve the performance of this. Maybe we could do one pass to compute the size and then allocate a single buffer instead of allocating throughout the program execution.
The text was updated successfully, but these errors were encountered: