Skip to content

Support for lazy computations - #1012

Draft
zerobias wants to merge 34 commits into
release/v24from
lazy-computations
Draft

zerobias wants to merge 34 commits into
release/v24from
lazy-computations

Conversation

@zerobias

@zerobias zerobias commented Nov 7, 2023 •

Copy link
Copy Markdown
Member

This PR implements lazy computations by building a graph of connected nodes. Each unit now has lazy metadata consisting of alwaysActive, usedBy, and activate.

  • activate — the previous nodes in the graph that need to be activated when the current node becomes active
  • usedBy — the next nodes in the graph; they make it possible to determine whether the current node is being used by anything
  • alwaysActive — a flag required for regular stores and some other units. By default, createStore() returns an always-active store

Laziness is implemented through the isUsed function in the Effector kernel, which allows unused nodes to be skipped and prevents them from being evaluated in the stack machine.

There is also an edge case where a derived store is not subscribed to, but its value is requested via getState(). To handle this case, initRef was changed so that it checks whether the derived store value is still up to date. If the stores it depends on have changed, its value is treated as stale and recomputed. For this operation, the node’s meta part is used outside of a scope, and scope.lazy is used inside a scope.

Base automatically changed from release/v23 to master November 28, 2023 13:18
@zerobias zerobias added this to the effector Neowise 24 milestone Jul 11, 2024
@movpushmov
movpushmov changed the base branch from master to release/v24 April 6, 2026 16:50
@movpushmov
movpushmov force-pushed the release/v24 branch 2 times, most recently from 600b673 to 6973b14 Compare April 6, 2026 19:57
@movpushmov
movpushmov force-pushed the lazy-computations branch 2 times, most recently from 9061327 to 4d46426 Compare April 7, 2026 18:04
@igorkamyshev
igorkamyshev marked this pull request as ready for review April 20, 2026 11:01
@igorkamyshev
igorkamyshev marked this pull request as draft April 20, 2026 11:01

This branch has not been deployed

No deployments
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.

2 participants