Repository navigation
Home: a key press no longer costs a late frame - key tables update in place, the catalog sync touches only changed rows, the hold band has hysteresis - #858
Merged
Conversation
…d band's hysteresis (red on main) A one-row ring step over 170 hubs rebuilds both key indexes and rewrites every element of the catalog (2270 index insertions, 2040 element-map writes against 24 for 10 hubs), and every one-row scroll sends the store a new band. Both tests fail on main; the fix follows. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… (Home and the Library) HoldBand re-sends only when the band last sent no longer covers the rows in view and their two-row margin, and then asks for two more rows each side, so a walk down a long page sends one band per two rows instead of one per press. Every row stays reachable: the band follows the view. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…e rows that changed A prune used to rebuild both key indexes from the table (every identity cloned and hashed to drop about ten keys); it now removes the entries from the table and moves the positions of the rest (registry::Compaction, shared by Home and the Library's KeyRegistry), and the identity strings are Arc<str>. sync_catalog keeps the projection, the shelf and the element-map entries of a row whose identity, title and cards (Arc::ptr_eq) or descriptor size are unchanged, so a landing that changes two of 170 rows projects two rows. The ring test now drives the store's own Hold and reload paths. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… reads it Dispatcher::state_hash walks every live instance's LogicalState, which for Home is the whole key table, so the unconditional dhash on each event frame cost 4.7-5.3 ms on the frame after every Home store landing (DEBUG-7b). Its only consumers are taps that record or grade it, so Tap gains wants_state (default false; the fixture RecTap says true) and the frame computes the hash, and sets FrameReport::state_hash, only when the tap asks. The recorder and replay hash through Dispatcher::state_hash directly and are unaffected; the debug build's section 5.4 assertion still hashes. Test: an unread hash is not computed; the prepare-does-not-change-the-hash test now uses a tap that wants it. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…tead of building it twice A row that gives its cards up publishes as many placeholders as it showed, so releasing it changes nothing about the catalog's shape. merge_held used to build the catalog, settle the ring, and build the whole catalog again whenever a row was released (every Down key that moves the band); it now overwrites the released rows' slices of the first build. settle_ring reports which rows it released, and the hero pool is lifted out and placed back (place_heroes), looking for a card at the slot it held before it scans the catalog. A test pins the patched catalog to the second merge it replaces, hero pool included. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…per tick merge_with_scope reserves the catalog, its hub rows and the per-card handle table before filling them, published_order reserves its order, and pump_reloads asks wanted_reloads for the deck offset instead of computing the published order a second time for it. catalog_bytes sizes a run of one shared placeholder once (the figure is the same), so the landing's log line no longer reads every placeholder of a released row. A host sample of the Home walk showed the last of these as the store's own share of a landing after the earlier changes. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…paction has its own test Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Closing the gaps of the dropped placeholder keys moves every key behind them in the table and in the indexes that name positions, so a publication that changed a row or two still paid for the whole table (49 of 71 sampled ms of Home's catalog sync on the host walk, nearly all of it hash probes over the placeholder slots). prune_keys now counts the keys that leave the page and sweeps the item keys when KEY_PRUNE_BATCH have, or at once when the table is over its bound; the groups (few) still go at once. A volatile key's identity carries its publication, so the keys that wait can never be named again. Tests: a ring walk sweeps once per batch, not per publication; the two tests that asked for a drop within one sync now ask for the batch bound. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…cards without collecting them A merge of 170 rows allocated a placeholder card for every released row and a vector of cards for every shelf. It now allocates one placeholder per source (every released row of the source publishes it) and filters a shelf's cards as it appends them. Rows publish the same cards. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… rows list the elements the key table now holds adopt_shows swaps element numbers between keys and restore rewrites the places they remember, both relying on the next sync to project the rows again. Since the sync keeps a row whole while its cards are the same Arcs, a remount's Continue Watching row hit that fast path and kept the elements the fresh page minted: the restored focus landed on an unrelated card whenever the next episode came back in another column, and the key table disagreed with the tile at that element from then on. Every row now carries a stale mark that invalidate_projection sets (from restore and from an adopt_shows that changed anything) and the fast paths honour. The wasted rebuild_indexes in adopt_shows is gone: swapping elements changes neither identities nor positions. The new test compares the rows, each key's remembered place and the element map with what a full projection over the same key table gives. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…nd it asked for The store keeps at most HOLD_ROWS rows of what a screen asks, cut around the middle. The band recorded what it ASKED, so Recommended's BACK to the top from rows 20..23 (the focused row 0 folded into the rows in view: an ask of rows 0..27, kept as 5..20) called rows 0..4 covered and sent nothing more as the view glided up: the top of the page stayed placeholders with no read in flight. HOLD_ROWS and clamp_hold move to a base module, hold, that the store re-exports and HoldBand applies, the way Tile lives in base because data and ui cannot name each other: one cut for every caller. The band remembers the cut of what it sent, asks again as the glide shortens the span, and does not resend a band the store would keep exactly as it keeps the one it has (a span too tall for any band). The rule the band relies on, the rows in view plus 2 * (margin + slack) fit the store's rows, is a compile-time assertion beside the constants. Tests: the shared band against a store that applies the cut, and the Library page's BACK through the real store. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…random histories, and a hub published twice keeps its second row's elements The sync's fast path and its patched element map are only right if they equal a projection from scratch; the new property test drives random publications, evict-and-remount, in-place restore and promote sequences and compares every step. The store does not rule out two hubs with one identity in a publication, so the element-map patch now falls back to a full rebuild when two rows share a group. The merge_held test also covers a second source, Continue Watching, a pin filter and a row that cannot release its cards. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…band-count bounds match the real cadence A tap reads the logical-state hash by implementing one method that is offered the hash as a thunk, so a tap can no longer implement state() and forget the separate wants_state() opt-in (the recorder would silently have written nothing). The HoldBand doc states the failed-row retry cadence (a band is sent once per HOLD_SLACK + 1 rows, so a stalled row is retried about once per three rows, not once per row), the Home comment names the margin and slack the band really asks for, KEY_PRUNE_BATCH's doc no longer claims a bound it does not keep, and the two band-count tests bound one band per three rows. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.
On the TV, every Down/Up on Home cost one late frame (about 24 ms) while scrolling a long Home. Measured with
home-grid-deep: 170 shelves, a key every 0.33 s, panel on, release build. 338 of 340 key presses produced one late frame.Cause (measured on the TV)
Each Down moved the shared hold band:
HubsCmd::Holdreleased the row that left the band and re-read the row that entered it.sync_catalogre-projected all 170 rows and 2048 items.prune_keysthen rebuilt every key index (rebuild_indexes) to drop about 10 of about 4000 keys.One instrumented TV run (every frame logged, sched trace) attributed the late frame's step:
dstep23.7 ms median:rebuild_indexes17.2 ms (73%), the drop scan 1.6, rows / elem_at / shelves 1.5 / 1.5 / 0.6.state_hashof 4.7 ms.The code came from #413, #605 and #609.
Fix (shared layers; Home and the Library both use them)
registry::Compactiondrops departed keys in place and the indexes follow. Identities areArc<str>. The item-key sweep runs once per 256 departed keys; that is a batch size, not a cap. The Library'sKeyRegistry::pruneuses the same compaction.elem_atand the key table are patched for the changed rows only, with a full rebuild if a publication ever carries two rows with one identity. A remount,adopt_showsorrestore()marks every row stale.ui::cards::HoldBand(margin 2, slack 2) re-sends the band only when the rows in view near its edge. It judges coverage against the band the store actually keeps, which isplx_base::hold::clamp_hold(HOLD_ROWS), not the band it asked for. A const assertion ties rows in view + 2×(margin+slack) toHOLD_ROWS. Every row stays reachable.state_hashis computed only for a tap that reads it. That tap is the replay recorder.Tap::state(f, hash_thunk)makes it impossible to implement one without the other.Verification
Red first:
a_ring_step_costs_the_rows_it_touches_not_the_catalog: 170 vs 10 hubs, equal index work, norebuild_indexes.the_hold_band_speaks_once_per_slack_and_never_leaves_the_view_short_of_its_margin.merge_held_equals_a_merge_of_the_settled_ring, with two sources, a deck, a pin filter and an unreleasable row.Gates on the committed tree (
git status --shortempty before and after):make checkexit 0: 29test result:lines, 18325 passed, 0 failed;103 steps — all ok; harness ok.make test-hostsimok. 931 passed; 0 failed.make check-nodefclean.make check-replay3 fixtures, 6 replays, 0 failures.TV (release build, 60 Hz, panel on, muted, mock only), 0f2687c:
home-grid-deeplibrary-recommendedlibrary-scrollHost (sim, 170 shelves): the landing-frame key step went from 3.0–3.5 ms to 0.7–0.8 ms.
One review: two blockers and four shoulds, all fixed here with tests. It also checked these and found them clean:
state_hashgate: nothing in production reads it, and idle detection does not use it;KEY_PRUNE_BATCHis not a cap on reachable content;The new
plx_base::holdmodule is registered inci/module-layers.ini. No crate, Cargo, Makefile, build.rs or workflow change, so the crate graph is unchanged and there is no build-bench table.Not in this PR
The Library's Recommended page with 170 shelves still has a per-key cost:
library-shelves-deepshowed 166 key frames with a 15 ms median step. That scene's walk also failed to enter the grid on this run. Both are being diagnosed separately. This PR does not merge until it is shown whether that failure predates the change.🤖 Generated with Claude Code