[go] log/slog: avoid fmt.Sprintf call to concat strings

58 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Mar 25, 2024, 2:23:29 PM3/25/24
to Kevin Burke, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Emmanuel Odeke, Cherry Mui, Jonathan Amsterdam, David Chase, Ian Lance Taylor, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
log/slog: use plain string concatenation for Attr.String

Plain string concatenation with the plus operator for Attr.String is
much faster than invoking fmt.Sprintf. Added a benchmark to verify
this (just running on my Mac with stuff in the background but should
be sufficient to demonstrate the effect).

name old time/op new time/op delta
AttrString-8 1.24µs ± 3% 0.43µs ± 0% -65.17% (p=0.000 n=20+17)

name old alloc/op new alloc/op delta
AttrString-8 432B ± 0% 152B ± 0% ~ (p=1.000 n=1+1)

name old allocs/op new allocs/op delta
AttrString-8 30.0 ± 0% 16.0 ± 0% ~ (p=1.000 n=1+1)
Change-Id: I18ac91cbff1047d168b51a595601e36b5f676615
Reviewed-by: David Chase <drc...@google.com>
Reviewed-by: Jonathan Amsterdam <j...@google.com>
Run-TryBot: Emmanuel Odeke <emma...@orijtech.com>
Auto-Submit: Emmanuel Odeke <emma...@orijtech.com>
Reviewed-by: Cherry Mui <cher...@google.com>
Reviewed-by: Emmanuel Odeke <emma...@orijtech.com>
TryBot-Result: Gopher Robot <go...@golang.org>
Files:
  • M src/log/slog/attr.go
  • M src/log/slog/attr_test.go
Change size: S
Delta: 2 files changed, 32 insertions(+), 2 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Emmanuel Odeke, +1 by Jonathan Amsterdam, +1 by David Chase, +1 by Cherry Mui
  • requirement satisfiedLegacy-TryBots-Pass: TryBot-Result+1 by Gopher Robot, Run-TryBot+1 by Emmanuel Odeke
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I18ac91cbff1047d168b51a595601e36b5f676615
Gerrit-Change-Number: 573517
Gerrit-PatchSet: 4
Gerrit-Owner: Kevin Burke <ke...@burke.dev>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: David Chase <drc...@google.com>
Gerrit-Reviewer: Emmanuel Odeke <emma...@orijtech.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages