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

refactor(core): Async tagging zone dev #47416

Closed

Conversation

JiaLiPassion
Copy link
Contributor

  1. Remove zone-async-tagging implementation from zone.js and move the
    implementation to @angular/core, so @angular/core can import this
    package more easily for better treeshaking.
  2. Add async tagging zone implemenation into @angular/core package.
    So we don't need to get the AsyncStackTaggingZoneSpec from global
    instance, we can import the class directly for better treeshaking.
  3. Only load this ZoneSpec when ngDevMode is true.

@JiaLiPassion JiaLiPassion added area: zones target: major This PR is targeted for the next major release area: devtools labels Sep 13, 2022
@ngbot ngbot bot modified the milestone: Backlog Sep 13, 2022
@JiaLiPassion JiaLiPassion added target: minor This PR is targeted for the next minor release and removed target: major This PR is targeted for the next major release labels Sep 13, 2022
Copy link
Contributor

@dgp1130 dgp1130 left a comment

Choose a reason for hiding this comment

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

Overall LGTM.

One implementation nit is to consider doing this in one commit so this change is very clearly a move from zone.js to @angular/core, instead of a delete and add across two commits.

Two trade offs are being made here which I want to be explicit about:

  1. Moving AsyncStackTaggingZoneSpec into @angular/core means that other users of Zone can't get this debugging benefit. zone.js is experimental I think and not recommended or widely used outside of Angular, so maybe we're just ok with that.
  2. This change presents a required runtime dependency on Zone.js in Angular dev builds, which might cause trouble with users who run Angular without Zones.
    • AsyncStackTaggingZoneSpec will always be tree shaken in prod mode, so it's not an issue there, but in dev mode it will be retained.
    • Technically @angular/core already has a required peer dep on zone.js according to package.json, but that's easy to ignore. With this change, I think it would be a hard error to not have a zone.js peer dep.
    • Do we understand the runtime impact of importing AsyncStackTaggingZoneSpec without the rest of zone.js?
    • If the runtime impact is a problem, then in google3 I think we'd need a patch to tree shake AsyncStackTaggingZoneSpec usage out for zoneless use cases. I'm less certain of our options in the CLI without moving the import to polyfills.ts or environments.ts.

As long as we are ok with 1. and can make sure zoneless apps work in a reasonable fashion for 2., then I'm good with this change.

@JiaLiPassion
Copy link
Contributor Author

@dgp1130 , thank you for the review, I will make this PR into a single commit.

  1. Yeah, I don't think there are a lot of zone.js user outside the Angular ecosystem, maybe it is ok.
  2. I also considered about this one,
  • Since async-stack-tagging is just a class, it doesn't require zone.js, even zone.js is not loaded(such as noop zone case) it will still work without issues.
  • To use NgZone,
    if (typeof Zone == 'undefined') {
    , import zone.js is required, so add the AsyncStackTaggingZoneSpec will not add any additional requirement for zone.js.
  • And just like you mentioned, in prod mode, it will be tree shaken.

@JiaLiPassion JiaLiPassion force-pushed the async-tagging-zone-dev branch 2 times, most recently from 8c9510a to 64e08ba Compare September 15, 2022 06:15
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 for dev-infra .bzl

Copy link
Contributor

@dgp1130 dgp1130 left a comment

Choose a reason for hiding this comment

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

SGTM @JiaLiPassion, thanks for clarifying the runtime impact for Zoneless users.

@jelbourn jelbourn requested review from AndrewKushnir and removed request for alxhub September 15, 2022 22:23
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

LGTM, just a couple minor comments.

packages/core/src/zone/async-stack-tagging.ts Outdated Show resolved Hide resolved
packages/core/src/zone/ng_zone.ts Show resolved Hide resolved
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

@JiaLiPassion thanks for addressing the feedback! Just left a tiny comment about the any type.

let ret;
if (task.consoleTask) {
ret = task.consoleTask.run(() => delegate.invokeTask(targetZone, task, applyThis, applyArgs));
ret = (task as any)
Copy link
Contributor

Choose a reason for hiding this comment

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

@JiaLiPassion do we still need as any here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AndrewKushnir , thank you, forget this one, just updated and remove this any.

1. Remove `zone-async-tagging` implementation from zone.js and move the
implementation to `@angular/core`, so `@angular/core` can import this
package more easily for better treeshaking.
2. Add `async tagging zone` implemenation into `@angular/core` package.
So we don't need to get the `AsyncStackTaggingZoneSpec` from `global`
instance, we can import the `class` directly for better treeshaking.
3. Only load this ZoneSpec when `ngDevMode` is `true`.
@JiaLiPassion JiaLiPassion added the action: merge The PR is ready for merge by the caretaker label Sep 20, 2022
@pkozlowski-opensource pkozlowski-opensource added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: merge The PR is ready for merge by the caretaker labels Sep 20, 2022
Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

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

LGTM

Reviewed-for: size-tracking

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

Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

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

Reviewed-for: global-approvers

@alxhub alxhub added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 23, 2022
@alxhub
Copy link
Member

alxhub commented Sep 23, 2022

This PR was merged into the repository by commit 8637253.

@alxhub alxhub closed this in 8637253 Sep 23, 2022
sonukapoor pushed a commit to sonukapoor/angular that referenced this pull request Sep 27, 2022
)

1. Remove `zone-async-tagging` implementation from zone.js and move the
implementation to `@angular/core`, so `@angular/core` can import this
package more easily for better treeshaking.
2. Add `async tagging zone` implemenation into `@angular/core` package.
So we don't need to get the `AsyncStackTaggingZoneSpec` from `global`
instance, we can import the `class` directly for better treeshaking.
3. Only load this ZoneSpec when `ngDevMode` is `true`.

PR Close angular#47416
@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 Oct 24, 2022
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 area: devtools area: zones target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants