Skip to content

Conversation

@arturmelanchyk
Copy link
Contributor

@arturmelanchyk arturmelanchyk commented Nov 8, 2025

It looks like Rust app allocates device on stack whereas Go app allocates on heap, lets fix this

./main.go:51:2: moved to heap: device

This trivial change gives us ~4% cpu time boost and ~7% less memory allocations

╰─⠠⠵ benchstat old.txt new.txt                                                             
goos: darwin
goarch: arm64
pkg: go-app
cpu: Apple M3 Max
                      │   old.txt   │              new.txt               │
                      │   sec/op    │   sec/op     vs base               │
GetDevicesParallel-16   2.061µ ± 3%   1.976µ ± 2%  -4.12% (p=0.000 n=15)

                      │   old.txt    │               new.txt               │
                      │     B/op     │     B/op      vs base               │
GetDevicesParallel-16   6.369Ki ± 0%   6.312Ki ± 0%  -0.90% (p=0.000 n=15)

                      │  old.txt   │              new.txt              │
                      │ allocs/op  │ allocs/op   vs base               │
GetDevicesParallel-16   26.00 ± 0%   24.00 ± 0%  -7.69% (p=0.000 n=15)

tested on

go version go1.25.4 darwin/arm64

Signed-off-by: Artur Melanchyk <13834276+arturmelanchyk@users.noreply.github.com>
Copy link
Owner

@antonputra antonputra left a comment

Choose a reason for hiding this comment

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

Thanks!

@antonputra antonputra merged commit 46872c5 into antonputra:main Nov 9, 2025
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