Why does it take so long to delete hggroup objects?
2 views (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 24 Jul 2015
Which MATLAB release are you using? In particular is it R2014b or later, or is it an earlier version?
Accepted Answer
Mike Garrity
on 28 Jul 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.
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!