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
v0.49.0 DCE/treeshaking regression #1592
Comments
(until rollup/rollup#1592 is resolved)
this [1] could be useful for a whitelist if you guys can assert that the property owner is a dom element. i could probably work around this (eg |
Even if Rollup does not know it's a DOM property with side effects, the property read should still be preserved in the event that the object may be undefined:
For that matter, Rollup drops globals that could throw:
|
Same problem here, here is a simple repository to reproduce the issue. |
This is really bad. Rollup was never able to handle getters properly but I think no-one noticed because tree-shaking failed for so many other reasons. The SAFE way would be to assume that any property access is actually a getter unless we are REALLY sure it is not. Basically, this would cripple the algorithm and we are back to square one 😢 HOWEVER looking at your examples @leeoniya, the way you access this getter is via calling an expression as a statement. So maybe this is something we can work with as this is something one would not usually do unless they expect an effect. @kzc Forget what I wrote, maybe even your code might be fixed by this. Let's see. |
@mjeanroy Since you are calling a constructor for side effects, your issue might be addressed by this as well. Will look into this tomorrow. |
The try/catch is not relevant to the two issues demonstrated. They were just put in there to show unambiguous test output. Uglify has an optional
Perhaps Rollup could offer something similar. |
@kzc I think you are right, this is exactly what we need. This sounds like the best way to address the issue of handling getters. However, changing the interface of rollup and introducing options like these would probably require a little more discussion, maybe we should make a separate issue for this? I would certainly offer my help in wiring this up, but right now I do not want to make possibly breaking interface decisions. |
Ok, I added my code to #1591. Let's see if this fixes your issues once it gets merged. |
Released 0.49.2 with the fix — thanks. Ultimately I think @kzc is right, we're forced to default to assuming that there are getters with side-effects everywhere. In the longer term it'd be nice to keep track of objects and properties so that this... foo = { bar: 1 };
foo.bar; ...is understood to not have side-effects. Tricky because you need to start tracing values as they flow through the program (aka the big rewrite I aborted a while back 😬), but certainly possible in many scenarios. |
I agree and I already got some ideas on how to handle this. Basically, I would not track values in a general sense but instead assignments of nodes to other nodes and really beef up what .assignedExpressions can do. But the ideas are still a little vague, for now I want to refactor call expression handling first to complete what I have started with the first refactoring (and finally add tree shaking to ClassDeclarations). |
@lukastaegert Thanks for the hard work! |
thanks @lukastaegert |
getters with side-effects is an extremely shitty pattern i have never encountered in real code. unfortunately we're stuck with the DOM api in this case. i don't think this is worth supporting generically if it makes the codebase slower and more complex. it's also highly unlikely that real code would ever have eg the implemented fix is sufficient, imo. |
Well, there is of course pixi.js–works really well, but they REALLY love their getters. |
the issue here is getters with side-effects, right? there's no problem removing getters otherwise. in the file you linked there is one getter where the comment says it "sets" [1], but the comment appears to be wrong. there's another one that may initialize a DisplayObject but it's unlikely anyone accesses that getter simply for that side-effect without using the return value. [1] https://github.com/pixijs/pixi.js/blob/dev/src/core/display/DisplayObject.js#L589 |
Rollup cannot know which getters have side effects so it has to be conservative by default. Or whether |
i understand. i'm postulating that getters with side-effects are quite rare, because they're shit pattern - no different than a function called |
Chai getters have side-effects. |
where? https://github.com/chaijs/chai/search?utf8=%E2%9C%93&q=get&type= |
Not sure where but chai is usually used like expect(value).to.be.true I assume they are creating the getters programmatically. It would certainly make chai unusable if these statements were removed. Luckily I think we got this one covered with the latest update. |
interesting. it seems linters didn't particularly appreciate this either:
right, only i stand by my previous statement that the implemented fix is sufficient, even for these oddball cases :p |
which forces a DOM repaint by accessing
offsetHeight
gets improperly culled to a noop:...and is then removed from all call sites.
probably introduced by #1582
The text was updated successfully, but these errors were encountered: