feat(undo): byte budget, meta-only eviction, compaction (PR11 part 1) - #292
Merged
Conversation
Bounds the on-mode delta chain's growth (memory, disk, and boot replay), replacing PR10's eager fold-into-base with the deferred foldedIds model from the plan. - Eviction is meta-only: TileShadow moves the oldest active entries into a `folded` list (no pixel work) while the window is over MAX_UNDO count OR the byte budget (min(32MB, storage.estimate().quota / 20), sized at boot). It keeps at least one active entry, so a user at the stack bottom overshoots transiently, never losing the entry they just made. After a commit the pointer sits at the tip, so eviction only ever folds entries strictly below it. - Compaction: once `folded` passes 30, one enqueued step bakes every folded entry into the base (the deferred cost) and bumps the base version. The store rewrites the base and deletes the folded rows in the same tx, so it never holds folded rows without a base to anchor them. - Reconstruction / serialize / hydrate apply base + folded + active, so boot replays the folded rows and stays exact across a compaction boundary. - Store: meta2 gains `foldedIds`; folded + active share one `entry:<id>` row namespace tracked by `savedRowIds`. A pre-PR11 meta2 (no foldedIds) still loads, with an empty folded list. Tests: fold/pointer-remap, byte-budget eviction, compaction state-equivalence, undo/redo-after-eviction, foldedIds store round-trip, compaction-tx (base rewrite + folded-row delete), and a 500-stroke soak that stays under budget + the folded cap while reconstructing exactly. Live tiled-boot.mjs gains an eviction phase (folded rows round-trip through IDB): 10/10 on real GPU Chrome. Quota-error recovery + the one-time toast are PR11 part 2.
This was referenced Jul 16, 2026
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.
First of two parts for PR11 (bounding the tile-undo delta chain). This part replaces PR10's eager fold-into-base with the plan's deferred
foldedIdsmodel + byte budget + compaction. Part 2 addsQuotaExceededErrorrecovery + the one-time toast. On-mode only; flag off is unchanged.What's in it
Meta-only eviction -
TileShadowmoves the oldest active entries into afoldedlist (no pixel work) while the window exceedsMAX_UNDOor the byte budget =min(32MB, storage.estimate().quota / 20)(sized at boot viaapplyBudget). Keeps ≥1 active entry, so a user at the stack bottom overshoots transiently rather than losing the entry they just made. After a commit the pointer is at the tip, so eviction only folds entries strictly below it (pointer remaps as it folds).Compaction - once
foldedpasses 30, one enqueued step bakes every folded entry into the base and bumps the base version; the store rewrites the base and deletes the folded rows in the same tx (never folded rows without a base).Reconstruction / serialize / hydrate apply
base + folded + active, so boot replays folded rows and stays exact across a compaction boundary.Store -
meta2gainsfoldedIds; folded + active share oneentry:<id>namespace tracked bysavedRowIds. A pre-PR11meta2(nofoldedIds) still loads with an empty folded list, so on-mode early sessions don't drop to the v1 ladder.Acceptance
folded≤ 30 (boot-replay cap), reconstructs exactly.tiled-boot.mjsgains an eviction phase (folded rows round-trip through IDB, boot == live paint): 10/10 on real GPU Chrome.Checks
npm run lintclean,npx tsc --noEmitclean,npx vitest run825/825,npm run build:appOK. Live:tiled-boot.mjs10/10,tiled-restore.mjs8/8 (no regression).