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

Remove side effect exports #4261

Merged
merged 18 commits into from
Aug 3, 2016
Merged

Conversation

jridgewell
Copy link
Contributor

@jridgewell jridgewell commented Jul 28, 2016

It seems Closure compiler can't DCE (notice timer, platform, and log are still in the compiled code -- We expect them to be gone since they're never called -- exports that are a side-effect. Side effects exports are the result of some function call, either a CallExpression (normal function call) or a NewExpression (creating a new instance of a "class" function).

This is breaking the SW especially, since there are references to the window variable, which is undeclared inside the SW environment.

So, let's change these side-effects into runtime side-effects (vs static compile-time side-effects). That way, closure can properly DCE.

TODO:

@erwinmombay is nice enough to look into updating our dev.assert() optimization to work with the new dev().assert() syntax. After that, I'll be able to post size diffs.

@dvoytenko
Copy link
Contributor

@jridgewell @erwinmombay Can we confirm that new form gets DCE'd?

@jridgewell timer.js will need to be refactored into timer-impl.js/timer.js pattern. Otherwise now only core's instance ever gets installed, but code is deployed in all extensions. It'd be fine if it's done in a separate PR, of course.

710.5 kB | 140.48 kB | 44.05 kB | shadow-v0.js / amp-shadow.js
787 B | 406 B | sw.js
83.97 kB | 19.54 kB | sw.max.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add normalizeRow(rows, 'sw.js', 'sw.max.js', true);
here https://github.com/ampproject/amphtml/blob/master/build-system/tasks/size.js#L98

will fix this bug, currently it doesn't automatically relate these two files together since it isnt under extensions and our other top level files don't all follow the .max convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the changes.

@erwinmombay
Copy link
Member

erwinmombay commented Jul 29, 2016

@dvoytenko @jridgewell confirmed the DCE is working with the compilerpass changes, all sizes are back or close to a 1kb +/- off from the one on master c69c82f

@jridgewell jridgewell force-pushed the side-effect-dce branch 2 times, most recently from be4a8ed to 3c5b11a Compare July 29, 2016 16:54
@jridgewell
Copy link
Contributor Author

I think everything's within .1kb of what it was. Some things, like a4a, went down 2kb.

@@ -29,6 +29,9 @@ export class Timer {
* @param {!Window} win
*/
constructor(win) {
if (!win || !win.setTimeout) {
throw new Error('Fuck you');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lmao

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are really starting to get on my nerves.

@jridgewell
Copy link
Contributor Author

timer.js will need to be refactored into timer-impl.js/timer.js pattern.

#4329

@jridgewell
Copy link
Contributor Author

PTAL

@dvoytenko
Copy link
Contributor

LgTm

@jridgewell jridgewell merged commit fe63400 into ampproject:master Aug 3, 2016
@jridgewell jridgewell deleted the side-effect-dce branch August 3, 2016 22:35
jridgewell added a commit to jridgewell/amphtml that referenced this pull request Aug 4, 2016
jridgewell added a commit that referenced this pull request Aug 4, 2016
ariangibson pushed a commit to Mixpo/amphtml that referenced this pull request Sep 7, 2016
* Do not export a side effect

Side effects can’t be DCE’d.

* Fix side effect in Performance

* Remove platform side effect

* Remove Timer#now

* eliminate dev().assert() and dev().fine() calls from src/log.js module

* Fix timer side effect

* Fix Log side effect

* Fix tests - part 1

* These damn tests

* Fix service worker tests

* Fix Analytics tests

* Linting

* Fix error

* Fix Signin

* fixes

* Disable test

* Disable check-types

* Fix merge
ariangibson pushed a commit to Mixpo/amphtml that referenced this pull request Sep 7, 2016
mityaha pushed a commit to ooyala/amphtml that referenced this pull request Nov 30, 2016
* Do not export a side effect

Side effects can’t be DCE’d.

* Fix side effect in Performance

* Remove platform side effect

* Remove Timer#now

* eliminate dev().assert() and dev().fine() calls from src/log.js module

* Fix timer side effect

* Fix Log side effect

* Fix tests - part 1

* These damn tests

* Fix service worker tests

* Fix Analytics tests

* Linting

* Fix error

* Fix Signin

* fixes

* Disable test

* Disable check-types

* Fix merge
mityaha pushed a commit to ooyala/amphtml that referenced this pull request Nov 30, 2016
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.

3 participants