Skip to content

fix(core): remove all toplevel property accesses - #30239

Closed
filipesilva wants to merge 5 commits into
angular:masterfrom
filipesilva:no-toplevel-prop-access
Closed

filipesilva wants to merge 5 commits into
angular:masterfrom
filipesilva:no-toplevel-prop-access

Conversation

@filipesilva

@filipesilva filipesilva commented May 2, 2019 •

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Followup to angular/angular-cli#14316

@mary-poppins

Copy link
Copy Markdown

You can preview 81f4228 at https://pr30239-81f4228.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview 2b5a2a3 at https://pr30239-2b5a2a3.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview 19f7a04 at https://pr30239-19f7a04.ngbuilds.io/.

"uncompressed": {
"runtime": 1497,
"main": 164945,
"main": 166696,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Vaguely surprised this went up a bit. I guess it's because of how the IIFEs increase code, especially when transpiled to ES5.

For instance

// original
const CORE_TOKENS = {
    'ApplicationRef': ApplicationRef,
    'NgZone': NgZone,
};
// transpiled
var CORE_TOKENS = {
    'ApplicationRef': ApplicationRef,
    'NgZone': NgZone,
};

versus

// modified with IIFE
const CORE_TOKENS = (() => ({
  'ApplicationRef': 'ApplicationRef',
  'NgZone': 'NgZone',
}))();
// transpiled
var CORE_TOKENS = (function () { return ({
    'ApplicationRef': 'ApplicationRef',
    'NgZone': 'NgZone',
}); })();

*/
// It's ok to access a property on Promise because it's a native global.
// tslint:disable-next-line:no-toplevel-property-access
const _CLEAN_PROMISE = Promise.resolve(null);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The tslint rule should ignore known globals, or even have a ignore list.

(() => ({
'ɵɵdefineBase': r3.ɵɵdefineBase,
'ɵɵdefineComponent': r3.ɵɵdefineComponent,
'ɵɵdefineDirective': r3.ɵɵdefineDirective,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This map strikes me as worrisome. Won't everything be retained if angularCoreEnv is used anywhere?

"name": "FLAGS"
},
{
"name": "FactoryPrototype"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like this was being retained unnecessarily.

@mary-poppins

Copy link
Copy Markdown

You can preview 71e1a02 at https://pr30239-71e1a02.ngbuilds.io/.

*/

import * as core from '@angular/core';
import {APP_INITIALIZER, ApplicationRef, DebugNode, NgProbeToken, NgZone, Optional, Provider, getDebugNode} from '@angular/core';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure why this file was importing core as a namespace.

*/
// It's ok to access a property on Promise because it's a native global.
// tslint:disable-next-line:no-toplevel-property-access
const _CLEAN_PROMISE = Promise.resolve(null);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's also a few of these global resolved promises just hanging around, they all seem the same.

@mary-poppins

Copy link
Copy Markdown

You can preview 56b96e8 at https://pr30239-56b96e8.ngbuilds.io/.

@filipesilva

filipesilva commented May 2, 2019 •

Copy link
Copy Markdown
Contributor Author

The TSLint rule identified some toplevel prop access on rxjs too, that I changed in https://github.com/filipesilva/rxjs/commit/4041f950dfd64e03623a69e14c67f79d353902ea, built and published to github as https://github.com/filipesilva/rxjs-6.4.0-without-toplevel-prop-assignment

"name": "EMPTY_OBJ"
},
{
"name": "EmptyErrorImpl"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mary-poppins

Copy link
Copy Markdown

You can preview 3888998 at https://pr30239-3888998.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview 1a116a9 at https://pr30239-1a116a9.ngbuilds.io/.

@filipesilva

Copy link
Copy Markdown
Contributor Author

With the last commit, the one that uses sed to add pure_getters: false to the CLI (undoing angular/angular-cli#14287), we see this error on the cli-hello-world-ivy-minimal integration test:

Commit 1a116a901ecf9adab58d36b22cd1ecf698955e6c uncompressed main exceeded expected size by >1% (expected: 14487, actual: 14717).

This is still an increase of ~2.5k, but much less than the ~14k increase we saw before.

@kzc

kzc commented May 2, 2019

Copy link
Copy Markdown

exceeded expected size by >1% (expected: 14487, actual: 14717).

This is still an increase of ~2.5k, but much less than the ~14k increase we saw before.

Isn't it an increase of 230 bytes, or 1.6%?

@filipesilva

Copy link
Copy Markdown
Contributor Author

@kzc only if count it correctly, which I didn't :D

Thanks for noticing that!

@kara kara added area: core Issues related to the framework runtime comp: ivy labels May 6, 2019
@ngbot ngbot Bot added this to the needsTriage milestone May 6, 2019
@mary-poppins

Copy link
Copy Markdown

You can preview 1f1a835 at https://pr30239-1f1a835.ngbuilds.io/.

@mary-poppins

Copy link
Copy Markdown

You can preview d216abb at https://pr30239-d216abb.ngbuilds.io/.

@filipesilva

Copy link
Copy Markdown
Contributor Author

Closing this PR as is to keep the comments and experiment results. #29329 will include this PR and in-repo tests to validate the changes work.

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: core Issues related to the framework runtime cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants