What are the reason for the performance improvement cause by alloc data of different sizes to adjacent memory addresses?

115 views
Skip to first unread message

qiulaidongfeng

unread,
Feb 9, 2024, 3:31:54 AM2/9/24
to golang-nuts
I recently added a new API (AllocSoonUse) to the https://gitee.com/qiulaidongfeng/arena I wrote (copy in https://github.com/qiulaidongfeng/arena)
This API allocdata to adjacent []byte, and the length can be set.
I use this benchmark code : https://go.dev/play/p/nAGveraT5_h

benchmark Brief description, use AllocSoonUse and new to allocate some data of different sizes that does not contain Pointers and use it soon after allocation.

I use `go test -bench=. -count=10 -benchtime=2s > new.txt && benchstat new.txt`  got this result
         │   new.txt   │
         │   sec/op    │
NoStd-16   207.4µ ± 4%
Std-16     245.0µ ± 1%
geomean    225.4µ

It appears that using AllocSoonUse takes 15.34% less time than using new in some scenarios.

I initially speculated that the reason for the performance improvement was the change in cache hit rate.

But using this benchmark https://go.dev/play/p/SCNMV6I9GWC and `go test -bench=. -count=10 -benchtime=2s > new.txt && benchstat new.txt`  got this result
         │   new.txt   │
         │   sec/op    │
NoStd-16   206.6µ ± 3%
Std-16     236.0µ ± 2%
geomean    220.9µ

It appears that there is still a 12.45% performance gap after commenting out the access code to allocated memory to reduce the access to memory.

I want to get the performance gap so the reason.

The possibility has been ruled out, AllocSoonUse  allows free memory in a way that allows for immediate reuse  , but I did not enable this opt-in.
Reply all
Reply to author
Forward
0 new messages