1

I'm trying to reduce my javascript code (which have 172k lines) with Closure Compiler installed via node package manager, but it fails with "out of memory error":

$ ccjs ./static/ui.jsexe/all.js --compilation_level=ADVANCED_OPTIMIZATIONS > ./static/ui.jsexe/all.min.js                                                                              
java.lang.OutOfMemoryError: Java heap space
        at java.util.Arrays.copyOf(Arrays.java:2245)
        at java.util.Arrays.copyOf(Arrays.java:2219)
        at java.util.ArrayList.grow(ArrayList.java:213)
        at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:187)
        at java.util.ArrayList.add(ArrayList.java:411)
        at com.google.javascript.jscomp.parsing.NewIRFactory.<init>(NewIRFactory.java:241)
        at com.google.javascript.jscomp.parsing.NewIRFactory.transformTree(NewIRFactory.java:289)
        at com.google.javascript.jscomp.parsing.ParserRunner.parse(ParserRunner.java:106)
        at com.google.javascript.jscomp.JsAst.parse(JsAst.java:84)
        at com.google.javascript.jscomp.JsAst.getAstRoot(JsAst.java:50)
        at com.google.javascript.jscomp.CompilerInput.getAstRoot(CompilerInput.java:118)
        at com.google.javascript.jscomp.Compiler.hoistNoCompileFiles(Compiler.java:1500)
        at com.google.javascript.jscomp.Compiler.parseInputs(Compiler.java:1404)
        at com.google.javascript.jscomp.Compiler.parse(Compiler.java:788)
        at com.google.javascript.jscomp.Compiler.compileInternal(Compiler.java:743)
        at com.google.javascript.jscomp.Compiler.access$000(Compiler.java:93)
        at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:655)
        at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:652)
        at com.google.javascript.jscomp.Compiler$4.call(Compiler.java:699)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)

I have 16 gigabytes on my machine, how can I resolve this issue?


Geradlus_RU
  • 1,466
  • 2
  • 20
  • 37

2 Answers2

0

Looks like that would be https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/parsing/NewIRFactory.java#L245 -- it's filling an ArrayList with the indexes of every newline in the file, so that list alone would have a size of 172K.

But, if you're putting all your JS in one file before passing it to the Closure Compiler, you might consider skipping that concatentation and letting the Closure Compiler do that, by passing individual files on the command line (... --js=file1.js --js=file2.js) or using a "glob" (... --js='src/scripts/*.js'). Then it can parse each file separately which should use less memory.

Or, you can increase the max memory the JVM uses, with the Xmx option

Community
  • 1
  • 1
Tyler
  • 21,762
  • 11
  • 61
  • 90
0

OK, this was resolved by project developers, hope no one will face this issue anymore.

https://github.com/dcodeIO/ClosureCompiler.js/issues/19

Geradlus_RU
  • 1,466
  • 2
  • 20
  • 37