Feature Library

Automatic version history, thinned with age

0.05 CPU ms
A still of the Automatic version history, thinned with age demo
Still
The live demo starts when it’s in view.Type in the notes · skip ahead and watch old copies thin out · open a version to compare or restore it · move a draft to Trash and try saving it · damage the newest save and try loading

A copy of a document kept by itself a few minutes into each stretch of changes, and named copies on demand; thinned as they age (every copy for two hours…

What it costs a frame

0.05 ms
GPU
not used
CPU, median
0.05 ms
CPU, 95th pct
0.09 ms
Draw calls
0
Weight
Light

Measured 4 November 2026 on 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 156, 1920×1080 at 1×. 600 frames × 3 rounds, median kept. What ran: Measured with the clock at an hour a second and the simulated author writing: each frame moves the clock, keeps any copy due (one IndexedDB transaction, thinned in it), thins in memory as copies age and moves the timeline’s dots; the list redraws four times a second. Phones: tiers are being measured next.

On every machine it was measured on
MachineGPU msCPU msCPU p95
unknown GPU · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring toolnot timed0.050.09
apple · Apple A19 Proin a browser tab · 16 November 2026not timed0.060.08
Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 2026not timed0.080.16

Bars against one 16.7 ms frame. A browser-tab run is timed in a visible tab without the tool’s scripted input, so read it as close, not exact.

What it needs

Renders with
DOM and CSSPlain DOM and CSS: every current browser.
Your browser
Runs hereNo WebGPU needed
Depends on
NothingNo other packages

What it’s for

  1. Editors and note apps
  2. Boards and canvases
  3. Design and level tools
  4. Long forms and drafts
  5. Anything saved only in the browser
  6. A library of documents with a Trash
  7. Moving off localStorage
  8. Game saves and app state that must never strand the player
  9. Settings or documents whose format changes between versions

Pitfalls, in brief

  1. Thin after every copy kept and when time passes: copies age into a coarser tier without anything being written, and thinNow(doc) is what lets them go.
  2. Name what must never go: thinning only ever looks at unnamed copies, so a “Before the redesign” copy stays until someone deletes it.
  3. Keep copies on this device apart from the document people sync: in the shared document every collaborator would download every copy.
  4. Days are cut in UTC unless you pass offset: “one a day” then means one per UTC day, which may not be the reader’s day.
  5. A storage error is a result, not an exception: check ok and tell the person (once) when the disk is full or the window is private, or they will trust a history that is not there.
12 more in brief
  1. Keep a copy of what is there before restoring: a restore is then itself undone from the same list.
  2. IndexedDB is per origin and per browser: it is not a backup.
  3. Moving off localStorage, never delete the old key: check the whole old list first (one damaged entry stops the move, and the next load tries again), copy it in one transaction, and mark the move done in that same transaction so it runs once.
  4. A save must refuse a document in Trash, inside the transaction that would write it: otherwise a stale tab’s autosave, or a debounced save already queued, quietly brings back what the person just threw away.
  5. Trash the open document with its latest edits (trash(id, current)) and cancel any queued save first: the edits are kept in the same step, and the recovery copy goes with it, so a reload does not reopen it.
  6. Wait for the transaction’s complete event, not the request’s success: a full disk arrives as an abort after every request has succeeded, so only complete says the write is kept.
  7. The limit counts Trash too: offer “Delete for good” (erase) or a full library stays full.
  8. Keep the last good save beside the newest, in the same row, written whole: two rows (or two files) can be left half-updated by a crash, and then neither is the one before.
  9. Move the newest save to “the one before” only once it is a while older than the one already there (a minute by default): saving every ten seconds would otherwise fill both slots with the same moment, and the fallback would fall back to the same bad state.
  10. Read a damaged save as missing, never as an error, and say so once in plain words.
  11. Never write over a save made by a newer version of the app: an older tab or an older install that cannot read it would replace it with less.
  12. Tell “could not be read” (the storage or network failed) apart from “there is none”: start fresh without saving, or the first autosave writes over a good save that was only out of reach.
17 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From SpaciousPro. Fully custom code.

Grandfather–father–son rotation: the backup scheme of keeping fewer copies the older they get, which the tiers follow (an idea, no code)

Longest common subsequence diff: the textbook dynamic-programming line diff behind diffLines (as in Hunt and McIlroy’s diff, much simplified)

version historyautosaveretentionIndexedDBrestorediffofflinedraftstrashmigrationsave gamelast good savefallbackversioned saveno dependencies

Near it in the frame