#40 Editing large timelines in the browser pauses on every draft save
–
- github
- github/openchronology/timeline-app
- github/openchronology/timeline-app#40
- issue
- state:closed
## Problem When a signed-in user edits a timeline kept only in the browser (imported or new, not yet saved to their account), each edit schedules a draft save 700 ms later. Guests keep no drafts, so this does not affect them (`persistDraft` in `src/app.ts`). The save rebuilds the whole document (`model.document()`) and stores it in IndexedDB, which structured-clones it on the main thread. The page pauses for a time proportional to the timeline's size: | Moments | `model.document()` | `structuredClone` | Pause | |--:|--:|--:|--:| | 10,000 | 14 ms | 21 ms | ~35 ms | | 50,000 | 47 ms | 137 ms | ~180 ms | | 100,000 | 94 ms | 302 ms | ~400 ms | | 200,000 | 202 ms | 648 ms | ~850 ms | These were measured in Node (V8) on a fast desktop; phones are estimated at 3–5× slower. The pause is the main limit on browser editing besides opening the timeline. ## Proposal Store drafts incrementally instead of whole: - Keep moments, durations and relationships in IndexedDB object stores keyed by ID, and write only the entities changed since the last save, plus the settings. That is O(changes), like the server's sparse saves. - Restoring a draft reads the stores back into a document. - Migrate existing whole-document drafts once. - (If incremental stores turn out impractical, a fallback is to serialize to a string in a Web Worker and store the string, which moves most of the cost off the main thread.) ## Acceptance criteria - The pause after an edit no longer grows with timeline size: under 10 ms at 200,000 moments, measured by the capacity benchmarks. - Drafts restore exactly, including durations, relationships and settings. Tests compare a restored draft with the edited document after random edits. - Existing drafts keep working. https://github.com/openchronology/timeline-app/issues/40
Related
Open #40 Editing large timelines in the browser pauses on every draft save in the timeline