Skip to content

Commit b924b9b

Browse files
liuchangyanhao022
authored andcommitted
cleanup: remove redundant loop variable rebinding for Go 1.22+
Go 1.22+ scopes loop variables per iteration, so closures capture the correct value without explicit rebinding. Remove the unnecessary `gpu := gpu/die := die` to simplify the code. Signed-off-by: Teresaliu <teresaliu@didiglobal.com>
1 parent ea1d638 commit b924b9b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

core/metrics/metax_gpu.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ func metaxCollectMetrics(ctx context.Context) ([]*metric.Data, error) {
126126
eg, subCtx := errgroup.WithContext(ctx)
127127
var mu sync.Mutex
128128
for _, gpu := range gpus {
129-
gpu := gpu
129+
// Since Go 1.22, loop variables are scoped per iteration,
130+
// so closures capture the correct gpu value without rebinding.
130131
eg.Go(func() error {
131132
gpuMetrics, err := metaxCollectGpuMetrics(subCtx, gpu)
132133
if err != nil {
@@ -324,7 +325,8 @@ func metaxCollectGpuMetrics(ctx context.Context, gpuId uint32) ([]*metric.Data,
324325
eg, subCtx := errgroup.WithContext(ctx)
325326
var mu sync.Mutex
326327
for die := uint32(0); die < gpuInfo.DieCount; die++ {
327-
die := die
328+
// Since Go 1.22, loop variables are scoped per iteration,
329+
// so closures capture the correct gpu value without rebinding.
328330
eg.Go(func() error {
329331
dieMetrics, err := metaxCollectDieMetrics(subCtx, gpuId, die, gpuInfo.Series)
330332
if err != nil {

0 commit comments

Comments
 (0)