-
-
Notifications
You must be signed in to change notification settings - Fork 926
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
disable Terser's "reduce_funcs" option for performance #3000
Conversation
Terser's “compress” option seems to degrade performance. So, disable it. This commit will increase file size by about 1%, but performance appears to improve.
I'm 90% sure it's related to the fact Terser inlines larger functions by creating IIFEs it doesn't proceed to flatten. Better would be finding the offending function(s) and either inlining it manually (if it's easy) or marking it with This isn't a merge blocker, though. |
scripts/bundler.js
Outdated
@@ -42,7 +42,8 @@ async function build() { | |||
return | |||
} | |||
console.log("minifying...") | |||
const minified = Terser.minify(original) | |||
// Terser's “compress” option seems to degrade performance. So, disable it. | |||
const minified = Terser.minify(original, {compress: false, mangle: true}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you see if just disabling reduce_funcs
helps, and keeping the rest of compression on? terser/terser#1305 among others are related.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried the following setting where only reduce_funcs
is false, but the output result seems to be the same as in v2.2.11...
const minified = Terser.minify(original, {compress: {reduce_funcs: false}, mangle: true})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that a newer version of terser works well with reduce_funcs: false
and produces output that is both small file size and performance. However, installing a newer version of terser seems to install packages that do not support node v18.
@dead-claudia Thank you for your review comments. |
@dead-claudia |
19ee8ed
to
c5f00b7
Compare
Terser's “reduce_funcs” option seems to degrade performance. So, disable it. This commit will increase file size of "mithril.min.js" slightly, but performance appears to improve.
Description
This PR makes mithril.js and mithril.min.js code equivalent (except mangling) by disabling Terser's “compress” option.This will increase the file size of “mithirl.min.js” by about 0.01KB (gzipped), but seems to improve performance.
Edit: The code in mithril.js and mithril.min.js is not equivalent because only reduce_funcs is disabled.
results of
npm run perf
(nodejs, using mithril.min.js)Motivation and Context
While measuring performance under various conditions, I noticed the performance was different between "mithril.min.js" and "mithril.js" ("mithril.min.js" seems slower).
Looking into the cause, I found that compressing the code with Terser's “compress” option seemed to affect performance as well as it reduced the amount of code.
I use mithril.min.js as is for prototyping, so I prefer mithril.min.js to be faster.
How Has This Been Tested?
npm run test
Types of changes
Checklist