feat(agera): add selector to wake only the keys whose answer changed - #200
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #200 +/- ##
==========================================
+ Coverage 84.80% 84.99% +0.19%
==========================================
Files 140 140
Lines 3119 3159 +40
Branches 586 596 +10
==========================================
+ Hits 2645 2685 +40
Misses 338 338
Partials 136 136 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A keyed derivation: one subscriber on the source, one node per key, and a change delivered only to the keys whose answer moved. `selector($source)` answers whether a key equals the source value; a second argument replaces that rule with any derivation of `(key, value)`. The returned function is not a signal - it has no value of its own, and calling it inside a tracked context subscribes the caller to that key alone. Liveness matches `computed`: a mountable source stays cold under a scope read, mounts through a live key and relays through a mountable reader.
dangreen
force-pushed
the
feat/agera-selector
branch
from
August 19, 2026 10:10
d9e0197 to
dc16c53
Compare
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.
When many things ask the same question about one value — which row is selected, which tab is open, which item is dragged — a
computedper asker subscribes them all to that value. Every change then wakes all of them so that all but one can conclude that nothing changed.selectorinverts it: the source gets one subscriber, and a change reaches only the keys whose answer actually moved.Shape
One subscriber on the source, one node per key, and the change pushed to the keys that moved. The key node is the smallest thing the core can deliver to — a value and a
destroy— and it ridespropagateandunlinkuntouched: it holds a pushed value, so nothing ever recomputes it.Nothing is attached until a real subscriber asks. The tracker is warmed up by the first tracked call, and the last key to lose its readers stops it, which is what releases the source. A key that loses its last reader deletes itself from the map through
destroy, so churn does not leak.The default rule answers
key === value, which moves exactly two keys per change and never visits the rest. A second argument replaces it with any derivation of(key, value):A custom derivation has to be asked for every live key on each change — so the default stays the one to reach for.
The returned function is not a signal. It has no value of its own, and calling it inside a tracked context subscribes the caller to that key alone; called outside one, it just answers. User derivations run with the caller detached, so their reads become nobody's dependency.
Liveness
A key relays presence like a mountable computed does, in both directions:
presentwalks source → tracker → keys → readers, and a key's level change walks back down the same two edges. So amountablesource behaves under a selector exactly as it behaves under acomputed— cold under a scope read, mounted through a live key, and released when that key's last reader leaves. The tracker itself is a relay, not a reader: it is an effect, andpresenthad to learn to ask a relay's subscribers instead of stopping at itsWatchingFlag.Cost
+240 B gzip in agera. Three models were set on the region at maximum effort to squeeze it; two of them rebuilt the size-limit pipeline and measured every variant. The best no-regression stack came to −15 B and the most aggressive to −28 B, none of which moves the pin (anything above 3100 B pins at
3.15 kB), so the region ships as written. What that round did establish: the node literals are nearly free — the tracker's is 87 minified bytes but 5 B gzipped, because it is a byte-identical run witheffect()'s — and every attempt to shorten them, share them through a factory or drop a field came back bigger. The only real lever is a computed-per-key redesign at −164 B, and it costs the whole point of the primitive: O(n) propagation per change, leaked keys, and a scope read that mounts the source.Pins move up in agera, kida and store;
nanoviewspays 2 B of brotli for thepresentrelay branch, which sits on the hot path.Benchmark
examples/benchmark/nanoviewsswitches its row class from a per-rowcomputedtoselector, which is what the js-framework-benchmark app does too. On the full six-framework run that tookselect 1kfrom 14.9 ms to 9.8 ms — tied for first place with vue-vapor, where it had been 1.5× off the best.