Skip to content

perf: allow assertions to be removed in production mode #20146

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

Merged
merged 1 commit into from
Aug 21, 2020

Conversation

crisbeto
Copy link
Member

Wraps all assertions in ngDevMode checks so that they can be stripped away in production mode. Furthermore, changes all the places where we were using the old isDevMode check.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 31, 2020
@crisbeto crisbeto force-pushed the ng-dev-mode branch 2 times, most recently from cf1e243 to 8f3416b Compare July 31, 2020 13:11
@crisbeto crisbeto marked this pull request as ready for review July 31, 2020 13:59
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Jul 31, 2020
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

Overall looks good, I'll do a preliminary presubmit. FWIW, I probably would have preferred to make this change in smaller parts.

@crisbeto
Copy link
Member Author

crisbeto commented Aug 1, 2020

Changed to dev_mode_types based on the discussion.

Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

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

LGTM. One question about View Engine support.

@@ -256,7 +255,7 @@ export class CdkDropList<T = any> implements OnDestroy {
if (typeof drop === 'string') {
const correspondingDropList = CdkDropList._dropLists.find(list => list.id === drop);

if (!correspondingDropList && isDevMode()) {
if (!correspondingDropList && (typeof ngDevMode === 'undefined' || ngDevMode)) {
Copy link
Member

Choose a reason for hiding this comment

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

Does removing isDevMode() mean that View Engine apps will have warnings/errors as in dev mode? It looks like View Engine enableProdMode does not set ngDevMode at all. Maybe it should?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I assumed that it would. We would need to fix that since we still need to report these issues in ViewEngine.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe that enableProdMode doesn't set the variable, because it's supposed to be replaced during build time. I don't think that this will be an issue for ViewEngine apps, because the majority of the current checks were running in production too. We have a handful of isDevMode ones, but they're sanity checks so it wouldn't really be a problem if they ran in production. The only one that may be a problem is the theme check in the common module since it has a getComputedStyle call so I'll add an exception for it.

@crisbeto crisbeto force-pushed the ng-dev-mode branch 2 times, most recently from cbfcffc to 643217b Compare August 3, 2020 19:21
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

Caretaker note: let's be sure to test this explicitly in an internal app to make sure the warnings are still logged as expected

@jelbourn jelbourn added merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note action: merge The PR is ready for merge by the caretaker labels Aug 3, 2020
@andrewseguin andrewseguin added P2 The issue is important to a large percentage of users, with a workaround and removed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Aug 11, 2020
@jelbourn
Copy link
Member

Caretaker note: hold off on merging this until Aug 17th so we can make a heads up announcement internally

@jelbourn
Copy link
Member

@crisbeto would you mind rebasing? I want to peek at how much this reduces bundle size by

@crisbeto
Copy link
Member Author

Rebased @jelbourn. Note that the tests are going to fail now, because #20304 hasn't been merged yet.

@crisbeto
Copy link
Member Author

Re-rebased to fix the test failures.

if (drawer.position == 'end') {
if (this._end != null) {
throwMatDuplicatedDrawerError('end');
if (typeof ngDevMode === 'undefined' || ngDevMode) {
Copy link
Member

Choose a reason for hiding this comment

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

@crisbeto just noticed this one is actually gating actual behavior for the component (setting this._end or this._start)

Copy link
Member Author

Choose a reason for hiding this comment

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

ops, good catch. Fixed, although it does reveal that if we have some faulty logic, our tests won't catch it since they're only being run in dev mode.

@jelbourn
Copy link
Member

Also I tested our internal component gallery app with this and it reduced the production bundle size by 4620 bytes.

@crisbeto crisbeto force-pushed the ng-dev-mode branch 2 times, most recently from ac96786 to 1ea40c8 Compare August 19, 2020 19:19
Wraps all assertions in `ngDevMode` checks so that they can be stripped away in production mode. Furthermore, changes all the places where we were using the old `isDevMode` check.
@wagnermaciel wagnermaciel added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Aug 21, 2020
@wagnermaciel wagnermaciel merged commit 79e4d28 into angular:master Aug 21, 2020
@angular-automatic-lock-bot
Copy link

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 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note P2 The issue is important to a large percentage of users, with a workaround target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants