Skip to content

Commit

Permalink
Replace Closure Compiler with UglifyJS 2.
Browse files Browse the repository at this point in the history
Replacing the slow Java Closure Compiler by UglifyJS 2.

Benchmark (local machine):

| Minifier | Time (sec) | Size (KB) |
| -------- | ---------- | --------- |
| Closure  |       54.9 |      2980 |
| UglifyJS |       27.2 |      2996 |

* Time: `time tools/minify-js`
* Size: `du -k static/min`

All safe optimizations for UglifyJS 2 are enabled by default and
can be disabled to reduce run time.

Fixes zulip#693.
  • Loading branch information
tommyip committed Jan 11, 2017
1 parent 207b2e0 commit 99591c9
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 46 deletions.
10 changes: 4 additions & 6 deletions docs/dev-setup-non-vagrant.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Start by cloning this repository: `git clone
https://github.com/zulip/zulip.git`

```
sudo apt-get install closure-compiler libfreetype6-dev libffi-dev \
sudo apt-get install libfreetype6-dev libffi-dev \
memcached rabbitmq-server libldap2-dev redis-server \
postgresql-server-dev-all libmemcached-dev python-dev \
hunspell-en-us nodejs nodejs-legacy npm git yui-compressor \
Expand Down Expand Up @@ -121,7 +121,7 @@ https://github.com/zulip/zulip.git`
```
sudo add-apt-repository ppa:tabbott/zulip
sudo apt-get update
sudo apt-get install closure-compiler libfreetype6-dev libffi-dev \
sudo apt-get install libfreetype6-dev libffi-dev \
memcached rabbitmq-server libldap2-dev redis-server \
postgresql-server-dev-all libmemcached-dev python-dev \
hunspell-en-us nodejs nodejs-legacy npm git yui-compressor \
Expand All @@ -142,7 +142,7 @@ https://github.com/zulip/zulip.git`
sudo dnf install libffi-devel memcached rabbitmq-server \
openldap-devel python-devel redis postgresql-server \
postgresql-devel postgresql libmemcached-devel freetype-devel \
nodejs npm yuicompressor closure-compiler gettext
nodejs npm yuicompressor gettext
```

Now continue with the [Common to Fedora/CentOS](#common-to-fedora-centos-instructions) instructions below.
Expand Down Expand Up @@ -179,8 +179,7 @@ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noa
sudo yum install libffi-devel memcached rabbitmq-server openldap-devel \
python-devel redis postgresql-server postgresql-devel postgresql \
libmemcached-devel wget python-pip openssl-devel freetype-devel \
libjpeg-turbo-devel zlib-devel nodejs yuicompressor \
closure-compiler gettext
libjpeg-turbo-devel zlib-devel nodejs yuicompressor gettext
# We need these packages to compile tsearch-extras
sudo yum groupinstall "Development Tools"
Expand Down Expand Up @@ -460,4 +459,3 @@ the results in your browser.
Currently, the Docker workflow is substantially less convenient than
the Vagrant workflow and less documented; please contribute to this
guide and the Docker tooling if you are using Docker to develop Zulip!

2 changes: 1 addition & 1 deletion docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ major focus area for the project.
* [Add support for changing users' email
addresses](https://github.com/zulip/zulip/issues/734)
* [Migrate from jslint to eslint](https://github.com/zulip/zulip/issues/535)
* [Replace the slow closure-compiler based static asset toolchain](https://github.com/zulip/zulip/issues/693)
* <strike>[Replace the slow closure-compiler based static asset toolchain](https://github.com/zulip/zulip/issues/693)</strike>
* [Use a modern JavaScript bundler like webpack](https://github.com/zulip/zulip/issues/695)
* [Add support for building frontend features in something like React](https://github.com/zulip/zulip/issues/694)

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"nwmatcher": "1.3.6",
"phantomjs-prebuilt": "2.1.14",
"webpack-dev-server": "1.12.1",
"xmlhttprequest": "1.5.0"
"xmlhttprequest": "1.5.0",
"uglify-js": "2.7.5"
},
"scripts": {
"lint": "eslint --quiet",
Expand Down
24 changes: 0 additions & 24 deletions puppet/zulip/manifests/static_asset_compiler.pp

This file was deleted.

18 changes: 5 additions & 13 deletions tools/minify-js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,6 @@ if prev_deploy:
changed_files.add(os.path.join(STATIC_PATH, 'js/bundle.js'))

JS_SPECS = settings.JS_SPECS
CLOSURE_BINARY = '/usr/bin/closure-compiler'
if not os.path.exists(CLOSURE_BINARY):
CLOSURE_BINARY = 'tools/closure-compiler/run'
if not os.path.exists(CLOSURE_BINARY):
print("closure-compiler not installed; the Vagrant tools/provision.py installs it via apt "
"or you can manually unpack http://dl.google.com/closure-compiler/compiler-latest.zip to "
"tools/closure-compiler")
sys.exit(1)

# Where to put minified JS and source maps
MIN_DIR = os.path.join(STATIC_PATH, 'min/')
Expand Down Expand Up @@ -123,11 +115,11 @@ for js_group, filespec in six.iteritems(JS_SPECS):

# No previous deploy, or a source file has changed, or copying was
# supposed to work but failed. Thus, minify the JS anew.
# (N.B. we include STATIC_HEADER_FILE before the JavaScripts.
# This way it doesn't throw off the source map.)
cmd = '%s --language_in ECMASCRIPT5 --create_source_map %s %s %s' % (
CLOSURE_BINARY, map_file,
settings.STATIC_HEADER_FILE, ' '.join(in_files))
cmd = 'node_modules/uglify-js/bin/uglifyjs %s %s --source-map %s' % (
' '.join(in_files),
settings.UGLIFY_ARGUMENTS,
map_file)

js = subprocess.check_output(cmd, shell=True)

# Write out the JS
Expand Down
1 change: 0 additions & 1 deletion tools/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
POSTGRES_VERSION = POSTGRES_VERSION_MAP[codename]

UBUNTU_COMMON_APT_DEPENDENCIES = [
"closure-compiler",
"memcached",
"rabbitmq-server",
"redis-server",
Expand Down
1 change: 1 addition & 0 deletions zproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def get_secret(key):
'USE_WEBSOCKETS': True,
'PASSWORD_MIN_LENGTH': 6,
'PASSWORD_MIN_ZXCVBN_QUALITY': 0.4,
'UGLIFY_ARGUMENTS': "--compress sequences=5 --mangle --comments",
}

for setting_name, setting_val in six.iteritems(DEFAULT_SETTINGS):
Expand Down

0 comments on commit 99591c9

Please sign in to comment.