Skip to content
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

perf: remove zopfli to speed up webpack #10288

Merged
merged 1 commit into from
Mar 16, 2019
Merged

perf: remove zopfli to speed up webpack #10288

merged 1 commit into from
Mar 16, 2019

Conversation

nolanlawson
Copy link
Contributor

This PR removes zopfli compression, speeding up webpack compilation in production by ~7.5x (6m36s -> 0m53s).

Analysis

I did some profiling of the command:

RAILS_ENV=production bundle exec rails assets:precompile

after some digging, I found I could debug webpack using:

RAILS_ENV=production NODE_ENV=production node --inspect-brk /home/nolan/workspace/mastodon/node_modules/.bin/webpack --config /home/nolan/workspace/mastodon/config/webpack/production.js

So I took a trace. I think the screenshot speaks for itself:

Screenshot from 2019-03-15 19-00-50

Benchmark

My benchmark is the following:

rm -fr tmp/
RAILS_ENV=production bundle exec rails assets:precompile

Then I use the time command to time it.

Without the fix, this takes 6m36.437s in real time on my Dell XPS 13. With the fix, it takes 0m52.958s (~7.5x improvement).

Explanation

Zopfli outputs a very compact gzip format, but it's slow. Removing it speeds things up considerably.

Even though nginx's default gzip output may be less efficient than zopfli, I don't think it's reasonable to force every instance admin to run this command which takes a very long time. Maybe some admins aren't even using gzip – maybe they're using Brotli. They can also configure the gzip options in nginx, or run zopfli themselves.

As a future improvement, I don't think generating .gz files is even strictly necessary. Given this config, nginx should serve gzipped content no matter what – it's just that we don't necessarily control the gzip output.

@Gargron Gargron merged commit 8da5b8e into master Mar 16, 2019
@Gargron Gargron deleted the nolan/remove-zopfli branch March 16, 2019 03:02
sumito3478 pushed a commit to orphos/mastodon that referenced this pull request Mar 19, 2019
@angristan
Copy link
Contributor

angristan commented Mar 30, 2019

Thanks a lot!

hiyuki2578 pushed a commit to ProjectMyosotis/mastodon that referenced this pull request Oct 2, 2019
messenjahofchrist pushed a commit to Origin-Creative/mastodon that referenced this pull request Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants