[metapost] [metaobj] performance leak with boxes

Stephan Hennig mailing_list at arcor.de
Fri Apr 14 11:48:15 CEST 2006


Hi,

there seems to be a performance leak in MetaObj when building boxes with
rounded corners. The code below builds a number of boxes, ties them to a
location and draws them afterwards. There are two methods implemented:

drawImmediately:
This one builds, ties and draws all boxes in one loop.

drawDelayed:
This one build all boxes in a first loop. Afterwards, in a second loop,
all boxes are tied and drawn.

Both methods run at comparable speed when boxes have no rounded corners,
i.e., when line

setObjectDefaultOption("Box")("rbox_radius")(5bp);

is uncommented.

Unfortunately, when box_radius is set to a positive value, drawDelayed
breaks down and runs _significantly_ slower. However, drawImmediately
still runs fine. I can't see any reason for such a behavior. Did I miss
something obvious or is this a bug?

This performance leak hits one especially, when building trees from
boxes and one cannot draw (or just tie) boxes immediately.

Regards,
Stephan Hennig


input metaobj
prologues := 1;
numeric node[];

def drawImmediately(expr n) =
  for i:=1 upto n:
    newBox.node[i](decimal i);
    node[i].c = (uniformdeviate 300bp, uniformdeviate 300bp);
    drawObj(node[i]);
  endfor
enddef;

def drawDelayed(expr n) =
  for i:=1 upto n:
    newBox.node[i](decimal i);
  endfor
  for i:=1 upto n:
    node[i].c = (uniformdeviate 300bp, uniformdeviate 300bp);
    drawObj(node[i]);
  endfor
enddef;

beginfig(1);
  setObjectDefaultOption("Box")("dx")(10bp);
  setObjectDefaultOption("Box")("dy")(5bp);
  setObjectDefaultOption("Box")("rbox_radius")(5bp);
%   drawImmediately(40);
  drawDelayed(40);
endfig;

end


More information about the metapost mailing list