Skip to content

perf(json): write IP and MAC fields without an intermediate string - #841

Open
javabetatester wants to merge 1 commit into
rs:masterfrom
javabetatester:perf/json-net-text
Open

javabetatester wants to merge 1 commit into
rs:masterfrom
javabetatester:perf/json-net-text

Conversation

@javabetatester

Copy link
Copy Markdown

AppendIPAddr, AppendIPPrefix and AppendMACAddr formatted with String and then copied the result into the event buffer. The text is appended directly instead. Output matches net.IP.String, net.IPNet.String and net.HardwareAddr.String, including <nil>, non-canonical masks and odd lengths. Covered by TestAppendNetTextMatchesString.

BenchmarkLogFieldType, medians of 8 runs on an AMD Ryzen 7 5700X:

benchmark before after
IPAddr 52.49 ns, 16 B, 1 alloc 39.72 ns (−24%), 0 B, 0 allocs
IPAddrs (10) 383.1 ns, 240 B, 10 allocs 195.2 ns (−49%), 0 B, 0 allocs
IPPrefix 76.46 ns, 32 B, 2 allocs 39.05 ns (−49%), 0 B, 0 allocs
IPPrefixes (10) 602.2 ns, 480 B, 20 allocs 288.1 ns (−52%), 0 B, 0 allocs
MACAddr 47.16 ns, 0 B, 0 allocs 27.54 ns (−42%), 0 B, 0 allocs

CPU and allocations both fall. go test -race ./... and go test -tags binary_log -race . pass.

net.IP, net.IPNet and net.HardwareAddr were formatted with String
before the bytes were copied into the event buffer. Append the same
text directly so those fields allocate nothing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant