Go 1.22 Release Notes(draft)
tip.golang.org
Go 1.22 Release Notes(draft)
1–4 of 4 posts
Re: Go 1.22 Release Notes(draft)
#2what is going to be the impact in terms of performance of allocating a new variable for each iteration of the loop ?
Is the compiler smart enough to only do this when it's needed ?
Re: Go 1.22 Release Notes(draft)
#3what is going to be the impact in terms of performance of allocating a new variable for each iteration of the loop ? Is the compiler smart enough to only do this when it's needed ?
The compiler will avoid unnecessary allocations when possible. For more details, see https://go.dev/wiki/LoopvarExperiment#will-the-change-make-p...
Re: Go 1.22 Release Notes(draft)
#4what is going to be the impact in terms of performance of allocating a new variable for each iteration of the loop ? Is the compiler smart enough to only do this when it's needed ?
It will try to do this, but certainly unable to do this for all cases, such as
func foo(constFunc func(*[100000]int)) {
for a, i := [100000]int{}, 0; i
in which, the big array a will be duplicated at each step.Performance downgrade is just one problem, the most serious problem is it will break some code, such as https://gotipplay.golang.org/p/srBxORL4bm__b. The code outputs differently with 1.22 and 1.22-.