I can't quite tell: are you aware the `begin end` does not introduce a
new scope?
This (sans begin-end) produces 'long'
local const aa = rand()
test2() = aa::Float64 + aa::Float64
@code_native test2()
and this short:
const aa = rand()
test2() = aa::Float64 + aa::Float64
@code_native test2()
Note sure what local is supposed to do but probably not slow down
things. Bug?
Anyway, I think the "correct" way is your test2 example:
let a::Float64 = rand()::Float64
global test2
test2() = a::Float64 + a::Float64
end
and if that is not fast/short then this is a performance bug, right?
>> Hi,
>> I was trying to find out, what the best way is to have some local, constant
>> storage for a function, which is only accessible from inside the function
>> So something like this:
>> begin
>> const local a = []
>> test() = dosomething(a)
>> end
>>
>> I was quite surprised, that you can't do this efficiently.
>> Or at least I didn't find a way, or tested it incorrectly.
>> Here are the different combinations I tried and the emitted native code:
>> https://gist.github.com/SimonDanisch/e4bed0a16bdd847a8c2b#file-local_functio
>> n_storage-jl
>>
>> test11 && test12 seems to be what julia does internally for test1-test4
>> (and the example here)
>> It's especially odd, as a global const seems to be faster than a local
>> const, even though that the local version is more restricted.
>> Is this because there has been more time spend on making globals fast?
>>
>> Best,
>> Simon