Why does it take so long to delete hggroup objects?

조회 수: 2 (최근 30일)
AFiorillo
AFiorillo 2015년 7월 24일
댓글: AFiorillo 2015년 7월 28일
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개)

Community Treasure Hunt

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

Start Hunting!

Translated by