# Slow CreateDialog when passing image sequence

I'm attempting to display an image sequence of 40 images inside of a Manipulate that cycles through each frame with a slider. I would like the Manipulate to appear in a separate DialogBox. I see a significant performance difference if I try to encapsulate this functionality inside its own function. This code displays the dialog nearly instantaneously:

CreateDialog[
Manipulate[
imageSequence[[frame]], {frame, 1, Length[imageSequence], 1}]]


However the code below takes around 10 seconds for the dialog to appear:

showit[imageSequence_] :=
CreateDialog[
Manipulate[
imageSequence[[frame]], {frame, 1, Length[imageSequence], 1}]]

showit[imageSequence]


It does not seem to matter if the function definition is surrounded by DynamicModule or not. Any ideas what is going on and what I can do to improve performance while maintaining encapsulation?

Thanks!

-

Try

showit[imageSequence_] :=
CreateDialog[
Module[{i = imageSequence},
Manipulate[i[[frame]], {frame, 1, Length[imageSequence], 1}]] ];
showit[imageSequence];


As to any insights what is going on here, I think you used the literal imagelist as Manipulate expression, thereby loading the whole of it into the front end and putting it into the manipulate cell. I used i\$xxxx as nanipulate expression, which is just a link to the actual imagelist in the kernel, from which a single frame is loaded on demand. Note, that your version of the dialog is self-contained and may be saved and then reopened in another session, my version in that case will not work, since the image list is no longer there in the kernel. Also note, that using DynamicModule doesn't help because it also keeps its variables in the front end. You may also link directly to your image lists in the kernel just by adding SetAttributes[showit, HoldAll] to your code, or using showit[Unevaluated@imageSequence]

-
It works! Any insight as to what exactly is going on behind the scenes? –  bridges2 Jul 21 '13 at 19:08
@bridges2, added some to the answer –  panda-34 Jul 22 '13 at 5:13