Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointer semantics in depthCounter #352

Merged
merged 1 commit into from
Apr 8, 2023

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 merged commit 2ec415b into godbus:master Apr 8, 2023
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.

None yet

2 participants