go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

采用fastrand 替换 "math/rand" 来提升性能

Open songoow opened this issue 5 years ago • 1 comments

Is your feature request related to a problem? Please describe. 根据他们测试的结果 https://github.com/bytedance/gopkg/tree/develop/lang/fastrand, fastrand 比math/rand 的使用要快不少,go-zero 中有不少场景使用了math/rand

Describe the solution you'd like 如果适合 go-zero 这边的话,我来提交一个pr

Describe alternatives you've considered https://github.com/valyala/fastrand 这个也许也是合适的

Additional context math/rand全局共享了同一个 globalRand 对象,fastrand 使用 go:linkname 直接调用了 runtime.fastrand

songoow avatar Oct 30 '21 02:10 songoow

感谢哈,不过这个不需要,原因有两个:

  1. 这个对性能的影响极低
  2. 尽可能减少包依赖

非常感谢哈

kevwan avatar Oct 30 '21 07:10 kevwan