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

Only selectively deoptimize call parameters #4892

Merged
merged 14 commits into from
Mar 9, 2023

Conversation

lukastaegert
Copy link
Member

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

Before, any call to a function would deoptimize all call parameters meaning that they become "unknown", even if the function was pure.

This PR changes the logic to actually track what mutations happen with a function parameter and apply only the corresponding deoptimizations to the call parameters.
There are some limitations as the initial naive implementation had terrible performance: Deoptimizations are only tracked one level deep. If a nested property is reassigned, i.e.

function foo(arg) {
  arg.a.b = 'mutated'
}

then this is treated as if the top-level property, i.e. arg.a, was reassigned instead. This also applies to property accesses because we do not track if deeper properties are setters/getters. So in the example, just the line arg.a.b would deoptimize arg.a.

But I think this should be good enough for most purposes and is already a huge improvement over the previous "deoptimize everything" approach.

I also applied this optimization to known global functions: Now all known global functions except Object.freeze, Object.defineProperty and Object.defineProperties employ this logic and no longer deoptimize their arguments.

@netlify
Copy link

netlify bot commented Mar 5, 2023

Deploy Preview for rollupjs ready!

Name Link
🔨 Latest commit e69c628
🔍 Latest deploy log https://app.netlify.com/sites/rollupjs/deploys/6405ba3993be4700085ae6ef
😎 Deploy Preview https://deploy-preview-4892--rollupjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Mar 5, 2023

Thank you for your contribution! ❤️

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

npm install rollup/rollup#selective-parameter-deoptimization

or load it into the REPL:
https://deploy-preview-4892--rollupjs.netlify.app/repl/?pr=4892

@codecov
Copy link

codecov bot commented Mar 5, 2023

Codecov Report

Merging #4892 (7a17845) into master (d985838) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #4892      +/-   ##
==========================================
+ Coverage   98.98%   99.01%   +0.03%     
==========================================
  Files         219      221       +2     
  Lines        7968     8025      +57     
  Branches     2194     2209      +15     
==========================================
+ Hits         7887     7946      +59     
  Misses         26       26              
+ Partials       55       53       -2     
Impacted Files Coverage Δ
src/ast/NodeInteractions.ts 100.00% <ø> (ø)
src/ast/nodes/Literal.ts 100.00% <ø> (ø)
src/ast/nodes/TemplateLiteral.ts 100.00% <ø> (ø)
src/ast/scopes/BlockScope.ts 100.00% <ø> (ø)
src/ast/scopes/CatchScope.ts 100.00% <ø> (ø)
src/ast/scopes/Scope.ts 84.61% <ø> (ø)
src/ast/scopes/TrackingScope.ts 100.00% <ø> (ø)
src/ast/nodes/ArrayExpression.ts 100.00% <100.00%> (ø)
src/ast/nodes/CallExpression.ts 100.00% <100.00%> (ø)
src/ast/nodes/ConditionalExpression.ts 100.00% <100.00%> (ø)
... and 30 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@lukastaegert lukastaegert force-pushed the selective-parameter-deoptimization branch 2 times, most recently from 2cb3c8a to e69c628 Compare March 6, 2023 10:02
@lukastaegert lukastaegert force-pushed the selective-parameter-deoptimization branch from e69c628 to ea44dcb Compare March 9, 2023 07:11
@lukastaegert
Copy link
Member Author

I tested this on several larger projects and both performance and output seem to be fine. Will release this soon.

@lukastaegert lukastaegert force-pushed the selective-parameter-deoptimization branch from 5020c98 to 7a17845 Compare March 9, 2023 18:45
@lukastaegert lukastaegert merged commit cff3bbc into master Mar 9, 2023
@lukastaegert lukastaegert deleted the selective-parameter-deoptimization branch March 9, 2023 18:57
@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.19.0. You can test it via npm install rollup.

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.

Simple reproductible issue with treeshaking
2 participants