-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add highlighting to code_warntype for non-leaf types (such as ::Type) #10988
Comments
Some of these were likely doing just fine because they got inlined (in which case I think this change is purely cosmetic). And while this may cause more specialized methods to be compiled, I believe that these are cases where we want them to be specialized. That said, I'm unfamiliar with these portions of the codebase (cc @Jutho for concatenation, @tanmaykm for readdlm) and these were purely mechanical changes spurred by JuliaLang#10988 (`ack '::(Data)?Type[^{]' base`). This may help readdlm performance (JuliaLang#10428), but I've done no testing.
IIUC, this is a case of specializing for a wider type (DataType instead of Type{Int})? I consider that a different issue than type stability. |
Ah, you're probably right. My language isn't quite right. It's not a type-instability, but it is resulting in a non-leaf type, which ends up allocating and is a non-obvious performance trap. |
Some of these were likely doing just fine because they got inlined (in which case I think this change is purely cosmetic). And while this may cause more specialized methods to be compiled, I believe that these are cases where we want them to be specialized. That said, I'm unfamiliar with these portions of the codebase (cc @Jutho for concatenation, @tanmaykm for readdlm) and these were purely mechanical changes spurred by JuliaLang#10988 (`ack '::(Data)?Type[^{]' base`). This may help readdlm performance (JuliaLang#10428), but I've done no testing.
Let's turn this into an enhancement request. |
My intention exactly, @pao. Thanks. I know that inference is returning the correct result for the arguments (technically), but I'd like this sort of thing to be easier to spot. I looked into it myself hoping to figure out some solution, but my knowledge of the internals isn't strong enough. Here's a roadmap: the introspection macros all consider the type of a type T to be Type{T}. I think this is what they have to do in order to find the correct method. What I think could change is that the code_typed function could check to see if the methods arguments are parameterized or not, and widen those unparameterized types to |
not release-blocking |
Example from #20217: julia> @noinline f(T::DataType) = Array{T}(0);
julia> @code_warntype f(Int)
Variables:
#self#::#f
T::Type{Int64}
Body:
begin
return $(Expr(:foreigncall, :(:jl_alloc_array_1d), Array{Int64,1}, svec(Any,Int64), Array{Int64,1}, 0, 0, 0))
end::Array{Int64,1}
julia> code_warntype(f, Tuple{DataType}) # What actually happens
Variables:
#self#::#f
T::DataType
Body:
begin
return ((Core.apply_type)(Main.Array,T::DataType)::Type{_} where _<:Array)(0)::Any
end::Any |
There's now a predicate For the |
The more recent #32834 is a duplicate of this, but it seems to have a fresher and more comprehensive discussion so I'll close this one in favor of it. |
In #10961, @swt30 found and fixed a performance problem with
collect
. It was type-unstable because it had been defined ascollect(T::Type, itr)
instead ofcollect{T}(::Type{T}, itr)
. But@code_warntype
gave it a pass:It's particularly tricky in this case because inference gets it right outside the function, and then when you look inside with
@code_warntype
the macro automatically considers the type of its type arguments to beType{T}
and notDataType
. Often this is what you want (in fact, I did this in one of my first PRs), but it isn't correct in this case.This is what we should have seen:
I'm not sure how to fix this — we want the
Type{T}
definition while looking up the method, but then we don't want to pass inference more information than it'll normally get when running the code.The text was updated successfully, but these errors were encountered: