Skip to content

absurdly slow operations on deeply nested pairs #30476

@stevengj

Description

@stevengj

I noticed while testing #30471 that printing deeply nested Pair types seems absurdly slow. In Julia 1.0, I get:

julia> p = mapfoldl(abs, =>, -27:-1); @time println(p)
(((((((((((((((((((((((((27=>26)=>25)=>24)=>23)=>22)=>21)=>20)=>19)=>18)=>17)=>16)=>15)=>14)=>13)=>12)=>11)=>10)=>9)=>8)=>7)=>6)=>5)=>4)=>3)=>2) => 1
 48.127456 seconds (1.36 M allocations: 67.004 MiB, 0.04% gc time)

Almost a minute and over a million allocations to print a 150-character string doesn't seem right.

In contrast, mapfoldl(abs, Pair{Any,Any}, -50:-1) prints instantly, and similarly for calling println(p) a second time above, so the problem must have to do with compiling lots of code specialized for the different nested Pair types above.

It might be fixed by adding @nospecialize to the show function for Pair, but I wonder if there is a deeper problem & solution for nested parameterized types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceMust go fasterregressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions