Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closure compiler dependency calculation much slower than closurebuilder.py

Previously, I have been using the following build script in order to compile a Closure project:

# BUILD SCRIPT 1:

closure-library/closure/bin/build/closurebuilder.py \
    --root=closure-library/ \
    --root=src/ \
    --namespace="entrypoint" \
    --output_mode=compiled \
    --compiler_jar=compiler.jar \
    --compiler_flags="--js=closure-library/closure/goog/deps.js" \
    --compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS" \
        > ../public_html/scripts/compiled.js

This works correctly, but yields the following output:

closure-library/closure/bin/build/closurebuilder.py: Closure Compiler 
now natively understands and orders Closure dependencies and
is prefererred over using this script for performing JavaScript 
compilation.

Please migrate your codebase.

See:
https://github.com/google/closure-compiler/wiki/Managing-Dependencies

After much experimentation, I finally got the compiler working correctly (including the necessary goog. libs):

# BUILD SCRIPT 2:

java -jar compiler.jar \
    --js "src/**.js" \
    --js "closure-library/closure/goog/**.js" \
    --js "!closure-library/closure/goog/**_test.js" \
    --dependency_mode=STRICT \
    --entry_point=entrypoint \
    --compilation_level=ADVANCED_OPTIMIZATIONS \
    --js_output_file=../public_html/scripts/compiled.js

This yields similar compiled code (some parts are re-ordered, some variable names are changed, but no important differences). However, build script 2 takes about 50% longer to run (45 seconds as compared to 30 seconds).

Is my build script 2 somehow incorrect / less efficient than it should be? If not, why is the significantly slower compilation method "preferred"?

like image 364
Mala Avatar asked Nov 07 '22 23:11

Mala


1 Answers

All the code actually gets parsed by closure-compiler, whereas closure-builder uses regex matching (I believe).

Closure-builder doesn't cover many modern dependencies such as CommonJS or ES6 modules - thus the migration.

like image 77
Chad Killingsworth Avatar answered Jan 01 '23 17:01

Chad Killingsworth