Skip to content

Pointer semantics in depthCounter#352

Merged
guelfey merged 1 commit intogodbus:masterfrom
marselester:depthCounter-allocs
Apr 8, 2023
Merged

Pointer semantics in depthCounter#352
guelfey merged 1 commit intogodbus:masterfrom
marselester:depthCounter-allocs

Conversation

@marselester
Copy link
Contributor

@marselester marselester commented Feb 8, 2023

Hi! I noticed that there is an inconsistent usage of pointer and value semantics in the depthCounter struct. In case both options achieve the same goal, it would be beneficial to stick to one (e.g., to the pointer semantics) to reduce allocs, i.e., 42 less allocs per operation, and almost 1KB of memory saved per operation.

$ go test -run='^$' -benchmem -bench '^BenchmarkUnixFDs$'
...
# new
BenchmarkUnixFDs-2   	    6584	    221914 ns/op	   15276 B/op	     563 allocs/op
# old
BenchmarkUnixFDs-2   	    4662	    307360 ns/op	   16290 B/op	     605 allocs/op

$ benchstat bench-old.txt bench-pointer.txt
name       old time/op    new time/op    delta
UnixFDs-2     263µs ±29%     273µs ±26%    ~     (p=0.720 n=9+10)

name       old alloc/op   new alloc/op   delta
UnixFDs-2    16.3kB ± 0%    15.3kB ± 0%  -6.19%  (p=0.000 n=8+6)

name       old allocs/op  new allocs/op  delta
UnixFDs-2       605 ± 0%       563 ± 0%  -6.94%  (p=0.000 n=10+10)

@marselester marselester changed the title Use pointer semantics in depthCounter Pointer semantics in depthCounter Feb 9, 2023
Copy link
Member

@guelfey guelfey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@guelfey guelfey force-pushed the depthCounter-allocs branch from 5c9258b to 5942541 Compare April 8, 2023 12:53
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.

2 participants