I'm working on a program that creates/destroys a large number of ROIs,
and noticed a slowdown after it has been running for certain amount of
time. I was able to boil it down to this simple test program, which
illustrates the problem perfectly.
On my machine, under both linux and windows, IDL 6.1 and 6.2, this
slowdown is clearly indicated - the first loop takes about 4 seconds,
gradually increasing each time through. After about 10-20 iterations,
it is taking upwards of 10 seconds per loop.
I made a few variations of this program, and was able to determine a
few things:
* The slowdown appears to be in the IDLGrWindow object. If I destroy
and recreate it, it returns to the original speed. Destroying and
recreating a view and model has no impact.
* If I reuse, and do not destroy, the IDLGrRois, the slowdown does not
occur. Removing the IDLGrRois from the IDLGRModel, and then re-adding
them has no speed impact.
Here's the code for my test:
FUNCTION getRoi, oModel, aPos, oRoi, COLOR=aColor
angles = FINDGEN(3600) / 10.0
angles = angles * !PI / 180.0
cosines = COS(angles) / 8.0 + aPos[0]
sines = SIN(angles)/8.0 + aPos[1]
aCircleData = TRANSPOSE([[sines],[cosines]])
IF OBJ_VALID(oRoi) THEN BEGIN
oModel->remove, oRoi
OBJ_DESTROY, oRoi
ENDIF
oRoi = OBJ_NEW('IdlGrRoi', COLOR=aColor,aCircleData )
oModel->add, oRoi
return, oRoi
END
PRO testcontours
oWindow = OBJ_NEW('IDLGRWindow', TITLE='Test Window', DIM=[400,400])
oWindow->show, 1
oView = OBJ_NEW('IDLGRView')
oModel = OBJ_NEW('IDLGRModel')
oModel->scale, 2, 2, 1
oModel->translate, -1, -1, 0
oView->add, oModel
angles = FINDGEN(360)
angles = angles * !PI / 180.0
cosines = COS(angles) / 4.0 + 0.5
sines = SIN(angles)/4.0 + 0.5
aColors = [[255,0,0], [0,255,0], [0,0,255], [0,0,0]]
aROIs = OBJARR(4)
FOR i = 0, 40 DO BEGIN
starttime = systime(/seconds)
FOR j = 0, 359 DO BEGIN
FOR k = 0, 3 DO BEGIN
aOffset = [cosines[(j+90*k) MOD 360],sines[(j+90*k) MOD 360]]
aRois[k] = getRoi(oModel, aOffset, COLOR=aColors[*,k],
aRois[k])
ENDFOR
oWindow->draw, oView
ENDFOR
print, systime(/seconds)-starttime
ENDFOR
oView->remove, oModel
OBJ_DESTROY, oModel
OBJ_DESTROY, oView
OBJ_DESTROY, oWindow
END
|