Why does it take so long to delete hggroup objects?

2 visualizaciones (últimos 30 días)
AFiorillo
AFiorillo el 24 de Jul. de 2015
Comentada: AFiorillo el 28 de Jul. de 2015
I'm using the impoly function from the Image Processing Toolbox to draw regions on a somewhat large image. When these regions have many vertices, 500+, it takes a long time (20+ seconds) to delete the impoly handle.
The hggroup object seems to essentially be a structure that contains an array of vertices/vectors. Why does it take so long to delete if that array has over a few hundred objects?
  2 comentarios
Walter Roberson
Walter Roberson el 24 de Jul. de 2015
Which MATLAB release are you using? In particular is it R2014b or later, or is it an earlier version?
AFiorillo
AFiorillo el 27 de Jul. de 2015
I'm using R2015a (8.5.0.197613) with the Image Processing Toolbox v9.2.

Iniciar sesión para comentar.

Respuesta aceptada

Mike Garrity
Mike Garrity el 28 de Jul. de 2015
It's not actually the hggroup objects. Deleting those is actually quite quick. It's all of the other stuff that's happening when you delete the hggroup objects. The profiler doesn't have a good way to tell you about all of the details.
Consider this example:
n = 5000;
%%Just Groups
clf
drawnow
h = gobjects(1,n);
tic
for i=1:n
h(i) = hggroup;
end
drawnow;
disp(['Just the groups, create = ' num2str(1e3*toc/n) ' milliseconds'])
tic
delete(h)
drawnow
disp(['Just the groups, delete = ' num2str(1e3*toc/n) ' milliseconds'])
%%Groups with Children
clf
drawnow
h = gobjects(1,n);
tic
for i=1:n
h(i) = hggroup;
line([i i],[-1 1],'Parent',h(i));
end
drawnow
disp(['Groups with lines, create = ' num2str(1e3*toc/n) ' milliseconds'])
tic
delete(h)
drawnow
disp(['Groups with lines, delete = ' num2str(1e3*toc/n) ' milliseconds'])
%%Groups with Children and ButtonDownFcns
clf
drawnow
h = gobjects(1,n);
tic
fcn = @(~,~)disp(i);
for i=1:n
h(i) = hggroup;
line([i i],[-1 1],'Parent',h(i));
set(h(i),'ButtonDownFcn',fcn)
end
drawnow
disp(['Groups with ButtonDownFcn, create = ' num2str(1e3*toc/n) ' milliseconds'])
tic
delete(h)
drawnow
disp(['Groups with ButtonDownFcn, delete = ' num2str(1e3*toc/n) ' milliseconds'])
If you run this, you'll see that the delete gets progressively slower in each of the three cases.
In the second case, we've added children to the hggroups. These get deleted when the hggroups get deleted. That costs something. The hggroup objects that impoly returns have couple of children to draw the polygon.
In the third case, we've added function handles to the hggroups. The hggroups which are created by impoly have a bunch of function handle properties added to them to implement all of the interactive behavior. These function handles have to be cleaned up when the hggroup objects are deleted.
  1 comentario
AFiorillo
AFiorillo el 28 de Jul. de 2015
Thank you for the detailed answer! This helped clarify the nature of a huge slow-down in my project.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by