-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR prepares the VM for a refactor toward autotracking by extracting modifiers and wrapping them in "effects". This is short for the term [side-effect](https://en.wikipedia.org/wiki/Side_effect_(computer_science)), which describes an action run within a function or computation that doesn't technically have anything to do with the _output_ of that computation. Modifiers are a form of side-effect, because they don't directly affect the output of the VM - they schedule a change that occurs _later_. This also presented a problem for autotracking, which is why I started with this PR. Autotracking operates on the premise that it is watching state used within a computation - i.e. _synchronously_. Async actions, like modifiers, violate the basic premise of autotracking. We were able to model it with Tags using UpdatableTag, which does allow this type of lazy structure, but updatable tags have been a major source of performance issues and bugs in general. Rather than having the VM be responsible for updating these async actions, the way to handle this with autotracking would be to have something _else_ handle it, specifically the place where the actual computations _occur_. This is the Effect Queue. \## How it works The VM handles registration and destruction of effects, but the environment is now responsible for updating them. Effects are scheduled to run in the same position modifiers were previously, and all effects in the queue are revalidated after each render. Ordering is also still guaranteed, in that child effects will always be triggered before parents. This is because new nodes are prepended to the tree, and thus any new children are guaranteed to run before their older parents. Due to the nature of the queue, it's possible that sibling update order could change and be unpredictable. \## Other options We could use a tree that mirrors the VM tree instead of a queue, but traversing that tree could end up being fairly expensive, especially if there are few modifiers. I opted for the simpler solution for the time being, and figured we could benchmark to see if there is a performance impact currently, and if so what solutions are better. Another option would be to make a n-ary tree that simply divides the effects up evenly in memoization chunks. This might allow us to get some wins in the general case, when most modifiers have not changed.
- Loading branch information
Chris Garrett
committed
Mar 22, 2020
1 parent
4bf27f7
commit b217e8d
Showing
12 changed files
with
299 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.