【发布时间】:2020-03-29 03:31:45
【问题描述】:
转到版本:1.13.4 在源代码sync/once.go中,以下cmets提到了“热路径”:
type Once struct {
// done indicates whether the action has been performed.
// It is first in the struct because it is used in the hot path.
// The hot path is inlined at every call site.
// Placing done first allows more compact instructions on some architectures (amd64/x86),
// and fewer instructions (to calculate offset) on other architectures.
done uint32
m Mutex
}
我的问题是:
这里的“热路径”是什么意思?
“It is first in the struct”是否会使“热路径”访问更有效?为什么?
【问题讨论】:
-
为什么将字段放在第一位是可取的,这在最后一句中进行了解释。有什么不清楚的地方吗?
-
计算偏移量
标签: go