Repository navigation
Experimental next/ implementation: re-run only when a read value changed - #130
Closed
johnsoncodehk wants to merge 2 commits into
Closed
johnsoncodehk wants to merge 2 commits into
johnsoncodehk wants to merge 2 commits into
Conversation
next/index.ts exposes the same API as src/index.ts. Links remember the value read through them, and a node that may be out of date compares those values in read order instead of relying on dirty marks alone. Computeds without subscribers keep their value without being referenced by their dependencies. Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
test:next runs the suites written for src against next/index.ts, plus: - behavior: where next intentionally differs from src - bound: getter and effect call counts equal a last-run reference model - fuzz: random graphs against evaluation from scratch - chaos: throwing getters, effects and cleanups, disposal during runs Co-authored-by: Johnson Chu <johnsoncodehk@users.noreply.github.com>
|
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
next/index.ts, a from-scratch implementation with the same public API assrc/index.ts, plus tests. Nothing insrc/changes and nothing innext/is built or published.Design
One rule: a getter or effect is called again only when a value it read during its last call is different now.
Cycle detected(computeds that read themselves or each other, effects that never settle).Results against
masterCorrectness
next(200 tests).trigger): 0 failures in 300,000 cases.Getter calls (20,000 random programs)
masternextnextmatches the last-run model on every single case, not only in total. Effect runs are identical everywhere (292,687).Steady-state instructions per iteration (
node --jitlessunder cachegrind, slope between 300 and 600 iterations)masternextWall-clock with the JIT agrees in direction: -1.5% to -12% on these workloads, -28% on a batch that leaves values unchanged.
Where
nextis worsemaster, about 81 ns onnextfor a 10-deep chain.nextwalks the chain comparing values (no getter calls);masteranswers in O(1) because the chain stays subscribed. This is the cost of letting unwatched computeds be collected.Garbage collection: of 1,000 unwatched computeds that were read once and dropped,
mastercollects 0 while the source signal lives;nextcollects all 1,000.Behaviour differences from
srcnextis not a drop-in replacement.next/tests/behavior.spec.tspins each of these:Testing
pnpm run test:nextruns the existing suites againstnext/index.tstogether withnext/tests/(229 tests).pnpm run build,pnpm run checkandpnpm run testpass.pnpm run checkonly coverssrc;next/index.tswas linted separately with the same tsslint rules and is clean.The instruction-count, wall-clock, memory and GC measurements were taken with scripts that are not part of this branch.