-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
Basic support for advanced (property-mangling) minify #29260
base: dev
Are you sure you want to change the base?
Conversation
Ref: issue mrdoob#29210 This change is an attempt to support property-mangling minify in three.js. Where obj[str] syntax is used, the object properties must all consistently use string syntax rather than dot syntax to avoid being broken by property mangling. These changes ought to be a no-op and have no impact on any usage other than making property-mangling minify work better, since when not using property mangling, there is no meaningful difference between dot and string syntax for object properties.
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
@Mugen87 Do you see any issues with this change? |
Basically no but I always wondering if updating the code base to fix such issues is the right step. To me, the minify tool would be the better place for a fix. |
I'm OK with the changes, no objection! These requirements have been in Closure Compiler for a long time, if I remember correctly. I am worried that it will be difficult to avoid regressions in future versions though, since we don't use these compilers ourselves and ESLint can't detect the problem, so it's hard to make guarantees about future compatibility. |
This is possible by using lists of property names to not change (Closure Compiler calls these "externs"). There are two downsides with this though: firstly those names are globally prevented from renaming, so for example if the name
If nobody cares about property mangling other than us, I'm happy to maintain it and submit fixes if we notice it break. Most likely we will do incremental updates on this to cover just the parts of the codebase we need and maintain them if anything stops working with property mangling. And if things stop working with property mangling, all it means is something used dot syntax instead of string syntax, and that doesn't affect anyone else, so the impact of any regressions should be strictly limited to property mangling. |
Hmm... Do you know what kind of saving are we talking about here? How many kb? And what % of that is relative to the whole game package? |
Using UglifyJS:
So advanced brings the script size down a further 33% (and 17% zipped) relative to simple minify. Closure Compiler does better, but it has dead code elimination in advanced mode and the file size is so much smaller I suspect it just deleted a lot of code as it was just fed a library script on its own (which I suppose is therefore entirely dead code). So the above figures should be seen as a baseline that Closure Compiler would probably beat. FWIW advanced mode also provides stronger protection against reverse engineering which is important for Construct developers. |
Related issue: #29210
Description
This PR is an attempt to support property-mangling minify in three.js. Where obj[str] syntax is used, the object properties must all consistently use string syntax rather than dot syntax to avoid being broken by property mangling. These changes ought to be a no-op and have no impact on any usage other than making property-mangling minify work better, since when not using property mangling, there is no meaningful difference between dot and string syntax for object properties.
This change does not provide full support for property-mangling across the entire three.js codebase. In testing this shows that the core does have support for property mangling. However it still fails with some other modules, such as
GLTFLoader
- it looks like the next big problem is that this and a few other parts of the codebase rely on parsing JSON. As the property names loaded from JSON must all be preserved, they must all also be updated to use string syntax. This looks like a bigger and more complex change, but can probably be done in a follow-up. Meanwhile this PR is a significant step towards supporting property mangling in three.js, and it should not have any negative impact on anything else.