Hi,
I'm developping an automation script in javascript, but I have serious speed issues which are starting to be pretty worrisom.
In my script, I need to scan through the layers and layerSets of the document and analyse the hierarchy, but using DOM objects in javascript is getting extremely slow with big psd/psb files (1 minute to scan a 3.5 Gb file with 600 layers/groups). Using Action Manager, which is faster, doesn't seem to be relevant, as you can not get the hierarchy ...
So my question is, would it be possible to get faster results using a C++ routine to analyze the document ? And pass the result to the javascript to go on with the script.
I'm getting pretty stuck with javascript, and I would really need to find a suitable solution ...
Thanks a lot,
Julien
I have not done a comprehensive study of JavaScript vs C/C++ on the speed front. I would guess that 90% of the time you are *not* going to get a huge speed improvemnt.
What *does* improve speed is watching out for *active* calls. In a loop don't ask for activeDocument.activeLayer but get the activeLayer reference *before* you enter the loop. Looking up the *active* stuff does take some time. The JavaScript engine does not keep any active state so all of those active calls are calls back into Photoshop to get the real state.
var myLayer = activeDocument.activeLayer; // or do something for the activeDocument separate from the activeLayer
// now do a bunch of work on this layer using myLayer.
There is a profiler in the ESTK under the Profile menu. Check the documentation for the ESTK. I have not used it much.
Hi Julien,
I don’t know how much size of the PSD file affects the results. My plug-in (C++) also analyze layer hierarchy in a document. I do not have PSD file of that size to test my software, but my plug-in can be used in a batch mode, so I have tried it on a bout 100 documents each having about 3-10 layers and it can work for several minutes. However during parsing PSD file it also saves a bunch of clips made from layers , opens and closes PSD files makes new documents copies layers etc, and at this moment I have no way to tell precisely how much of the time goes to analyzing layers Select-Copy-Paste and disk related operations. Just for analyzing layer structure, 1 minute for 600 layers looks a bit to much to me.
If you can post somewhere a smaller example (same number of layers but smaller file for download), I could give it a try and we can compare the speed.
Regards,
Momir Zecevic
If you use the "Action Manager" APIs from Javascript it is much easier to optimize your code because you can ask for only the data you care about, and then directly send messages to execute the commands you need; iterating through layers using the DOM APIs often requires building up more complex objects and doing computations on the image data, which can be slow if the image is large.
North America
Europe, Middle East and Africa
Asia Pacific