Highlighted

Any ways to increase performance of iterating through large collections?

Contributor ,
Sep 25, 2020

Copy link to clipboard

Copied

   I have a lot of scripts which deal with cleaning up imported architectural artwork which tends to have 100's of 1000's of objects, most of which are very small, or white objects on white backgrounds, or unfilled and unstroked objects - all of which and can be deleted.

 

   At least with very large collections, it seems that iterating through them is on the order of n² for some reason.  These larger the collection is the longer it takes to iterate through it, and that time grows exponentially, not linearly as one might assume.

 

   Wondering if anyone elses has run into this problem with larger collections and has found any methods to work around it?

TOPICS
Performance, Scripting

Views

65

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Any ways to increase performance of iterating through large collections?

Contributor ,
Sep 25, 2020

Copy link to clipboard

Copied

   I have a lot of scripts which deal with cleaning up imported architectural artwork which tends to have 100's of 1000's of objects, most of which are very small, or white objects on white backgrounds, or unfilled and unstroked objects - all of which and can be deleted.

 

   At least with very large collections, it seems that iterating through them is on the order of n² for some reason.  These larger the collection is the longer it takes to iterate through it, and that time grows exponentially, not linearly as one might assume.

 

   Wondering if anyone elses has run into this problem with larger collections and has found any methods to work around it?

TOPICS
Performance, Scripting

Views

66

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 25, 2020 1
Most Valuable Participant ,
Sep 25, 2020

Copy link to clipboard

Copied

Without knowing your code nobody can tell you much. Chances are you simply need to break it down in chunks to avoid the object collection become so bloated.

 

Mylenium

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 25, 2020 1
Contributor ,
Sep 25, 2020

Copy link to clipboard

Copied

Here's a simple example.  This script creates 10,000 pathItems, 100 groups of 100. After each group is added to the document all pathItems in the document are iterated through and the length property is accessed. This iteration is timed and after the iteration the time is output to the console. Times from $.hiresTimer are in microseconds.

 

Plotting this, it's actually nowhere close to n² but it still gets very slow very fast for an iteration you would expect to be linear.

 

You'll want to run this in the ExtendScript IDE so you can stop the script.

 

#target illustrator

var groups = 100;
var groupSize = 100;

var doc = app.documents.add();

clearConsoleWindow();

for (var i = 0; i < groups; i++)
{
    for (var j = 0; j < groupSize; j++)
    {
        doc.pathItems.rectangle (10, 10, 10, 10);
    }
    $.hiresTimer;
    
    for (var j = 0; j < doc.pathItems.length; j++)
    {
        var temp = doc.pathItems.length;
    }

    var time =  $.hiresTimer;
    $.writeln(i + ", "+ time);
    
}

function clearConsoleWindow()
{
    var estApp= BridgeTalk.getSpecifier("estoolkit");
    if(estApp)
    {
        var bt = new BridgeTalk;
        bt.target = estApp;
        bt.body = "app.clc()";
        bt.send();
    }
}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 25, 2020 0
ssamanen LATEST
Explorer ,
Sep 25, 2020

Copy link to clipboard

Copied

I often have a similar issue, which is importing PDFs exported from CAD, Vectorworks and Sketchup, architectural drawings.  I don't have a good answer, but what I do is run through the drawings and select lines and dimensions I absolutely need, then paste it into a new document.  Sometimes I select all white and unstroked unfilled objects and delete them at once, which can help.  Generally I'm less and less impressed with Illustrator's performance.  Photoshop gets faster seemingly all the time, but Illustrator isn't noticeably faster than it was ten years ago.  Big complex documents just kill it.

 

Interestingly, I've just downloaded Affinity Design, and early indications for me are that it doesn't appear to have the same problem with large complex documents.  In one complex Illustrator file (3,000 paths, 13,000 points, 35mb), moving one object incurs a delay of 1-2 seconds for me, while no lag exists in Affinity Design with the exact same complex object in the exact same file.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 25, 2020 0