Message Boards Message Boards

Is Grid preferable to GraphicsGrid for dynamic rendering?

Posted 1 day ago

In the context of my research, I created a static 2X2 array of plots of some complexity and displayed them using GraphicsGrid I then wanted to observe how the bottom row changed with a certain parameter with the top row fixed, not dependent upon this parameter. As precomputed static plots, I thought they would not make rendering much more difficult. The resulting animation, generated by Manipulate[GraphicsGrid[{{staticPic1, staticPic2}, {dynPic1[p], dynPic2[p]}}, {p, 0, 1}], was not highly responsive. Specifically, the motion in the bottom two plots was jumpy. After trying many ways to make dynPic1 and dynPic2 more efficient, I found merely replacing GraphicsGrid with Grid produced a completely smooth and responsive animation (and switching back slowed the animation again and switching back to Grid again sped it back up).

I then tried to illustrate what I thought was the generic slowing behavior of GraphicsGrid (relative to Grid) using the simple example below, though switching to GraphicsColumn for simplicity, the single column case of Grid. But this example, provided at the end of this post, seemed to render just as quickly with GraphicsColumn as with Column.

I assume that Grid and Column are preferable from the standpoint of performance but my attempt to generate a simple illustration of this has failed. I could try to create a more complex example but I thought I might ask for help. To explicitly state the question: Are Grid and Column indeed preferable when speed or responsiveness is desired and the items being plotted are non-trivial? If the answer to this question is "yes", perhaps this should be mentioned in the Properties and Relations section of the documentation for Grid and GraphicsGrid.

The failed example

Compare responsiveness of slider of the following Manipulate commands:

Manipulate[
 GraphicsColumn[{Plot[Sin[2 Pi f t - 2 Pi 0], {t , 0, 6}], 
   Plot[Sin[2 Pi f t - 2 Pi 0.2], {t , 0, 6}], 
   Plot[Sin[2 Pi f t - 2 Pi 0.4], {t , 0, 6}], 
   Plot[Sin[2 Pi f t - 2 Pi 0.6], {t , 0, 6}]}], 
 {f, 0.5, 2.5}
 ]

Manipulate[
 Column[{Plot[Sin[2 Pi f t - 2 Pi 0], {t , 0, 6}], 
   Plot[Sin[2 Pi f t - 2 Pi 0.2], {t , 0, 6}], 
   Plot[Sin[2 Pi f t - 2 Pi 0.4], {t , 0, 6}], 
   Plot[Sin[2 Pi f t - 2 Pi 0.6], {t , 0, 6}]}], 
 {f, 0.5, 2.5}
 ]

Result: comparable responsiveness on an M3 MacBook Air.

POSTED BY: David O'Gorman
2 Replies

It seems it is slower to convert GraphicsGrid[] to boxes:

grid = ConstantArray[Graphics[{}, Axes -> True], {2, 2}];

GraphicsGrid[grid] // MakeBoxes[#, StandardForm] &; // RepeatedTiming
(*  {0.0460591, Null}  *)

Grid[grid] // MakeBoxes[#, StandardForm] &; // RepeatedTiming
(*  {0.00023938, Null}  *)

If we include everything, generating the plots and making boxes, we get the following timings:

grid := ConstantArray[Plot[Sin[2 Pi 0.5 t - 2 Pi 0], {t, 0, 6}], {2, 2}]; (* delayed evaluation *)
GraphicsGrid[grid] // MakeBoxes[#, StandardForm] &; // RepeatedTiming
Grid[grid] // MakeBoxes[#, StandardForm] &; // RepeatedTiming
(*
{0.33534, Null}
{0.0111483, Null}
*)
POSTED BY: Michael Rogers
Posted 1 day ago

If I've understood your post, the problem was detectable when comparing Grid and GraphicsGrid, but the example you've given us is Column and GraphicsColumn. I went ahead and switched them to Grid and GraphicsGrid, but I can't know what the code actually was that showed the problem. I saw no slowdowns nor any difference in any of the four examples I tried.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract