JuliaGizmos / Interact.jl

Interactive widgets to play with your Julia code
Other
525 stars 76 forks source link

Widget creation gradually becomes very slow #400

Closed yha closed 3 years ago

yha commented 3 years ago

In a complex notebook, I find that creation of widgets (in nested @manipulate) becomes very slow (more than 10s) with continuing interaction. Reloading the page helps temporarily. Here is a simple reproducer only with widgets and no plots (using ## to represent cell breaks):

using Interact

##

@manipulate for i in 1:10
    @manipulate for j in 1:i
        j
    end
end

##

@manipulate for i in 1:10
    @manipulate for z in ["a$j" for j in 1:i]
        z
    end
end

##

@manipulate for i20 in 1:10
@manipulate for i19 in 1:10
@manipulate for i18 in 1:10
@manipulate for i17 in 1:10
@manipulate for i16 in 1:10
@manipulate for i15 in 1:10
@manipulate for i14 in 1:10
@manipulate for i13 in 1:10
@manipulate for i12 in 1:10
@manipulate for i11 in 1:10
@manipulate for i10 in 1:10
@manipulate for i9 in 1:10
@manipulate for i8 in 1:10
@manipulate for i7 in 1:10
@manipulate for i6 in 1:10
@manipulate for i5 in 1:10
@manipulate for i4 in 1:10
@manipulate for i3 in 1:10
@manipulate for i2 in 1:10
@manipulate for i1 in 1:10
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end

After some interaction with the last cell, the first two become sluggish to render the inner widget when changing the top slider. (my actual notebook has no more than two levels of nesting, but has more cells with several complex plots).

twavv commented 3 years ago

Generally you should use a "combined" for syntax.

@manipulate for i in 1:10, j in 1:10, ...
     ...
end

Only one @manipulate per widget. Otherwise, changing the outermost parameter has to re-create the whole tree beneath it, which is (as you've noticed) slow.

yha commented 3 years ago

I'm aware that @manipulate supports this syntax, but it doesn't remove the need for nested @manipulate. Nested @manipulate is required whenever the inner widgets depend on the setting of outer widgets. Not having them is a pretty severe limitation on what can be done with Interact. And it generally works fine at first but becomes slow gradually, suggesting there is some leak.