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

Do not make Object.defineProperty/ies a side effect by default #4492

Closed
wants to merge 1 commit into from

Conversation

lukastaegert
Copy link
Member

@lukastaegert lukastaegert commented May 8, 2022

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

This was spawned from the same discussion https://twitter.com/pschroen/status/1522269915864256512?s=20&t=8igcqT2KuKkLKgGP3hjvVA as #4489 and will improve tree-shaking by only considering Object.defineProperty and Object.defineProperties side effects if the target object is used. Their presence will still deoptimize the object in question, though.
This is not entirely correct in so far as those two functions can throw e.g. when incorrect parameters are used ore when try to redefine a non-configurable property. I think this is acceptable as when this is actually critical, it will likely be wrapped in a try-catch, in which case Rollup will deoptimize and include the statement anyway.

https://rollupjs.org/repl/?pr=4492&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmV4cG9ydCUyMGNvbnN0JTIwZm9vJTIwJTNEJTIwJTdCJTdEJTNCJTVDbiUyRiUyRiUyMFRoaXMlMjB3aWxsJTIwYmUlMjBpbmNsdWRlZCUyMGJlY2F1c2UlMjBmb28lMjBpcyUyMGV4cG9zZWQlNUNuT2JqZWN0LmRlZmluZVByb3BlcnR5KGZvbyUyQyUyMCdmb28nJTJDJTIwJTdCdmFsdWUlM0ElMjB0cnVlJTdEKSUzQiU1Q25PYmplY3QuZGVmaW5lUHJvcGVydGllcyhmb28lMkMlMjAlN0IlMjBiYXIlM0ElMjAlN0J2YWx1ZSUzQSUyMHRydWUlN0QlN0QpJTNCJTVDbiU1Q24lMkYlMkYlMjBUaGlzJTIwd2lsbCUyMGJlJTIwbm90JTIwYmUlMjBpbmNsdWRlZCU1Q25jb25zdCUyMGJhciUyMCUzRCUyMCU3QiU3RCUzQiU1Q25PYmplY3QuZGVmaW5lUHJvcGVydHkoYmFyJTJDJTIwJ2ZvbyclMkMlMjAlN0J2YWx1ZSUzQSUyMHRydWUlN0QpJTNCJTVDbk9iamVjdC5kZWZpbmVQcm9wZXJ0aWVzKGJhciUyQyUyMCU3QiUyMGJhciUzQSUyMCU3QnZhbHVlJTNBJTIwdHJ1ZSU3RCU3RCklM0IlMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlMjJmb3JtYXQlMjIlM0ElMjJlcyUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE

@github-actions
Copy link

github-actions bot commented May 8, 2022

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#tree-shake-object-define-properties

or load it into the REPL:
https://rollupjs.org/repl/?pr=4492

@codecov
Copy link

codecov bot commented May 8, 2022

Codecov Report

Merging #4492 (4dac40c) into master (8c6e0f3) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #4492   +/-   ##
=======================================
  Coverage   98.72%   98.72%           
=======================================
  Files         206      206           
  Lines        7351     7352    +1     
  Branches     2086     2087    +1     
=======================================
+ Hits         7257     7258    +1     
  Misses         34       34           
  Partials       60       60           
Impacted Files Coverage Δ
src/ast/nodes/Identifier.ts 100.00% <ø> (ø)
src/ast/nodes/shared/Expression.ts 100.00% <ø> (ø)
src/ast/variables/LocalVariable.ts 93.15% <ø> (ø)
src/ast/variables/ThisVariable.ts 100.00% <ø> (ø)
src/ast/nodes/ArrayExpression.ts 100.00% <100.00%> (ø)
src/ast/nodes/ObjectExpression.ts 100.00% <100.00%> (ø)
src/ast/nodes/shared/ClassNode.ts 100.00% <100.00%> (ø)
src/ast/nodes/shared/ObjectEntity.ts 100.00% <100.00%> (ø)
src/ast/nodes/shared/knownGlobals.ts 90.47% <100.00%> (-1.53%) ⬇️
src/ast/variables/GlobalVariable.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c6e0f3...4dac40c. Read the comment docs.

@pschroen
Copy link

pschroen commented May 8, 2022

Confirmed to be working locally with rollup/rollup#tree-shake-object-define-properties and my test bundle.

With regards to mrdoob/three.js#24006 this one change alone has made a huge difference, reducing the total size down to 662 KB (uncompressed), that's a savings of ~34%! 🎉

@lukastaegert
Copy link
Member Author

Superseded by #4493

@lukastaegert lukastaegert deleted the tree-shake-object-define-properties branch May 11, 2022 04:31
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

2 participants