-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to minify/compress thousands of JS files - including some large ones - at the same time or sequentially without crashing the console? #2113
Comments
Since you're dealing with huge volumes of emscripten generated asm.js code that cannot benefit from the uglify
Uglify Should that option not work due to the size of the inputs you may be forced to disable both
|
Something else you may try: google how to increase node stack size with: Also be aware that |
Unless I misunderstand how those So looks to me Apologies if this is a dumb request, but would you mind sharing the JavaScript input files (so presumbly stuff created by I know from experience that |
I've been playing around some more with it, and it looks like the 23MB file is the one causing the issue. If I remove that one from my I'm afraid I can't share that file, however, as it's not open source. I could get in major trouble with my employer. |
@jslegers no worries. If you can somehow produce a skeleton test case that would also help, otherwise I'm afraid there are too many possibilities for me to figure out where the potential problem is. Suggestion by @kzc above would help to identify which stage is crashing, e.g. |
@alexlamsl It's easy to find large emscripten projects or make one of your own from a C/C++ code base. Here's a decent sized example: https://github.com/kripken/sql.js/
|
@kzc individually, none of them seems to fail with I've took that directory, removed $ uglifyjs js/*.js -mc passes=3,unsafe,keep_fargs=0 -o min.js --stats
<--- Last few GCs --->
[644:0000023D5829F920] 87776 ms: Mark-sweep 1403.2 (1463.6) -> 1403.2 (1432.6) MB, 1102.5 / 0.0 ms last resort
[644:0000023D5829F920] 88881 ms: Mark-sweep 1403.2 (1432.6) -> 1403.2 (1432.6) MB, 1104.5 / 0.0 ms last resort
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 00000282C84A9891 <JS Object>
1: push(this=0000021472EC4FC9 <JS Array[50855]>)
2: visit [000002B068302311 <undefined>:~3297] [pc=000000C114B258EB](this=0000025C3CF918F1 <a TreeWalker with map 00000099FF44BBB1>,node=00000293BB6B1909 <an AST_SymbolRef with map 00000099FF4526F1>,descend=000001361D388C11 <JS Function noop (SharedFunctionInfo 000000FB2CC42E59)>)
3: _visit [000002B068302311 <undefined>:~1213] [pc=00...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory |
Not surprising. Increase node's stack size or try it without mangle and/or compress. |
I'll need to do some further testing next week. |
This works:
So this is a heap rather than stack issue - and without any further specifics, I think the V8 option would be the best solution. |
Okay, it's a node issue. Not much we can do on the uglify side given the file sizes and the memory it'd take to hold the AST. |
@kzc agreed. @jslegers I'll close this out for now - will re-open if there is a different error from #2113 (comment) |
Context
With a demo I'm currently refactoring, I have a
src
folder that contains 196 MB. About 142 MB consist of two binary files.About 2000 of the remaining 2137 files (which is about 46 MB) consists of JavaScript files. More specifically, these are official and complete distributions of the LuciadRia framework & Dojo toolkit. The largest JavaScript file is about 23MB. It is unminified code originally written in C++ and compiled - with emscripten - to asm, and this code makes up the heart of the LuciadRia rendering engine.
I wanted to write a Node.js script that copies all of my files from the
src
path to thedist
path and minifies every JS or CSS file it encounters along the way. Unfortunately, the number and/or size of JS files involved seems to break my script.Let's go through the steps I took...
Step 1
I started with writing a small build script that copied all data from my
src
folder to mydist
folder. I was surprised to learn that this process finishes in a matter of seconds.Herebelow is my code for this script. Note that you'll need Node 8 to run that code.
Step 2
Tto minify my CSS files whenever I encountered them, I added CSS minification.
For that, I made the following modifications to my code.
First, I added this function :
Then, I modified my copy function, like this :
So far, so good. Everything still runs smoothly at this stage.
Step 3
Then, I did the same to minify my JS.
So again, I added a new function :
Then, I modified my copy function again :
The problem
Here, things go wrong. As the process keeps encountering more and more JS files, it keeps slowing down until the process seems to stop completely.
It appears that too many parallel processes get started and keep consuming more and more memory until no more memory is left and the process just dies silently. I tried other minifiers besides UglifyJS, and I experienced the same issue for all of them. So the problem doesn't appear to be specific to UglifyJS.
Any ideas how to fix this issue?
This is the complete code :
The text was updated successfully, but these errors were encountered: