I know this is an optimization. I'm just seeking why the criterion to apply 
the optimization is made as the current implementation.

On Sunday, May 23, 2021 at 10:10:59 AM UTC-4 peterGo wrote:

> Here, and elsewhere (Strange benchmark results), if you not sure what is 
> going on then you say that it must be weird, strange, an error, inaccurate, 
> and so on. The problem appears to be that you are not taking into account 
> that the Go gc and gccgo compilers are optimizing compilers.
>
> For your example,
>
> https://play.golang.org/p/3Cst23vNkKI
>
> $ go version
> go version devel go1.17-cca23a7373 Sat May 22 00:51:17 2021 +0000 
> linux/amd64
> $ go run -gcflags='-m -m' tl.2.go
> ./tl.2.go:18:6: can inline g with cost 8 as: func() []T { var ts []T; ts = 
> make([]T, N); return ts }
> ./tl.2.go:9:6: can inline main with cost 28 as: func() { var r []T; r = 
> make([]T, N); println(r[i]); var r1 []T; r1 = g(); println(r1[i]) }
> ./tl.2.go:13:15: inlining call to g func() []T { var ts []T; ts = 
> make([]T, N); return ts }
> ./tl.2.go:10:17: make([]T, N) does not escape
> ./tl.2.go:13:15: make([]T, N) does not escape
> ./tl.2.go:19:18: make([]T, N) escapes to heap:
> ./tl.2.go:19:18:   flow: ts = &{storage for make([]T, N)}:
> ./tl.2.go:19:18:     from make([]T, N) (spill) at ./tl.2.go:19:18
> ./tl.2.go:19:18:     from ts = make([]T, N) (assign) at ./tl.2.go:19:9
> ./tl.2.go:19:18:   flow: ~r0 = ts:
> ./tl.2.go:19:18:     from return ts (return) at ./tl.2.go:20:5
> ./tl.2.go:19:18: make([]T, N) escapes to heap
>
>
> On Sunday, May 23, 2021 at 5:01:38 AM UTC-4 tapi...@gmail.com wrote:
>
>> And how to interpret the conflicting messages for the following program?
>>
>> package main
>>
>> type T int
>>
>> const N = 1<<12
>> var i = N - 1
>>
>>
>> func main() {
>>     var r = make([]T, N) // make([]T, N) does not escape
>>     println(r[i])
>>     
>>     var r1 = g() // make([]T, N) does not escape
>>     println(r1[i])
>>     
>> }
>>
>> func g() []T {
>>     var ts = make([]T, N) // make([]T, N) escapes to heap
>>     return ts
>> }
>>
>> On Sunday, May 23, 2021 at 4:51:30 AM UTC-4 tapi...@gmail.com wrote:
>>
>>> In the following code, "make([]T, n)" is reported as escaped.
>>> But does it really always escape at run time?
>>> Does the report just mean "make([]T, n) possibly escapes to heap"?
>>>
>>> package main
>>>
>>> type T int
>>>
>>> const K = 1<<13
>>> const N = 1<<12
>>> var n = N
>>> var i = n-1
>>>
>>> func main() {
>>>     var r = make([]T, N) // make([]T, N) does not escape
>>>     println(r[i])
>>>     
>>>     var r2 = make([]T, n) // make([]T, n) escapes to heap
>>>     println(r2[i])
>>>     
>>>     var r3 = make([]T, K) // make([]T, K) escapes to heap
>>>     println(r3[i])
>>> }
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/34565fef-a650-4790-8ad2-93fa527e9281n%40googlegroups.com.

Reply via email to