commit | 2da8a55584aa65ce1b67431bb8ecebf66229d462 | [log] [tgz] |
---|---|---|
author | Joe Tsai <joetsai@digital-static.net> | Wed Feb 01 18:18:57 2023 -0800 |
committer | Joseph Tsai <joetsai@digital-static.net> | Sat Feb 04 19:29:52 2023 +0000 |
tree | d09f8d9001e6eeb976a5b48e2494393d6744df05 | |
parent | 25f5d9d4a253cb880bff909ebbdc05c8941c4a48 [diff] |
log: make use of fmt.Append functionality Since log is already responsible for managing its own buffers it is unfortunate that it calls fmt.Sprintf, which allocates, only to append that intermediate string to another buffer. Instead, use the new fmt.Append variants and avoid the allocation. We modify Logger.Output to wrap an internal Logger.output, which can be configured to use a particular append function. Logger.output is called from all the other functionality instead. This has the further advantage of simplifying the isDiscard check, which occurs to avoid the costly fmt.Print call. We coalesce all 6 checks as just 1 check in Logger.output. Also, swap the declaration order of Logger.Print and Logger.Printf to match the ordering elsewhere in the file. Performance: name old time/op new time/op delta Println 188ns ± 2% 172ns ± 4% -8.39% (p=0.000 n=10+10) PrintlnNoFlags 139ns ± 1% 116ns ± 1% -16.71% (p=0.000 n=9+9) name old allocs/op new allocs/op delta Println 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) PrintlnNoFlags 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) Change-Id: I79d0ee404df848beb3626fe863ccc73a3e2eb325 Reviewed-on: https://go-review.googlesource.com/c/go/+/464345 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org>
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 4.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Official binary distributions are available at https://go.dev/dl/.
After downloading a binary release, visit https://go.dev/doc/install for installation instructions.
If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.