On Monday, January 06, 2014 07:00:45 PM Brendan O'Connor wrote:
> That's in the case where your code asserts the type, correct?
Yes, or when Julia can infer the type on its own.
> I think the following might illustrate what I'm wondering.
> Say arr::Array{A}, and odd elements have type B but even elements have C.
>
> This is slow, right?
> for i=1:2:length(arr) arr[i].x end
Yes.
> Will this be fast? Can Julia get away with only having to assert a
> typecheck, which hopefully is fast?
> for i=1:2:length(arr) (arr[i]::B).x end
Right again.
You probably know this as well, but just in case: Julia optimizes at the
function level, so even though your first example would be slow, let's say that
instead the inner loop contains
some_big_computation_in_a_function(arr[i])
Once Julia figured out arr[i]'s actual type and called the appropriate method,
the actual computation itself would be fast.
--Tim