What is the quickest way to iterate over all layers in a document?

when working with large amount of files every ms counts.

I’d make use of every optimisation I could.

glad the beta is more acceptable

As of now, repeat timings can have DOM sometimes faster for some of the actions and sometimes the BatchPlay for it. So it really isn’t worth trying to optimize some of it when that is the case.

That said, I am looking at trying to remove some of the doc.duplicates, as that seems to be the costly step now. I will try see if it’s cheaper to modify the current document and save, then revert history to return to the full color pre-change mode state. If anyone knows if spawning docs or using revert tends to faster, it would be nice to have some pre-info.

I still run into what appears to be a slow memory leak. Since I don’t save into the global space in the script, it shouldn’t be the script directly, but over time Photoshop slowly increases memory used until it is double what it starts with and then it crashes. That crash is now my biggest time killer since it means I can’t just let things run overnight as a batch.

may I ask what are you using for export/save
and why are you duplicating docs?
are you resizing or what?

look into

  1. suspend history (also helps with performance)
  2. modify doc
  3. export
  4. resume history
  5. invoke undo (this should undo all changes since suspend history)

It’s been a couple of years and UXP versions, but tests I did led me to revert to a previous history state rather dupe to a new file. I can’t give you any raw figures on that though.

duplicating docs is very costly on performance and should be used as last resort for repeated tasks.

we should avoid actions that create unnecessary history entries as they’re very demanding for memory and disk space.

from my limited tests I found that suspending history greatly improves execution time and should almost always be used

This has gone way beyond iterating layers in a document. I will start a new thread dealing with optimizing repeated operations.

also please summarise your findings on this topic and mark them as solution for future readers.