Why does it take so long to delete hggroup objects?

2 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2015-7-24
Which MATLAB release are you using? In particular is it R2014b or later, or is it an earlier version?
AFiorillo
AFiorillo 2015-7-27
I'm using R2015a (8.5.0.197613) with the Image Processing Toolbox v9.2.

请先登录,再进行评论。

采纳的回答

Mike Garrity
Mike Garrity 2015-7-28
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 个评论
AFiorillo
AFiorillo 2015-7-28
Thank you for the detailed answer! This helped clarify the nature of a huge slow-down in my project.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by