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): decouple effects from change detection #51049

Closed

Conversation

alxhub
Copy link
Member

@alxhub alxhub commented Jul 15, 2023

Previously effects were queued as they became dirty, and this queue was flushed at various checkpoints during the change detection cycle. The result was that change detection was the effect runner, and without executing CD, effects would not execute. This leads a particular tradeoff:

  • effects are subject to unidirectional data flow (bad for dx)
  • effects don't cause a new round of CD (good/bad depending on use case)
  • effects can be used to implement control flow efficiently (desirable)

This commit changes the scheduling mechanism. Effects are now scheduled via the microtask queue. This changes the tradeoffs:

  • effects are no longer limited by unidirectional data flow (easy dx)
  • effects registered in the Angular zone will trigger CD after they run (same as Promise.resolve really)
  • the public effect() type of effect probably isn't a good building block for our built-in control flow, and we'll need a new internal abstraction.

As effect() is in developer preview, changing the execution timing is not considered breaking even though it may impact current users.

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.

Excellent start @alxhub !

I've left some comments as discussion points, let's catch up on those.

packages/core/test/render3/reactivity_spec.ts Outdated Show resolved Hide resolved
packages/core/src/render3/reactivity/effect.ts Outdated Show resolved Hide resolved
@jessicajaniuk jessicajaniuk added the area: core Issues related to the framework runtime label Jul 17, 2023
@ngbot ngbot bot added this to the Backlog milestone Jul 17, 2023
@e-oz
Copy link

e-oz commented Aug 23, 2023

oh oh, not merged into 17.next.1 😿

@alxhub alxhub force-pushed the fw/reactivity/effect-timing-update branch 2 times, most recently from 5679430 to f1a9ece Compare August 25, 2023 00:26
@alxhub alxhub added the target: patch This PR is targeted for the next patch release label Aug 25, 2023
@alxhub alxhub force-pushed the fw/reactivity/effect-timing-update branch from f1a9ece to 29244a6 Compare August 25, 2023 00:30
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!

@alxhub alxhub force-pushed the fw/reactivity/effect-timing-update branch from 29244a6 to 5d5f2c7 Compare August 31, 2023 23:08
@alxhub alxhub force-pushed the fw/reactivity/effect-timing-update branch from 5d5f2c7 to 743f454 Compare August 31, 2023 23:33
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
Reviewed-for: fw-core

Copy link
Contributor

@jessicajaniuk jessicajaniuk 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: public-api

Previously effects were queued as they became dirty, and this queue was
flushed at various checkpoints during the change detection cycle. The result
was that change detection _was_ the effect runner, and without executing CD,
effects would not execute. This leads a particular tradeoff:

* effects are subject to unidirectional data flow (bad for dx)
* effects don't cause a new round of CD (good/bad depending on use case)
* effects can be used to implement control flow efficiently (desirable)

This commit changes the scheduling mechanism. Effects are now scheduled via
the microtask queue. This changes the tradeoffs:

* effects are no longer limited by unidirectional data flow (easy dx)
* effects registered in the Angular zone will trigger CD after they run
  (same as `Promise.resolve` really)
* the public `effect()` type of effect probably isn't a good building block
  for our built-in control flow, and we'll need a new internal abstraction.

As `effect()` is in developer preview, changing the execution timing is not
considered breaking even though it may impact current users.
@alxhub alxhub force-pushed the fw/reactivity/effect-timing-update branch from d5b4271 to 6119bbc Compare September 11, 2023 19:22
@alxhub alxhub added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Sep 11, 2023
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.

Reviewed-for: public-api

@AndrewKushnir AndrewKushnir 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 Sep 11, 2023
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: public-api
Reviewed-for: fw-core

@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit 38c9f08.

@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 13, 2023
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
Previously effects were queued as they became dirty, and this queue was
flushed at various checkpoints during the change detection cycle. The result
was that change detection _was_ the effect runner, and without executing CD,
effects would not execute. This leads a particular tradeoff:

* effects are subject to unidirectional data flow (bad for dx)
* effects don't cause a new round of CD (good/bad depending on use case)
* effects can be used to implement control flow efficiently (desirable)

This commit changes the scheduling mechanism. Effects are now scheduled via
the microtask queue. This changes the tradeoffs:

* effects are no longer limited by unidirectional data flow (easy dx)
* effects registered in the Angular zone will trigger CD after they run
  (same as `Promise.resolve` really)
* the public `effect()` type of effect probably isn't a good building block
  for our built-in control flow, and we'll need a new internal abstraction.

As `effect()` is in developer preview, changing the execution timing is not
considered breaking even though it may impact current users.

PR Close angular#51049
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: core Issues related to the framework runtime merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note 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

8 participants