Why does turning the visibility of a figure to "off" slow things down?

I have an application where turning the visibility of the figure off actually quadruples the run time of my program. I do a lot of axis and lighting manipulations between grabbing the screen.
Here is brief example that leads to a roughly 10% increase in time:
%%->> Visible ON<<-
tic
h = figure('Visible', 'On');
surf(peaks);
light;
axis([10 40 10 40 -5 5]);
h.Color = 'r';
view(45,45);
data = getframe();
toc
%%->>Visible OFF<<-
tic
h = figure('Visible', 'Off');
surf(peaks);
light;
axis([10 40 10 40 -5 5]);
h.Color = 'r';
view(45,45);
data = getframe();
toc
Basically, I would love an explanation as to why MATLAB acts any differently when the figure is not displayed!

Answers (1)

They actually don't do the same thing at all.
In the Visible='on' case, the pixels are already sitting in the framebuffer on the graphics card. The getframe function just fetches them.
In the Visible='off' case, there is no framebuffer and the graphics haven't already been drawn. So the getframe command basically starts a print job. Printing is nearly as tightly optimized as on screen rendering because it supports lots of additional features that you're not using here. For one thing, it needs to allocate a number of resources which are basically free when you're drawing into the framebuffer.

2 Comments

Mike, is that "is nearly" or "is not nearly" ? The "is nearly" would imply that the timing should be very close, which the rest of your discussion seems to argue otherwise.
Yes, it looks like I lost track of a negation there. Sorry about that.

Sign in to comment.

Categories

Asked:

on 19 Nov 2015

Commented:

on 23 Nov 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!