Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-08-26 Thread Kevin Liu
Thanks Tim for leading me to this thread. On Friday, August 26, 2016 at 11:06:33 AM UTC-3, Kevin Liu wrote: > > Nice video recommendation, Yichao. Thanks. > > On Saturday, April 2, 2016 at 1:16:07 PM UTC-3, Yichao Yu wrote: >> >> On Sat, Apr 2, 2016 at 10:26 AM, Cedric St-Jean

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-08-26 Thread Kevin Liu
Nice video recommendation, Yichao. Thanks. On Saturday, April 2, 2016 at 1:16:07 PM UTC-3, Yichao Yu wrote: > > On Sat, Apr 2, 2016 at 10:26 AM, Cedric St-Jean > wrote: > > > >> Therefore there's no way the compiler can rewrite the slow version to > the > >> fast

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-05 Thread 'Greg Plowman' via julia-users
Thanks for your relies. I'm starting to understand some of this now. In particular, I'm learning there are many aspects to dynamic dispatch. Also worth noting the difference between: if isa(features[i], A) retval += evaluate(features[i]::A) elseif isa(features[i], B) retval +=

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-04 Thread Yichao Yu
On Apr 4, 2016 1:36 PM, "Cedric St-Jean" wrote: > > I'm not a compiler dev, but here's how I understand it: > Sorry forgot to reply > > On Sunday, April 3, 2016 at 6:32:17 PM UTC-4, Greg Plowman wrote: >> >> It seems to me that slowness of dynamic dispatch and type

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-03 Thread 'Greg Plowman' via julia-users
Thanks for your replies. I'm sorry to trouble you again, but I'm still confused about general concepts. It seems to me that slowness of dynamic dispatch and type instability are orthogonal. I mean is dynamic dispatch inherently slow, or is it slow because it involves type instability?

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Yichao Yu
On Sat, Apr 2, 2016 at 10:53 PM, Cedric St-Jean wrote: > That's actually a compiler bug, nice! > > abstract Feature > > type A <: Feature end > evaluate(f::A) = 1.0 > > foo(features::Vector{Feature}) = isa(features[1], A) ? > evaluate(features[1]::A) :

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Cedric St-Jean
That's actually a compiler bug, nice! abstract Feature type A <: Feature end evaluate(f::A) = 1.0 foo(features::Vector{Feature}) = isa(features[1], A) ? evaluate(features[1]::A) : evaluate(features[1]) @show foo(Feature[A()]) type C <: Feature end evaluate(f::C) = 100 @show

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread 'Greg Plowman' via julia-users
Thanks Cedric and Yichao. This makes sense that there might be new subtypes and associated specialised methods. I understand that now. Thanks. On my machine (v0.4.5 Windows), fast() and pretty_fast() seem to run in similar time. So I looked as @code_warntype as Yichao suggested and get the

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Cedric St-Jean
On Saturday, April 2, 2016 at 5:39:45 PM UTC-4, Greg Plowman wrote: > > Cedric, > On my machine fast() and pretty_fast() run in the roughly the same time. > Are you sure pre-compiled first? > Yep. I'm using @benchmark on Julia 0.4.5 on OSX, and the time difference is definitely > 2X. > >

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Yichao Yu
On Sat, Apr 2, 2016 at 5:39 PM, 'Greg Plowman' via julia-users wrote: > Cedric, > On my machine fast() and pretty_fast() run in the roughly the same time. > Are you sure pre-compiled first? > > Yichao, >> >> The compiler has no idea what the return type of the third

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread 'Greg Plowman' via julia-users
Cedric, On my machine fast() and pretty_fast() run in the roughly the same time. Are you sure pre-compiled first? Yichao, > The compiler has no idea what the return type of the third one so this > version is still type unstable and you get dynamic dispatch at every > iteration for the floating

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Cedric St-Jean
I tried that, but it has no impact on performance, in either pretty_fast or slow. I don't understand why... retval += x::Float64 On Saturday, April 2, 2016 at 4:42:01 PM UTC-4, Matt Bauman wrote: > > Perhaps a simpler solution would be to just assert that `evaluate` always > returns a

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Matt Bauman
Perhaps a simpler solution would be to just assert that `evaluate` always returns a Float64? You may even be able to remove the isa branches in that case, but I'm not sure how it'll compare. On Saturday, April 2, 2016 at 4:34:09 PM UTC-4, Cedric St-Jean wrote: > > Thank you for the detailed

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Cedric St-Jean
Thank you for the detailed explanation. I tried it out: function pretty_fast(features::Vector{Feature}) retval = 0.0 for i in 1 : length(features) if isa(features[i], A) x = evaluate(features[i]::A) elseif isa(features[i], B) x =

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Yichao Yu
On Sat, Apr 2, 2016 at 12:16 PM, Tim Wheeler wrote: > Thank you for the comments. In my original code it means the difference > between a 30 min execution with memory allocation in the Gigabytes and a few > seconds of execution with only 800 bytes using the second

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Tim Wheeler
Thank you for the comments. In my original code it means the difference between a 30 min execution with memory allocation in the Gigabytes and a few seconds of execution with only 800 bytes using the second version. I thought under-the-hood Julia basically runs those if statements anyway for

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Yichao Yu
On Sat, Apr 2, 2016 at 10:26 AM, Cedric St-Jean wrote: > >> Therefore there's no way the compiler can rewrite the slow version to the >> fast version. > > > It knows that the element type is a Feature, so it could produce: > > if isa(features[i], A) > retval +=

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Cedric St-Jean
> Therefore there's no way the compiler can rewrite the slow version to the > fast version. It knows that the element type is a Feature, so it could produce: if isa(features[i], A) retval += evaluate(features[i]::A) elseif isa(features[i], B) retval += evaluate(features[i]::B) else

Re: [julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-02 Thread Yichao Yu
On Fri, Apr 1, 2016 at 9:56 PM, Tim Wheeler wrote: > Hello Julia Users. > > I ran into a weird slowdown issue and reproduced a minimal working example. > Maybe someone can help shed some light. > > abstract Feature > > type A <: Feature end > evaluate(f::A) = 1.0 > >

[julia-users] dispatch slowdown when iterating over array with abstract values

2016-04-01 Thread Tim Wheeler
Hello Julia Users. I ran into a weird slowdown issue and reproduced a minimal working example. Maybe someone can help shed some light. abstract Feature type A <: Feature end evaluate(f::A) = 1.0 type B <: Feature end evaluate(f::B) = 0.0 function slow(features::Vector{Feature}) retval =