fix: change runtime.fastrand to runtime.cheaprand in go 1.22 #206
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在 Go 1.22 中
runtime.fastrand
被重构,原先的版本被改为runtime.cheaprand
但经过测试还是原先的版本更快,而且差距很大
所以我建议在 go 版本大于等于 1.22 时,使用
runtime.cheaprand
而不是runtime.fastrand
ref: https://zhuanlan.zhihu.com/p/673906980
ps: 本人在复盘 Kitex 的 Alias Method 算法 ( cloudwego/kitex#1199 )时发现在 Go 1.22 版本下的性能倒退现象,追查到本项目的 fastrand ,而 fastrand 直接依赖于
runtime.fastrand