CEP-Resources icon indicating copy to clipboard operation
CEP-Resources copied to clipboard

Signed extension loading time too long due to node_modules

Open Jolg42 opened this issue 8 years ago • 18 comments

Hi!

I recently signed a CEP extension with node activated and some node_modules and I was surprised by the time needed to load the extension in Photoshop 2015.5.1, 1 to 3 minutes on some computers at each Photoshop restart when opening the extension.

This is only happening on computers with PlayerDebugMode to 0

I looked at the node_modules folder, there are ~5000 files.

Do you know how to have a reasonable load time (less than 20 seconds)?

Jolg42 avatar Oct 18 '16 16:10 Jolg42

Hi Joël, in my experience this has happened when the node_modules folder contained also building tools (Gulp etc) – removing them solved the issue. But frankly I haven't too many dependencies in my own projects, so you might have run into a CEP limit...?

undavide avatar Oct 18 '16 18:10 undavide

Signature verification expands, with file count. Include those additional modules, judiciously. ;)

bbb999 avatar Oct 18 '16 19:10 bbb999

It's the known issue in CEP and planning to have few improvements in the next release. For now, you can consider reducing the number of files in the extension.

venpa avatar Oct 19 '16 04:10 venpa

Thank you all for the help 😉

I reduced the number of files of node_modules to ~700 by checking everything and removing a lodash dependency from a dependency we have with npm-shrinkwrap.json (Lodash is +1000 files!) + filtering useless files (*.md, doc, tests & co).

It looks better but I need to check on more computers to be sure!

@venpa Good to know..! So is this improvement already in the Pre-Release version?

Jolg42 avatar Oct 19 '16 13:10 Jolg42

I did an homemade filtering but I just found https://github.com/KyleRoss/modclean that is doing the same but better.

Jolg42 avatar Oct 19 '16 13:10 Jolg42

@Jolg42 : We are discussing about what can be done to improve the performance of signing verification. At least, it takes 3 to 4 months to get into Prerelease builds if there is a better idea for signing verification.

venpa avatar Oct 19 '16 14:10 venpa

@venpa Ok! Thank you for the details 👍

Jolg42 avatar Oct 19 '16 14:10 Jolg42

@Jolg42 Probably a bit late for you but using a framework like Webpack to consolidate your JS can massively improve this performance (10x +)

johnlouis-swaine-axomic avatar May 22 '17 10:05 johnlouis-swaine-axomic

@johnlouis-swaine-axomic Yes! But only for the "front-end" part.

For Node.js dependencies, it's a lot harder :( My advice for Node.js dependencies is to select them carefully and to check sub-dependencies...! As 1 package can add a few thousand files sometimes!

I also use modclean to clean the node_modules folder (removings "test" folders & useless things).

Jolg42 avatar May 22 '17 10:05 Jolg42

We recently had to solve this problem too, we had over 10,000 files in our node_modules modclean didn't really help much, because the number of "actual" .js files alone was pretty huge.

In the end, I used module-concat to concatenate all the files in node_modules together with my own JS files into 1 single JS file. And the ZXP signing and verification during ZXP installation/panel loading was much faster.

jingtaotan avatar May 22 '17 10:05 jingtaotan

Your output file must be huge :D Thanks for sharing! Do you know if it's compatible with a Webpack or Browserify setup?

Jolg42 avatar May 22 '17 10:05 Jolg42

Your output file must be huge

Our concatenated single JS file is 2MB in size, the signed ZXP only about 500KB.

I am not sure about using module-concat with Webpack and Browserify. I had in mind to try Webpack/Browserify but they both seemed too complex to setup for what I was trying to do.

In fact the author of module-concat says that he also did not want a heavy-weight approach like Webpack/Browserify. So maybe @Jolg42 you could give one or the other a try.

jingtaotan avatar May 22 '17 10:05 jingtaotan

I'm already using Browserify actually, but I didn't try to require/concat node_modules with it. I don't know if this approach is compatible with any package though, like packages requiring binaries...

Jolg42 avatar May 23 '17 09:05 Jolg42

Does anyone have a solution/workaround? I have encountered the same problem. Loading extensions takes minutes as the extension contains thousands of files and the signature verification takes a long time.

zhangusc avatar Feb 09 '21 08:02 zhangusc

The only solution I found was to drastically reduce the amount of files. I used webpack but any bundler should do the job.

noamraby-ssky avatar Feb 09 '21 09:02 noamraby-ssky

@ErinFinnegan Is it possible for the signing tool (ZxpSignCmd) to exclude a subfolder (e.g. a JS library) in the extension from signing?

zhangusc avatar Feb 10 '21 19:02 zhangusc

@zhangusc here's the answer from engineering:

As of now it is not possible to exclude a subfolder in signing using the ZXPSignCmd. All the contents of the input directory provided in signing are packaged inside the signed ZXP.

ErinFinnegan avatar Feb 11 '21 12:02 ErinFinnegan

For what it's worth, another bottleneck for load times, at least in InDesign, can be the structure of the ExtendScript (jsx) files. We were able to reduce our load times from ~30 seconds to ~2 seconds using the following two methods:

  1. The larger the fully unfolded .jsx file pointed to in your manifest.xml file, the longer the load time. It's not just the size of the single .jsx file pointed to in the manifest file, but all the files included by that file. Optimizing that file by removing all unnecessary and redundant includes improved our load times a lot.

  2. Compiling the .jsx file pointed to in the manifest file to .jsxbin, and pointing the manifest to that jsxbin file, also reduced our load times.

lsh246 avatar Aug 24 '21 15:08 lsh246