heliosdrm / GRUtils.jl

Tools for using the GR framework in Julia
Other
31 stars 6 forks source link

Loss of performance with respect to GR #46

Open heliosdrm opened 4 years ago

heliosdrm commented 4 years ago

From #45:

I currently observe a slight performance loss of 30-40% when switching from GR to GRUtils. I would like to investigate this in more detail.

I have made some comparisons (in the REPL with the GKS device, and in Atom with Juno's plotting pane) using this code and the resulting table: https://gist.github.com/heliosdrm/e242ab6c3e035af72e4d70c521c187b3

(In the uploaded code, the jl file is ready to calculate times taken by GR; switch commented lines to change to GRUtils.)

I have observed the following (see the table in the gist):

In short: there is indeed something to look at in the cases of imshow and trisurf. But for the rest, there is a tradeoff to be considered.

I guess that the slower "first plot of each kind" is due to the fact that the method draw for Geometry also dispatches on the type of a second argument, which is a Val{kind} (where kind is the symbol that represents the kind of the plot. So, the specific method for drawing each geometry kind is not compiled until it is actually used. I made it that way in order to avoid the many if blocks that jlgr has, and perhaps (I'm not really sure) this is a factor for the improvement in the time to the very first plot. In plots that do not use a great variety of kinds, this should not be very annoying, but it may be worth to see how to improve this further.

Also, the fact that on average drawing the plots is more expensive than in GR, is probably due to the fact that the draw method for Figure always clears the current device and redraws the whole plot (including subplots). I expect this to be specially noticeable when new data are added to a figure after hold(true) or subplot(m,n,p), because the current implementation in jlgr keeps the device without clearing, and just adds new primitives to it. That is more efficient than the approach taken in GRUtils, but it leads to the problems observed e.g. in Atom and when saving figures with multiple plots with GR.