Skip to content

Improve performance of depth-limited type printing in stack traces #55952

@charleskawczynski

Description

@charleskawczynski

Can we improve the performance of depth-limited type printing in stack traces? Here is an example where printing truncated types takes quite a while with a highly nested struct:

Base.@kwdef struct Nested{A,B}
    num::Int = 1
end
nest_val(na, nb, ::Val{1}) = Nested{na, nb}()
nest_val(na, nb, ::Val{n}) where {n} = nest_val(Nested{na, nb}, Nested{na, nb}, Val(n-1))
nest_val(na, nb, n::Int) = nest_val(na, nb, Val(n))
nest_val(n) = nest_val(1, 1, n)
foo1(t::Nested) = error("oops")
foo2(t::Nested) = foo1(t)
foo3(t::Nested) = foo2(t)
foo4(t::Nested) = foo3(t)
foo5(t::Nested) = foo4(t)
foo6(t::Nested) = foo5(t)
foo7(t::Nested) = foo6(t)
foo8(t::Nested) = foo7(t)
foo9(t::Nested) = foo8(t)
foo10(t::Nested) = foo9(t)
NV = nest_val(20); # be careful with changing 20 to a larger number
foo10(NV) # errors, takes ~45 seconds on Julia 1.10

I haven't looked at the implementation in a while, but I imagine that this could be related to #55807.

Metadata

Metadata

Assignees

No one assigned

    Labels

    display and printingAesthetics and correctness of printed representations of objects.performanceMust go fastertypes and dispatchTypes, subtyping and method dispatch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions