Script takes longer and longer when accessing individual pathPoint objects.
I wrote a test script after noticing that my scripts were taking longer to run each successive time. My guess was that accessing individual path points on a pathItem was the cause and it seems that I was right.
The following script simply iterates through all the path points in all the path items of the active doc. It does this 50 times in a row. After each iteration of the main loop the time increases. The first iteration takes 103ms. The 50th iteration takes 4391ms. The script doesn't add anything to the document or modify it. It simply queries the pathPoint.anchor property for each path point.
#target illustrator
var executionTimes = [];
var timeDifferentials = [];
for(var counter = 0; counter < 50; counter++)
{
var start = new Date().getTime();
var allShapes = [];
for(var i = 0; i < app.activeDocument.pathItems.length; i++)
{
var curPI = app.activeDocument.pathItems[i];
allShapes.push(curPI);
}
for(var i = 0; i < allShapes.length; i++)
{
var curPI = allShapes[i];
for(var j = 0; j < curPI.pathPoints.length; j++)
{
curPathPoint = curPI.pathPoints[j];
var curPointLocation = curPathPoint.anchor;
}
}
var end = new Date().getTime();
var time = end - start;
executionTimes.push(time);
if(counter > 0)
{
timeDifferentials.push(time - executionTimes[counter - 1]);
}
}Below is a list of the execution times as recorded during the script
103,150,236,319,436,531,629,732,822,933,1018,1213,1424,1392,1398,1648,1606,1740,1859,1917,1937,1957,2185,2234,2283,2424,2467,2705,2584,2708,2801,2839,2996,3078,3174,3200,3355,3474,3426,3614,3789,3822,3818,3977,4062,4048,4251,4316,4406,4391
If I comment out the second line below, the execution times reduce drastically but they still increase with each iteration. However, if I comment out both the iteration times do NOT increase. they stay constnatly around 4ms.
curPathPoint = curPI.pathPoints[j];
var curPointLocation = curPathPoint.anchor;
Interestingly, if I run the script a second time on the same document without closing it, the first iteration takes longer than the last iteration of the first time I ran the script. However, if I save the doc, close illustrator, and then reopen the doc the script starts out at ~100ms again.
I don't really understand what's happening under the hood, maybe the DOM is holding on to cached data? Does anybody know a way to flush out any cached data through the javascript interface? It's troublesome to reopen illustrator every time I need to run my scripts again.
