You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is problematic, as it actually prevents the Julia compiler from working it's performance magic. See this part of the manual.
The problem is that this actually tells the Julia compiler that this field has to be able to hold any subtype of AbstractFloat, so the compiler has to box it, meaning it can't optimize on the actual type of freq at runtime.
Sounds like a small improvement, but a good one. Yeah I'm always looking for ways to make the code more Julian and easier to use. Do you have time to create a PR?
The way Starlight.jl's datatypes are currently defined with abstractly-typed fields, e.g.
AbstractFloat
inis problematic, as it actually prevents the Julia compiler from working it's performance magic. See this part of the manual.
The problem is that this actually tells the Julia compiler that this field has to be able to hold any subtype of
AbstractFloat
, so the compiler has to box it, meaning it can't optimize on the actual type offreq
at runtime.The correct way to do this is to use parametric types :
This way, the concrete type of
freq
is known to the compiler at runtime, so it can optimize on it.As an aside, a better way to define default fields values is to use Parameters.jl :
This has the advantage that it automatically defines constructors with keyword arguments, so the following snippets are all valid,
The text was updated successfully, but these errors were encountered: