Isaiah's demo is brief and compelling. You'll want this, though:
disassemble(f, Int) -> disassemble(f, (Int,))
See a rather more long-winded explanation here:
http://docs.julialang.org/en/latest/manual/faq/#how-do-abstract-or-ambigious-
fields-in-types-interact-with-the-compiler
On Friday, July 26, 2013 09:29:12 PM Isaiah Norton wrote:
> Compare the LLVM IR for these two simple functions:
>
> julia> f(x::Int) = x + 1
> julia> f(x::Union(Int, Nothing)) = x + 1
>
> julia> disassemble(f, Int)
> julia> disassemble(f, (Union(Int, Nothing),))
>
> The former maps to a single instruction, whereas the latter generates a
> mess of bookkeeping
> and error-checking instructions to deal with the ambiguity.
>
> On Fri, Jul 26, 2013 at 7:33 PM, Tomas Lycken <
tomas....@gmail.com>wrote:
> > In most cases, it's about storage - for example, an Array{Float64} can be
> > stored as a contiguous array of floats, and the compiler knows exactly how
> > much memory will be needed, how to access it, etc, while an Array{Number}
> > is much more ambiguous and leaves the compiler with very few possibilities
> > of optimizing the code.
> >
> > There's a whole section on this in the
> > manual<
http://docs.julialang.org/en/release-0.1/manual/performance-tips/#
> > declare-specific-types-for-fields-of-composite-types>;) It mentions this
> > mostly for composite types, but I guess it's a pretty general
> > consideration - if the compiler knows more about how to store your data,
> > it can optimize better. Since no type can inherit from concrete types in
> > Julia, using concrete types guarantees that the compiler has the maximum
> > possible amount of information about what you're trying to do, so it can
> > optimize as well as possible.
> >
> > // T
> >
> > On Saturday, July 27, 2013 12:28:44 AM UTC+2, Cassio Martini M. P. wrote:
> >> Interesting. Do you have some idea of what would be the speedup?
> >> Em 26/07/2013 15:58, "Dahua Lin" <
lind...@gmail.com> escreveu:
> >>
> >> I am actually considering an alternative implementation that does not
> >>
> >>> rely on declaring fields as Union(Node, Nothing).
> >>>
> >>> In my experience, using non-concrete types (e.g. union or abstract
> >>> types) almost always limits performance.
> >>>
> >>> - Dahua
> >>>
> >>> On Thursday, July 25, 2013 8:58:28 AM UTC-5, Cassio Martini M. P. wrote:
> >>>> Thanks everyone for their input.
> >>>>
> >>>> I think that coming from other languages that have some kind of null
> >>>> pointer, such as Java, Python, C, etc, I just expected that Julia would
> >>>> have it too, but I see what Stefan is saying about performance. I
> >>>> wonder if
> >>>> Numpy/Scipy also suffer from this problem.
> >>>>
> >>>> lindahua is using the same technique of Union(T,Nothing) to account for
> >>>> null possibilities in
https://github.com/**lindahua**
> >>>> /DataStructures.jl/**blob/**master/src/deque.jl<
https://github.com/lind
> >>>> ahua/DataStructures.jl/blob/master/src/deque.jl>
> >>>>> As already mentioned,
https://github.com/****
> >>>>> lindahua/DataStructures.jl<
https://github.com/lindahua/DataStructures.
> >>>>> jl> is a good source of inspiration (and perhaps there's even a data
> >>>>>>>>>
http://docs.julialang.org/en/**l**atest/manual/constructors<http:/
> >>>>>>>>> /
docs.julialang.org/en/latest/manual/constructors>
> >>>>>>>>>
> >>>>>>>>> The discussion of incomplete initialization on that page may
> >>>>>>>>> address your second point. If not, can you clarify what you are
> >>>>>>>>> looking
> >>>>>>>>> for? Ptr{Void} is a valid thing and can be used (with care) in the
> >>>>>>>>> context
> >>>>>>>>> of calling C libraries. Otherwise None and Nothing can fulfill the
> >>>>>>>>> "undefined" role in pure Julia programs - used in moderation!
> >>>>>>>>>
> >>>>>>>>> Also, you may be interested in the following packages:
> >>>>>>>>>
https://github.com/JuliaLang/**G**raphs.jl<
https://github.com/Juli
> >>>>>>>>> aLang/Graphs.jl>
> >>>>>>>>>
https://github.com/lindahua/**Da**taStructures.jl<
https://github.
> >>>>>>>>> com/lindahua/DataStructures.jl>