Live data from Hacker News

Go 1.22 Release Notes(draft)

tip.golang.org

1–4 of 4 posts

Re: Go 1.22 Release Notes(draft)

#2
what 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)

#3
post #2

what 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)

#4
post #2

what 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-.