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

Consider moving from tedivm/jshrink to garfix/js-minify #34309

Open
hostep opened this issue Oct 11, 2021 · 6 comments
Open

Consider moving from tedivm/jshrink to garfix/js-minify #34309

hostep opened this issue Oct 11, 2021 · 6 comments

Comments

@hostep
Copy link
Contributor

hostep commented Oct 11, 2021

Description (*)

Consider swapping the tedivm/jshrink package with garfix/js-minify for increased performance when minifying JS

Expected behavior (*)

Faster minifying of javascript code during static content deployment

Benefits

Faster deploys

Additional information

Based on the discussion in tedious/JShrink#105, it might be worth testing this out
I haven't tested it out myself but it sounds very promissing.

@m2-assistant
Copy link

m2-assistant bot commented Oct 11, 2021

Hi @hostep. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@hostep
Copy link
Contributor Author

hostep commented Oct 25, 2021

Hmm, I just gave this a try by compiling the Magento/blank & Magento/luma themes, only in the en_US locale, and:

  • there is a slightly better compression happening, 21.099.275 bytes with garfix/js-minify vs 21.124.037 bytes with tedivm/jshrink (which is about 24 kilobytes, not bad)
  • the times to compile are slower, ~34.48 seconds with garfix/js-minify vs ~31.76 seconds with tedivm/jshrink (this is the entire SCD call, not the js minifier itself and I've used the --no-js-bundle flag)

So I'm not sure if we should proceed with swapping out these two libraries...

@hostep
Copy link
Contributor Author

hostep commented Oct 25, 2021

In case anybody wants to try this out, the only changes I did make were these ones and I executed:

$ bin/magento config:set dev/js/minify_files 1
$ bin/magento deploy:mode:set production --skip-compilation
$ rm -R var/view_preprocessed/* pub/static/*
$ bin/magento setup:static-content:deploy --no-js-bundle --theme Magento/luma en_US

Executed the last 2 commands with the original library installed and afterwards with the new library and looked at the execution times and compared the output a bit with a diff tool.
I executed this with PHP 7.4.25 natively installed (no virtual machine or docker or whatever have you these days).

@hostep
Copy link
Contributor Author

hostep commented Oct 25, 2021

Ow okay, I see, I have pcre.jit disabled to circumvent a nasty bug in the PCRE library with the JIT compiler

But when I enable it again, garfix/js-minify suddenly runs twice as fast.

See the output, both times with garfix/js-minify, only difference is the pcre.jit setting:

$ rm -R var/view_preprocessed/* pub/static/*; php -d pcre.jit=0 bin/magento setup:static-content:deploy --no-js-bundle --theme Magento/luma en_US

Deploy using quick strategy
frontend/Magento/blank/en_US            1882/1882           ============================ 100%   13 secs
frontend/Magento/luma/en_US             1898/1898           ============================ 100%   16 secs

Execution time: 36.887857913971

$ rm -R var/view_preprocessed/* pub/static/*; php -d pcre.jit=1 bin/magento setup:static-content:deploy --no-js-bundle --theme Magento/luma en_US

Deploy using quick strategy
frontend/Magento/blank/en_US            1882/1882           ============================ 100%   8 secs
frontend/Magento/luma/en_US             1898/1898           ============================ 100%   8 secs

Execution time: 18.244688987732

So this indeed sounds like a good library out of the sudden 👍

@hostep
Copy link
Contributor Author

hostep commented Oct 25, 2021

Final test results after which I'll call it a day:

### Using tedivm/jshrink

$ rm -R var/view_preprocessed/* pub/static/*; php -d pcre.jit=0 bin/magento setup:static-content:deploy --no-js-bundle --theme Magento/luma en_US

Deploy using quick strategy
frontend/Magento/blank/en_US            1882/1882           ============================ 100%   11 secs
frontend/Magento/luma/en_US             1898/1898           ============================ 100%   11 secs

Execution time: 30.361593008041


$ rm -R var/view_preprocessed/* pub/static/*; php -d pcre.jit=1 bin/magento setup:static-content:deploy --no-js-bundle --theme Magento/luma en_US

Deploy using quick strategy
frontend/Magento/blank/en_US            1882/1882           ============================ 100%   9 secs
frontend/Magento/luma/en_US             1898/1898           ============================ 100%   9 secs

Execution time: 20.288753986359



### Using garfix/js-minify

$ rm -R var/view_preprocessed/* pub/static/*; php -d pcre.jit=0 bin/magento setup:static-content:deploy --no-js-bundle --theme Magento/luma en_US

Deploy using quick strategy
frontend/Magento/blank/en_US            1882/1882           ============================ 100%   11 secs
frontend/Magento/luma/en_US             1898/1898           ============================ 100%   13 secs

Execution time: 32.813580036163


$ rm -R var/view_preprocessed/* pub/static/*; php -d pcre.jit=1 bin/magento setup:static-content:deploy --no-js-bundle --theme Magento/luma en_US

Deploy using quick strategy
frontend/Magento/blank/en_US            1882/1882           ============================ 100%   6 secs
frontend/Magento/luma/en_US             1898/1898           ============================ 100%   6 secs

Execution time: 14.330065965652

So with pcre.jit enabled, garfix/js-minify seems to win. With pcre.jit disabled tedivm/jshrink wins.

Note that all my results are each time pretty different, sometimes 2 to 4 seconds difference, which means my testing was not done properly and the test runs were only executed once instead of many times and averaged out. Also I'm on battery currently and have some other programs running in the background, all of these things probably have a certain amount of effect on the results...

@GamesmenJordan
Copy link

GamesmenJordan commented Nov 22, 2021

Side note, this also fixed an issue I had with the default minifier, some forms of IEFs like: !function(){...}(); would produce broken js files after minifying. Garfix minify handled this case without issue. For this reason alone I have swapped out the minifier in my instance.

A non-destructive way of doing this is requiring the module with composer and then using di.xml rule <preference for="JShrink\Minifier" type="Garfix\JsMinify\Minifier" />, requires no core edits and easy to reverse the change by simply removing the DI and recompiling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for Grooming
Development

No branches or pull requests

2 participants