The issue is also present for 0.3.3 --- oldest version I have installed.
That's the LLVM IR code generated:
```
julia> code_llvm(sumofsins2, (Int, ))
define double @"julia_sumofsins2;19930"(i64) {
top:
%1 = icmp sgt i64 %0, 0, !dbg !848
br i1 %1, label %L, label %L3, !dbg !848
L: ; preds = %top, %pass
%r.0 = phi double [ %6, %pass ], [ 0.000000e+00, %top ]
%"#s119.0" = phi i64 [ %5, %pass ], [ 1, %top ]
%2 = call double inttoptr (i64 4707812848 to double (double)*)(double
3.400000e+00), !dbg !849
%3 = fcmp ord double %2, 0.000000e+00, !dbg !849
br i1 %3, label %pass, label %fail, !dbg !849
fail: ; preds = %L
%4 = load %jl_value_t** @jl_domain_exception, align 8, !dbg !849, !tbaa
%jtbaa_const
call void @jl_throw_with_superfluous_argument(%jl_value_t* %4, i32 4),
!dbg !849
unreachable, !dbg !849
pass: ; preds = %L
%5 = add i64 %"#s119.0", 1, !dbg !848
%6 = fadd double %r.0, %2, !dbg !849
%7 = icmp eq i64 %"#s119.0", %0, !dbg !849
br i1 %7, label %L3, label %L, !dbg !849
L3: ; preds = %pass, %top
%r.1 = phi double [ 0.000000e+00, %top ], [ %6, %pass ]
ret double %r.1, !dbg !852
}
```
On Tuesday, January 27, 2015 at 8:46:59 AM UTC+1, Jason Merrill wrote:
>
> Looking at code_llvm(sumofsins2, (Int,)), it looks like sin(3.4) used to
> be constant collapsed [1], but is now recomputed each time through the loop.
>
> [1] That's the 0xBFD05AC910FF4C6C in the LLVM code in John's post
> reinterpret(Float64, 0xBFD05AC910FF4C6C) == -0.2555411020268312 == sin(3.4)
>
> On Monday, January 26, 2015 at 11:23:36 PM UTC-8, Mauro wrote:
>>
>> This is a performance regression, also for 0.3.5. My timings for 0.3.5:
>>
>>
>> julia> @time [sumofsins1(100_000) for i in 1:100];
>> elapsed time: 0.446675737 seconds (320109932 bytes allocated, 21.32% gc
>> time)
>>
>> julia> @time [sumofsins2(100_000) for i in 1:100];
>> elapsed time: 0.115537618 seconds (896 bytes allocated)
>>
>>
>> but for 0.2.1:
>> julia> @time [sumofsins1(100_000) for i in 1:100];
>> elapsed time: 0.347052858 seconds (320072020 bytes allocated)
>>
>> julia> @time [sumofsins2(100_000) for i in 1:100];
>> elapsed time: 0.008610216 seconds (896 bytes allocated)
>>
>>
>> Can you check whether an issue for this has been filed and if you can't
>> find one file one?
>>
>> On Tue, 2015-01-27 at 07:36, Kuba Roth <[email protected]> wrote:
>> > Hi there,
>> > Recently I run into this very interesting post:
>> >
>> http://www.johnmyleswhite.com/notebook/2013/12/06/writing-type-stable-code-in-julia/
>>
>> >
>> > Surprisingly, when tested both examples against the latest 0.4 build -
>> the
>> > speed difference of the type-stable version is only 2-3 times faster
>> then
>> > unstable one.
>> > I wonder what is the source of such a huge disparity and what version
>> of
>> > Julia was used?
>> >
>> > My timings:
>> > unstable: 0.425013212 seconds (305 MB allocated, 7.56% gc time in 14
>> pauses
>> > with 0 full sweep)
>> > stable: 0.14287404 seconds (896 bytes allocated)
>> >
>> > John's:
>> > unstable: 0.412261722 seconds (320002496 bytes allocated)
>> > stable: 0.008509995 seconds (896 bytes allocated)
>> >
>> > Thanks,
>> > kuba
>>
>>