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.
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.
│ 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.