4 ms·
Go 1.22 Release Notes(draft)
- bsaul 3y agowhat 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 ?
- athoscouto 3y agoThe compiler will avoid unnecessary allocations when possible. For more details, see https://go.dev/wiki/LoopvarExperiment#will-the-change-make-programs-slower-by-causing-more-allocations https://go.dev/wiki/LoopvarExperiment#will-the-change-make-p...
- tapirl 3y agoIt 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 < len(a); i++ { constFunc(&a) } } 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 https://gotipplay.golang.org/p/srBxORL4bm__b. The code outputs differently with 1.22 and 1.22-.