Prevent Re-drawing the Same Plot

I have large pluto notebooks with many plots, they are different analysis’ for engineers to re-use and update when the corresponding designs are updated.

My issue is that opening one of these in pluto for the first time takes maybe 1 minute. I see that a large portion of this is re-generating plots. Most of the time these plots are going to be re-drawn exactly the same over and over.

What I would like is if Pluto could detect if there was any change to the plot() call and only redraw when it changes. When there was not any changes, pluto would just reload a saved .png in the working directory. It seems like this would be relatively easy to get working:

  1. Hash all the input arguements and save it somehow (comment in notebook?)
  2. Generate image when drawing plot
  3. Next time, hash input arguments again
  4. If hashes differ, redraw plot and save new image
  5. if hashes are the same, call LocalResource("plot_image.png")

I might start developing this but I wanted to see if there was already some feature out there that could get me going quicker. Or if anyone has any sugestions about better ways to do this.

Hey @luke-pikaart !

You could put your plotting code in a function (with the right arguments), and use @memoize from Memoization.jl on that function. Then you don’t need to deal with image files :slight_smile: Check the Memoization.jl docs for more info, you probably want to use an LRU cache.

Alternatively, you could use @use_memo from PlutoHooks.jl.

1 Like