#127 · Cancel and undo moment edits without rebuilding indexes, and drop the blurred backdrop
- timeline-app
- pull request
The PostgreSQL job's UI gate kept failing now and then on **browser 10000 cancel-moment** (154 ms, 169 ms against 150). Recent runs measured 79–169 ms and were over the 100 ms budget in 6 of 11, so the slowness was real, not noise. Two causes: ## 1. Cancel and undo rebuilt the duration and relationship indexes `discardMomentEdits()` (cancelling the moment dialog) and `applyEdit()` (undo and redo) reverted a moment by **deleting** it and putting the original back. `TimelineIndex.delete()` treats a moment that durations or relationships follow as removed and marks the interval and edge indexes for rebuilding (#68). So the next frame rebuilt both from scratch, re-parsing every duration and relationship time. A CPU profile of a cancel on the benchmark's 10,000-moment document (1,000 durations, 1,000 relationships) shows `render → frame → durationTree` at 278 ms and `edgeTree` at 142 ms, mostly in `Q.parse`. **Fix:** when the reverted moment is the same moment, the original simply **replaces** it with `put()`, as duration edits already do. `put()` keeps the indexes when the moment's time is unchanged. Only a moment that goes away, such as an undone creation, is deleted. ## 2. The blurred dialog backdrop `dialog::backdrop { backdrop-filter: blur(4px) }` re-blurs the whole window whenever the timeline under a dialog redraws. Without a fast GPU (CI's software rendering, weaker machines), the Event Timing API showed the frame after the click taking 200–670 ms to paint, with handlers under 15 ms and no long task. The backdrop is now a plain, slightly darker scrim. ## Results (local, `bench/ui.mjs`, browser, 10,000 moments, 5 samples) | | before | after | | --- | --- | --- | | cancel-moment | 391 ms | **48 ms** | | typing | 143 ms | **31 ms** | | undo-redo | — | 26 ms | | save-moment | 14 ms | 12 ms | | open-moment | — | 31 ms | At 4× CPU slowdown, cancel went from 1,379 ms to 160 ms; that configuration is past the slow-device comfortable size, so it only feeds the advice. Unit tests and the full Chromium browser suite pass.