Performance of placing many images in a document

I’m working on a UXP plugin that will fetch some data from an API, and place a list of image on a document as a result of it.
This list could count thousands of images, so I’m trying to find the most performant way to achieve this.

Here is a simple snippet to show how I’m considering implementing it:

Although the placeImage calls happen asynchronously, I still feel the performance is quite sluggish, eg 50 seconds for 700 images.

Are there any smart ways to improve the performance of such a script? Relinking? Disabling enableRedraw? Not relying on opening a file every time? etc?

In the past, with ExtendScript, I’ve found that turning off redraw and, strangely, hiding certain panels helps with performance of placing things. The panels might have been my weirdness because I was applying styles too.

Also, this likely won’t help, but things are much faster if the document isn’t visible. You can open documents and have them not visible. The trick, for me, has then how to make them visible without closing and reopening. I’ve never found that secret sauce! But if you are doing something like making this document and making a PDF of it, the user likely might not need to see the document and the visibility might not be important.

Jon

The trick, for me, has then how to make them visible without closing and reopening. I’ve never found that secret sauce!

app.activate() works for me.

Interesting! According to the docs:

activate()
Makes the application the front-most or active window.

What would be the “previous state”? There is no app.deactivate() method. Would I open a different blank document programmatically and keep focus on it while my operation runs, and then focus back on the original document? Hoever, app.activate() hints at the fact that it is the app that gets focus, not the document…?

Curious! I see that app.scriptPreferences.enableRedraw is by default false, so unfortunately I can’t gain much, there. Do you happen to recall which panels made a difference, for you, in terms of rendering performance? :slight_smile:

Turning off the image preview would probably save some time (relevant topic here: Solved: image preview -- reduce image placement time - Adobe Community - 9690052, because I’m too lazy), but, to be honest, 50 seconds for 700 images feels quite performant. Using InDesign server would also help.

1 Like