-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
show_default
, but without type parameters
#36263
Comments
Seems suspiciously relevant Lines 477 to 483 in 3222aba
One idea is a trait-based API, where a type could register "when you |
Also, julia> r = Base.OneTo(3)
Base.OneTo(3)
julia> io = IOBuffer();
julia> @btime show($io, $r)
135.656 ns (2 allocations: 96 bytes)
julia> @btime Base.show_default($io, $r)
345.577 μs (44 allocations: 21.73 KiB) A 2000x performance regression is not something to embrace lightly. |
Is there a way to make |
I agree. I suspect this is due to "show_default has great logic to use I notice that the definitions prevent specializing compiled code to the type of Lines 390 to 397 in 814945c
It seems reasonable that specializing on the type would abate that performance penalty, at the cost of introducing a compilation penalty. |
When the type is known to inference, yes. When the type is not known to inference (e.g., printing elements of a julia> using MethodAnalysis
julia> methodinstances(Base._show_default)
3-element Vector{Core.MethodInstance}:
MethodInstance for _show_default(::IOContext{IOBuffer}, ::Any)
MethodInstance for _show_default(::IOBuffer, ::Any)
MethodInstance for _show_default(::IO, ::Any) so you only have to dispatch on the |
Don't guess, profile. 99% of the time is spent on this line: Line 399 in a4cd68c
It ends up spending all of its time in calling A bit of memoization, if that would be safe, might be quite effective here. |
Definitions like
julia/base/range.jl
Line 742 in 1e76111
There are many places where that's a default behavior that is wanted. For example, when all the type parameters correspond to fields that when
show
'd reveal their type. For exampleproduces
Foo{Base.OneTo{Int64}}(Base.OneTo(3))
,which is unnecessary.
Also,
show_default
has great logic to useIOContext
to see which names need to be qualified or not:Notice the inconsistency in
Foo{OneTo{Int64}}(Base.OneTo(3))
.x-ref: #33260
The text was updated successfully, but these errors were encountered: