From 2701c820843c4ec3f8b18861cfdca3dc29f4c094 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 19:31:39 -0300 Subject: anim 8: the note, docs/next-anim.md --- docs/next-anim.md | 877 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 877 insertions(+) create mode 100644 docs/next-anim.md (limited to 'docs/next-anim.md') diff --git a/docs/next-anim.md b/docs/next-anim.md new file mode 100644 index 00000000..9f43a232 --- /dev/null +++ b/docs/next-anim.md @@ -0,0 +1,877 @@ +# anim: the game animation pass, as built + +The author's words were the spec: scrolling whose timing is consistent so +it never feels choppy; every scroll animated, a long one too; smooth +while keeping the responsiveness; the thin insert-mode caret animated like +the block; small motions that read as smooth; the game's habits for +implementation and testing, frame timings measured as a game measures +them. Later rounds: input latency is a hard constraint; p90/p99 against +the mean is the smoothness measure; throughput on a big file; every file +kind, pane kind and way a view moves, the tty, long lines walked along, +picture and PDF first frames; ponytail for all of it; recordings. + +Positions, not a verdict: argue with them. + +## The change stack (workspace `pardes-n-anim`, above converge `oqolqlko`) + +| change | what | +|---|---| +| anim 1 `vtmwqzpt` | `src/FrameStats.zig`, the frame probe in `Pardes.frames`, stamped by `pump`; the Debug box's timing lines; `PARDES_FRAMES` dump at exit | +| anim 1b `sxxnrzqz` | input-to-present latency, work zones, the view shown, the tty's bytes; the timedemos (`PARDES_FRAMES_DEMO=scroll\|stress\|jumps\|kinds\|panes\|longlines\|one\|clip-*`); `PARDES_FRAMES_CAPTURE` (every presented frame's pixels, for the samples) | +| anim 2 `yqwqutws` | the GUI's paced frame loop: a tick grid, each frame sampled at its tick, an input's frame at once | +| anim 3 `wkxvyoqy` | every scroll glides, whatever moved the view | +| anim 4 `qztrptlo` | the thin caret glides; a step eases; the caret rides a scroll's glide | +| anim 5 `ntnlpots` | colours painted ahead on a worker (`Stream.paintAhead`) | +| anim 6 `xykrnoql` | the tty paced too, its acks and output waited through | +| anim 7 `powlyrxv` | what the probe found: the spin, glide measure and emission, far-jump and long-line paints, the caret's sideways scroll, no join on the loop, pictures decoded off the loop | +| anim 8 | this note | + +Tests (one check each, `-Dtest-filter`): "frame stats: gaps into a motion +count as jank ...", "every scroll glides on one law ...", "a cursor eases +a cell at a time, keeps up with typing, and glides a jump ...", "the +focused cursor glides a jump, eases a step, the thin caret too ...", +"Stream: a scroll's colours are painted ahead on a worker ...", "a long +line is painted only around the caret", "a caret deep in a long line +scrolls the view sideways to it, measured from the view's edge". Builds: +Debug and ReleaseSafe, gui and tty. Failing: only the two baseline +failures NEXT.md names. Not re-baselined: the GUI golden `16-debug` (the +Debug box is three rows taller; it shows `frame virtual clock` under the +golden's clock so it stays still). + +## Method + +The probe (anim 1, 1b): a fixed ring of 16384 frames in `Pardes` (1.3 MB, +nothing allocated per frame, three clock reads a frame, always on). Per +drawn frame: update, render, present µs; the gap since the last present; +whether something was moving into it (a gap over 1.5 periods then is +jank); the input-to-present latency of the first input it answers (SDL's +event timestamp, moved onto the monotonic clock; the tty stamps a key as +its loop takes it); the view and the picture's offset (throughput is rows +actually presented); zones (the core's body rows and colours; the GUI's +instance build, shaping and rasterizing in it; a soft present's GPU wait, +upload and flip); the tty's bytes. `Debug` shows the last second. + +The timedemos are a game's: fixed scripts fed through the shell's own +input paths, named phases, the session ending itself. The tty is driven +through a pty I own (`.scratch/tools/ttydemo.py`, typing the same +scenarios as bytes, answering the frame acks). The corpus +(`.scratch/tools/corpus.sh`) links 13 big real files from the genizah +(a generated C parser, helix's commands.rs, a Python table, jquery, a +minified bundle, a grammar JSON, CHANGELOG.md, an HTML spec page, the +simdutf amalgamation, a TypeScript parser, a long shell test, a Go table, +guide.typ) and generates five (a 600 KB one-line JSON, CJK/emoji/ +combining/RTL/tab text, a 32 MB log, 400k short lines, six 360 KB lines). +The stress file is layout.zig x23 (38k lines, 1.6 MB). + +**Every before/after below is a pair run back to back** (`batch3.sh`: +base then after per demo), the before binary being main+probe (anim 1/1b +alone, `.scratch/base-bin`). The first batch, before and after an hour +apart, was useless: this i7-11700 under intel_pstate moves its clock 2-5x +with load, which moved every number more than any change did. + +## What the probe found, and what came of it + +1. **Only a wheel notch animated.** Ctrl-d/u/f/b, PageDown, G, ge, gg, n, + a Look: zero animated frames; a wheel flick past a body less three rows + snapped. Now every move glides (below). +2. **The loop ran uncapped while anything moved**, ~230 frames a second + on a 60 Hz display (the core asks for a 1 ms wait; the Wayland soft + present has no vsync), so the compositor showed whichever frame was + newest at each refresh: motion sampled at a random phase, the choppy + the author felt. Moving gaps before: p50 4.3 ms, stdev 2.2. Now one + frame a tick, sampled at the tick: p50 16.6, p99 17.2-18.0 ms. +3. **Pacing asleep made every frame 2-5x slower** (the same body-rows + work 3 -> 16 µs, an input's first frame 2.6 -> 7.5 ms p50 RS): a core + that sleeps 80% of each 16 ms is clocked down. Fixed by spinning while + something moves, as a game's frame limiter does (A/B below). +4. **Tree-sitter parsing on the frame** (perf: 36% of the Debug stress + run, most of it the DebugAllocator capturing a stack trace for every + tree-sitter allocation): a scroll past the painted stretch parsed the + next one on the frame, 6-58 ms in Debug, a hitch every two pages. Now + painted ahead on a worker; Debug held PageDown render p90 24 -> 1 ms. +5. **A key typed in the middle of a 500 KB line repainted the line**: + 172-213 ms a key in ReleaseSafe (minified JS, one-line JSON). Now 16 KB + round the caret. +6. **The caret's sideways scroll walked a long line from its start** + (no-wrap, `ensureCursorVisible`, `rawAtDisplay` measures the whole + line): now measured from the view's edge (`lineDisplayOffset`, which + already existed for selections). +7. **A picture decoded on its first frame**: 80-94 ms RS, 285-296 ms + Debug for the docs' screenshot. Now on a thread; the pane appears at + once and the picture lands a frame or so after the decode. +8. **The ReleaseSafe tail is the soft present**: a GPU fence wait (p50 0.6 + ms, p99 6.4) and a 6.7 MB upload (p50 0.9-1.7, p99 4.8) every frame. + With the GPU swapchain (X11 here) the scroll is 0.34 ms of work p50. + Not changed: see the positions. +9. Smaller, fixed: the glide's shift search on a page's first frame (6 ms + Debug: the core's line count is tried first), its emission of every + body row however far it lagged (twice the instances), a far jump + painting three views on the frame, a paint asked at every keystroke, a + paint of a 600 KB line joined on the loop (half a second), the tty's + loop running at the terminal's round trip (its acks woke it: one frame + every 0.4-2 ms while anything moved). + +## The design as built + +### Pacing (anim 2, 6, 7) + +While anything moves, the GUI draws one frame a display refresh on a grid +of ticks (`waitInput`, `Gui.pace_ns`), and the core is advanced to the +tick (`guiNow` -> `Shell.paced_ns`), not to whenever the loop woke, so each +frame moves the motion by exactly a period. A late frame skips the ticks +it missed. An input ends the wait at once and its frame is drawn then; +the grid restarts from it. Idle, the loop sleeps as before. Patterns: a +fixed presentation cadence over variable-step evaluation (the springs are +closed form, evaluated at the tick; the core's stepped animations keep +their 16 ms steps), a frame limiter, input acted on at once and never +gated (only the picture is paced). + +The tick is waited out polling, not asleep (anim 7). Same binary, same +script, interleaved, ReleaseSafe, the scroll demo (`.scratch/runs/ab*`): + +| loop | input-to-present p50/p90 ms (notches) | moving gap p50/p90/p99 ms | CPU s per 18 s run | +|---|---|---|---| +| before: uncapped | 3.2/15.2 | 4.4/9.3/10.1 | 1.9 | +| paced, asleep | 6.8-8.2/11-14 | 16.4/19.0/23.6 | 2.9-3.1 | +| paced, spinning | 1.8-1.9/7.7-15 | 16.6/16.8/17.4 | 7.0-7.3 | + +The tty is paced asleep (a terminal has no vsync and no sub-cell motion, +and power matters more there), and its wait now runs through the frame +acks and pty output to the tick (`waitOnce`): its moving frames went from +every 0.4-2 ms (each a write) to one a 16 ms tick. + +### Every scroll glides on one law (anim 3, 7) + +`stepGlide` keeps each pane's view as the last loop saw it (`Glide.seen`) +and finds the one that moved, whatever moved it. The body as the last +frame drew it is still in `core.surface` then, so it is copied there (no +per-frame copy). The next frame measures the rows moved (the core's line +count tried first; the shift search only when wrapped rows disagree), +keeps the rows that left for the gap, and kicks the spring. + +- The law: the Motion flavour's critically damped spring (the one the + author liked on a notch) at 1.5x its pace; a move during a glide adds + its rows and keeps the speed: retarget, never queue. A notch settles in + 12 frames, a half page 15, a page or a 30 000-line jump 16. +- Past what two frames share, the last frame's body is laid just past the + new one and slides one body (`.scratch/ge-montage.png`: line 55 runs + into 9448). The lag may reach two bodies, so a jump mid-glide carries on. +- Readable: at most a body in four frames (`Glide.sample`). +- Not gliding: a new pane (appears at once), a pane moved or resized in + the same step, a terminal's output, a touchpad (follows the finger), + generated text rewritten as its view moved, Motion off (all land; the + test checks). +- The caret and the glide quad ride the picture (`glideLift`). + +### The cursor (anim 4) + +The thin caret glides as the block does. A step of a cell or less eases +instead of landing: its own spring 1.5x stiffer, the four corners +together, never overshooting, ~60 ms; at a key's repeat it trails half a +cell and never smears a caret into a block. A jump still smears and bows. + +### Colours painted ahead (anim 5, 7) + +`Stream.paintAhead` asks the disk engine's worker (its own generation +bit) to paint the stretch two views ahead the way the view last went, +with its own parser and cursor (`syntax.highlightApart`; markdown and +typst, whose injections share parsers, stay on the loop). +`refreshHighlights` takes it on arrival (`takeAhead`). A paint still +reaching into what is asked is let finish; one that does not is told to +stop and left to end on its own, never joined on the loop. Not asked +while the view stands still, nor for stretches over 512 KB. + +## Per scenario: glides, snaps or follows + +| scenario | | why | +|---|---|---| +| wheel notch, a spin | glides, each notch retargeting | discrete steps, piled onto one glide | +| touchpad | follows | direct manipulation: smoothing is lag | +| Ctrl-d/u/f/b, PageDown/Up, held | glide, retargeting | discrete jumps | +| G, 12G, 300G, 9000G, gg, ge | glide; past a body, one body's slide | a jump shorter than a body glides its rows; longer ones on the same law | +| n/N, `*`, a query's Ctrl-n/p moving its owner | glide (the owner's view) | the eye follows where the place went | +| Look `:40`, `:7000`, `file:line` in the same pane | glide | same | +| a Look opening a new pane | appears at once | nothing to glide from | +| jumplist Ctrl-o/Ctrl-i, SPC j o/i | glide | jumps | +| rail B1/B2/B3, a tick | glide | pardes's rail is acme's: a click scrolls by the row clicked; there is no thumb to drag, so nothing to follow (a thumb drag, if added, must be skipped in `stepGlide` as the touchpad is) | +| wheel over the gutter | glides | the wheel's | +| typing, arrows, w/e/l on long lines | the caret eases | small steps | +| Enter at the bottom of the view | a one-row glide each | the text rolls up | +| a 200-line paste | one body's slide | a long jump | +| terminal output | snaps | a stream would always lag | +| terminal under the wheel | glides | the wheel's; keys in its normal mode snap (position 4) | +| PDF | its own scroll | untouched here | +| no-wrap sideways scroll | snaps | horizontal glides were not asked; position 6 | + +## Ponytail pass (on the stack, amended in place) + +Deleted: the cursor-quad columns of the probe (unused by any analysis: +about 5 lines in anim 1 and 3 in 1b), the `PARDES_PACE_SLEEP` toggle and +the sleeping branch it kept (about 12 in anim 7; the A/B above is its +record); nothing else in the stack had a cheaper rung. +Shortcuts marked `ponytail:` with their ceilings: the ring's size, the +tick grid's phase (ours, not the display's), one glide at a time, one +paint at a time, the spin's cost, a thread a picture, the 16 KB long-line +paint. Measured behaviour unchanged by the pass (the toggle's default was +what was measured). + +## Numbers + +Every row is a pair run back to back (`batch3.sh`), the final binaries, +ms p50/p90/p99/max; *latency* is input-to-present of the frames that answer +an input; *frame work* is update + render + present of every drawn frame; +*present gap* only over frames something was moving into; *late* counts +moving gaps over 25 ms. The soft present (Wayland) in both. Small phases +(under ten inputs) move a couple of ms round to round in both directions; +the long phases are the ones to read. + +### Headline: every phase of a demo pooled, before -> after + +| build | demo | latency | frame work | present gap (moving) | +|---|---|---|---|---| +| rs | scroll | 4.2/8.2/11.4/17.4 → 2.4/7.8/14.1/14.1 | 3.6/8.4/11.2/17.0 → 3.0/6.6/11.5/14.0 | 4.5/9.4/11.9/12.6 → 16.6/16.8/16.9/17.8 | +| rs | stress | 6.4/12.4/20.7/29.5 → 2.1/6.5/12.2/14.5 | 3.6/10.4/19.3/29.5 → 2.1/6.3/10.0/14.4 | 3.3/8.7/9.6/12.4 → 16.5/16.8/17.1/22.2 | +| rs | jumps | 6.5/10.1/15.9/21.5 → 3.8/11.2/12.8/20.5 | 4.0/8.8/13.5/21.1 → 1.9/7.1/11.6/20.0 | 8.4/17.1/21.2/23.8 → 16.6/16.8/18.0/22.7 | +| rs | kinds | 6.3/10.9/21.0/220.1 → 3.3/8.1/18.4/74.4 | 4.1/8.7/13.7/218.1 → 2.4/7.1/11.7/67.5 | 4.2/9.1/11.4/18.6 → 16.6/16.8/17.6/39.0 | +| rs | panes | 6.8/9.8/20.8/84.3 → 5.4/9.4/17.9/39.2 | 5.2/8.7/13.8/84.0 → 3.6/8.1/14.6/39.1 | 4.3/9.1/14.8/25.7 → 16.6/16.8/18.0/43.2 | +| rs | longlines | 8.7/17.6/189.4/218.7 → 7.7/17.9/26.5/37.7 | 4.7/9.1/13.7/210.2 → 3.6/9.3/19.9/36.7 | 4.3/9.2/11.3/22.0 → 16.5/16.8/17.3/22.1 | +| dbg | scroll | 8.2/15.6/33.3/40.2 → 4.4/15.6/23.7/29.7 | 3.7/8.9/15.5/32.9 → 3.1/7.5/17.6/23.2 | 4.4/8.9/11.8/15.0 → 16.6/16.8/17.3/18.0 | +| dbg | stress | 4.1/25.0/51.6/65.8 → 4.0/8.6/39.0/111.1 | 3.9/17.4/43.0/63.1 → 3.6/8.3/22.6/111.1 | 4.0/9.3/16.7/33.7 → 16.4/16.8/23.1/111.2 | +| dbg | jumps | 12.7/23.2/41.8/247.9 → 11.5/21.2/35.9/280.9 | 6.9/15.0/33.3/247.4 → 3.5/11.5/22.9/280.4 | 8.1/16.9/30.0/38.9 → 16.6/16.9/29.6/73.9 | +| dbg | kinds | 8.1/18.7/53.0/1979.3 → 4.6/15.2/56.8/438.8 | 4.4/12.3/28.9/1963.1 → 3.6/9.0/24.4/188.1 | 4.3/8.8/12.3/72.5 → 16.5/16.9/24.5/115.3 | +| dbg | panes | 7.9/16.2/65.6/304.3 → 6.2/16.1/64.1/266.2 | 5.3/13.1/18.7/301.1 → 4.1/12.9/23.7/262.6 | 4.6/9.2/27.9/108.3 → 16.6/16.8/37.1/146.3 | +| dbg | longlines | 16.6/33.1/35.8/2801.3 → 16.0/33.0/130.0/319.3 | 10.1/15.7/25.3/1963.0 → 9.2/16.5/80.0/180.3 | 8.6/16.8/27.4/34.5 → 16.6/16.8/18.2/167.2 | + +CPU (user s) per run, before -> after: base-rs-scroll 1.968, after-rs-scroll 7.072, base-rs-stress 4.059, after-rs-stress 14.329, base-rs-jumps 17.935, after-rs-jumps 48.597, base-rs-kinds 34.805, after-rs-kinds 94.319, base-rs-panes 11.838, after-rs-panes 24.085, base-rs-longlines 37.191, after-rs-longlines 70.976, base-dbg-scroll 2.524, after-dbg-scroll 7.842, base-dbg-stress 6.108, after-dbg-stress 18.640, base-dbg-jumps 31.800, after-dbg-jumps 60.583, base-dbg-kinds 56.343, after-dbg-kinds 109.000, base-dbg-panes 19.374, after-dbg-panes 29.634, base-dbg-longlines 77.796, after-dbg-longlines 90.633. +The spin is most of the difference (a core while something moves). + +Read in Debug: the before's long-line spikes were 2 s (a key in a 500 KB +line repainting it); after, a key there is 80-180 ms in Debug (16 KB of +tree-sitter through the DebugAllocator: position 2) and 18-22 ms in +ReleaseSafe; the pooled Debug p99 rises because those keys are many and +the 2 s ones were few, the max falls 2801 -> 319. + +### Per scenario + +#### GUI ReleaseSafe: `scroll` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| notches | before | 3.8/6.9/6.9/6.9 | 3.4/8.4/10.8/11.5 | 4.5/9.5/11.9/12.6 | 7 | 0 | +| | after | 1.9/8.4/8.4/8.4 | 1.8/3.2/8.3/8.3 | 16.7/16.9/17.8/17.8 | 7 | 0 | +| spin | before | 2.9/8.0/9.2/9.2 | 3.2/8.2/9.2/10.0 | 4.0/9.0/10.2/11.1 | 35 | 0 | +| | after | 2.4/7.1/11.8/11.8 | 2.3/6.4/11.7/11.7 | 8.8/16.7/17.0/17.0 | 34 | 0 | +| pages | before | 6.8/7.2/17.4/17.4 | 6.7/7.1/17.0/17.0 | - | 3788 | 0 | +| | after | 7.6/14.1/14.1/14.1 | 4.1/7.6/13.6/14.0 | 16.6/16.8/16.9/17.0 | 3598 | 0 | +| retarget | before | 8.4/11.2/11.2/11.2 | 8.4/11.1/11.1/11.1 | - | 150 | 0 | +| | after | 5.0/11.4/11.4/11.4 | 5.0/5.2/11.3/11.3 | 16.6/16.8/16.9/16.9 | 92 | 0 | +| cursor | before | 6.9/8.8/11.4/11.4 | 6.1/8.8/11.3/11.5 | 5.5/9.8/12.4/12.5 | 0 | 0 | +| | after | 2.4/8.2/10.6/10.6 | 4.0/6.7/10.4/11.5 | 16.6/16.7/16.9/17.7 | 0 | 0 | + +#### GUI ReleaseSafe: `stress` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| spin | before | 2.8/8.0/9.9/11.3 | 2.8/7.9/9.7/11.3 | 3.3/8.7/9.6/12.4 | 189 | 0 | +| | after | 2.1/6.0/7.6/10.6 | 2.2/6.5/7.5/10.6 | 8.2/13.2/16.8/16.9 | 175 | 0 | +| held-ctrl-d | before | 7.6/15.1/20.0/20.0 | 7.5/15.0/20.0/20.0 | - | 539 | 0 | +| | after | 2.2/6.5/14.5/14.5 | 2.1/6.1/9.3/14.4 | 16.6/16.9/17.3/18.2 | 508 | 0 | +| held-j | before | 6.8/11.1/15.3/15.3 | 6.7/11.0/15.3/15.3 | - | 35 | 0 | +| | after | 2.0/6.3/11.5/11.5 | 2.2/6.0/7.6/11.4 | 16.6/16.9/17.1/17.8 | 33 | 0 | +| held-pagedown | before | 11.2/19.4/29.5/29.5 | 11.1/19.3/29.5/29.5 | - | 758 | 0 | +| | after | 2.1/5.7/7.8/7.8 | 2.2/6.3/7.7/10.3 | 16.6/16.8/17.3/22.2 | 703 | 0 | +| far | before | 8.1/17.2/17.6/17.6 | 8.1/15.8/16.2/16.2 | - | 64670 | 0 | +| | after | 12.2/12.4/12.5/12.5 | 1.8/8.6/12.3/12.4 | 16.6/16.8/17.0/17.0 | 60219 | 0 | + +#### GUI ReleaseSafe: `jumps` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| counted-G-big | before | 6.9/12.0/16.5/16.5 | 6.5/9.6/16.1/16.1 | 4.7/9.4/10.7/10.7 | 9605 | 0 | +| | after | 8.6/12.5/12.8/12.8 | 5.2/8.5/12.1/12.3 | 16.6/16.8/22.5/22.5 | 8998 | 0 | +| pages-up-big | before | 8.2/14.2/21.2/21.2 | 8.1/14.1/21.1/21.1 | - | 1784 | 0 | +| | after | 8.4/8.8/15.4/15.4 | 4.1/6.0/12.7/15.3 | 16.6/16.8/18.0/18.1 | 1706 | 0 | +| search-n-big | before | 7.3/9.1/10.1/10.1 | 4.3/8.9/10.7/12.4 | 5.0/10.0/21.6/23.8 | 1255 | 0 | +| | after | 11.4/11.8/11.8/11.8 | 1.8/7.0/11.7/11.7 | 16.6/16.8/16.9/18.0 | 1255 | 0 | +| rail-big | before | 6.2/15.6/15.6/15.6 | 4.5/8.9/15.5/15.5 | 5.3/9.9/12.5/14.9 | 3028 | 0 | +| | after | 8.5/12.6/17.4/17.4 | 1.9/6.2/12.5/17.2 | 16.6/16.8/17.0/18.0 | 3030 | 0 | +| query-ctrl-n-big | before | 7.8/15.9/16.1/16.1 | 4.2/10.3/15.8/16.0 | 4.7/10.2/16.1/16.1 | 624 | 0 | +| | after | 6.3/8.8/9.2/9.2 | 1.8/6.0/9.1/11.7 | 16.6/16.8/17.9/18.2 | 724 | 0 | +| star-big | before | 6.9/10.1/10.1/10.1 | 3.5/8.6/11.2/11.2 | 4.5/10.6/16.0/16.0 | 853 | 0 | +| | after | 11.5/11.7/11.7/11.7 | 1.9/11.4/11.6/11.6 | 16.6/16.8/16.9/16.9 | 853 | 0 | +| jumplist-big | before | 12.5/15.6/19.1/19.1 | 6.8/12.6/19.0/19.0 | 16.9/18.9/22.7/22.7 | 4506 | 0 | +| | after | 11.6/11.8/11.9/11.9 | 1.8/7.1/11.7/11.8 | 16.6/16.9/18.7/21.9 | 7227 | 0 | +| insert-big | before | 3.3/7.4/12.6/21.5 | 2.4/7.0/12.3/21.0 | 15.9/16.8/22.0/22.4 | 42 | 0 | +| | after | 2.5/6.2/8.6/20.5 | 1.9/6.0/7.5/20.0 | 16.6/16.8/16.9/17.9 | 58 | 0 | +| counted-G-small | before | 9.1/12.4/12.4/12.4 | 9.0/12.3/12.3/12.3 | - | 384 | 0 | +| | after | 8.2/11.4/11.4/11.4 | 2.5/8.6/11.3/12.0 | 16.6/16.8/18.2/18.2 | 363 | 0 | +| pages-up-small | before | 7.6/15.6/15.7/15.7 | 7.5/15.4/15.6/15.6 | - | 78 | 0 | +| | after | 11.6/11.8/12.6/12.6 | 1.8/6.8/11.6/12.5 | 16.6/16.8/17.0/17.5 | 74 | 0 | +| search-n-small | before | 8.9/10.1/12.0/12.0 | 3.3/8.8/10.3/11.7 | 4.0/9.3/12.2/14.1 | 44 | 0 | +| | after | 7.2/10.7/11.4/11.4 | 5.6/7.1/11.3/11.3 | 16.6/16.8/18.1/18.1 | 45 | 0 | +| rail-small | before | 8.8/9.8/12.3/12.3 | 8.8/9.7/12.3/12.3 | - | 71 | 0 | +| | after | 7.3/7.8/8.7/8.7 | 7.1/7.5/8.5/8.5 | 16.6/16.8/16.9/16.9 | 72 | 0 | +| query-ctrl-n-small | before | 8.7/9.0/12.5/12.5 | 4.6/8.7/10.3/12.3 | 5.1/10.0/16.2/16.2 | 91 | 0 | +| | after | 7.1/7.6/10.8/10.8 | 1.8/7.0/10.5/10.5 | 16.6/16.8/17.5/17.5 | 94 | 0 | +| star-small | before | 9.3/10.4/10.4/10.4 | 6.8/9.5/11.0/11.0 | 6.9/9.7/12.4/12.4 | 166 | 0 | +| | after | 7.8/8.4/8.4/8.4 | 1.8/7.7/9.2/9.2 | 16.6/16.9/22.7/22.7 | 155 | 0 | +| look-small | before | 7.5/7.5/7.5/7.5 | 7.4/7.4/7.4/7.4 | - | 0 | 0 | +| | after | 8.3/9.6/9.6/9.6 | 5.9/9.4/12.2/12.2 | 16.6/16.8/18.0/18.0 | 80 | 0 | +| jumplist-small | before | 9.4/10.2/12.2/12.2 | 8.7/10.1/12.1/12.1 | 16.6/17.2/22.0/22.0 | 88 | 0 | +| | after | 8.2/9.5/11.2/11.2 | 6.6/8.1/12.3/12.3 | 16.6/17.2/22.4/22.4 | 87 | 0 | +| insert-small | before | 4.6/8.7/12.1/12.3 | 4.1/8.2/12.2/13.1 | 18.1/20.4/23.2/23.5 | 27 | 0 | +| | after | 2.0/6.2/8.0/12.9 | 1.8/5.7/7.6/12.8 | 16.6/16.8/17.4/17.9 | 38 | 0 | +| look-new-pane | before | 7.8/7.8/7.8/7.8 | 4.5/7.0/9.7/9.7 | 16.6/17.4/18.8/18.8 | 0 | 0 | +| | after | 14.8/14.8/14.8/14.8 | 14.0/14.0/14.0/14.0 | - | 0 | 0 | + +#### GUI ReleaseSafe: `kinds` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| generated-parser.c | before | 4.4/10.4/15.9/25.6 | 3.3/8.3/13.4/23.7 | 4.0/8.9/10.7/12.3 | 3794 | 0 | +| | after | 2.1/6.7/11.6/22.9 | 2.1/6.9/12.2/21.4 | 16.6/16.8/17.2/18.0 | 3788 | 0 | +| commands.rs | before | 6.8/11.8/22.4/62.2 | 4.1/9.0/18.2/60.6 | 4.3/9.0/10.8/11.8 | 1696 | 0 | +| | after | 2.0/7.0/11.7/16.2 | 1.9/6.5/11.5/14.7 | 16.5/16.8/18.1/22.6 | 1694 | 0 | +| tables.py | before | 6.9/12.7/16.3/25.2 | 3.7/8.7/13.8/23.4 | 4.2/9.1/11.4/12.3 | 2447 | 0 | +| | after | 2.0/6.4/9.5/11.4 | 1.9/5.7/11.3/12.6 | 16.6/16.8/17.9/22.6 | 2447 | 0 | +| jquery.js | before | 6.8/10.2/14.5/199.5 | 4.2/9.1/13.2/197.7 | 4.1/9.1/10.9/11.5 | 2154 | 0 | +| | after | 1.9/7.0/11.8/31.1 | 1.9/6.7/11.3/29.3 | 16.5/16.8/17.4/22.7 | 2147 | 0 | +| minified.js | before | 7.0/16.8/21.4/21.9 | 5.7/9.0/11.5/12.5 | 7.5/10.0/11.8/11.8 | 0 | 0 | +| | after | 7.0/16.5/22.5/22.6 | 4.8/8.3/12.0/12.5 | 16.6/16.8/16.9/16.9 | 0 | 0 | +| grammar.json | before | 6.2/9.9/13.1/205.0 | 3.2/8.1/12.1/204.2 | 4.0/8.6/9.7/10.5 | 2286 | 0 | +| | after | 1.8/7.0/11.5/22.4 | 1.8/6.9/11.1/20.4 | 16.6/16.8/16.9/18.0 | 2282 | 0 | +| oneline.json | before | 6.7/8.9/13.1/25.3 | 6.2/8.9/12.5/24.0 | 5.0/10.0/11.5/11.5 | 4 | 0 | +| | after | 6.8/10.1/35.0/47.4 | 6.4/9.1/32.0/45.8 | 16.6/16.8/16.8/16.8 | 4 | 0 | +| CHANGELOG.md | before | 4.1/16.5/26.4/28.2 | 3.3/8.7/21.8/28.1 | 4.0/9.0/11.6/13.6 | 715 | 0 | +| | after | 2.9/7.6/13.7/25.4 | 2.4/7.1/11.4/25.2 | 16.6/16.8/22.7/25.5 | 712 | 2 | +| cascade.html | before | 5.2/9.4/16.3/87.4 | 3.3/8.3/12.1/79.9 | 3.9/8.9/10.4/11.1 | 645 | 0 | +| | after | 2.2/6.7/10.8/74.4 | 1.9/6.5/11.1/67.5 | 16.6/16.8/17.0/17.6 | 645 | 0 | +| simdutf.cpp | before | 5.1/12.5/23.0/24.5 | 4.0/9.1/22.5/24.4 | 4.4/8.9/10.8/12.8 | 9874 | 0 | +| | after | 2.0/6.9/11.0/11.0 | 1.9/6.2/10.8/11.0 | 16.6/16.8/17.2/17.6 | 9872 | 0 | +| parser.ts | before | 5.4/9.5/13.0/33.0 | 4.5/8.9/12.3/32.0 | 4.5/9.6/11.4/12.0 | 1779 | 0 | +| | after | 2.0/7.0/10.6/25.8 | 2.0/6.8/11.9/24.8 | 16.5/16.8/17.5/18.3 | 1778 | 0 | +| fcnal-test.sh | before | 4.1/10.4/14.0/57.5 | 3.3/8.6/12.2/55.3 | 4.0/8.9/10.6/11.6 | 1037 | 0 | +| | after | 1.9/7.0/10.8/58.8 | 1.9/6.6/10.7/56.6 | 16.6/16.8/17.5/18.2 | 1036 | 0 | +| data.go | before | 6.9/9.2/14.3/28.0 | 3.9/8.6/12.3/27.8 | 4.3/9.1/11.2/12.1 | 3898 | 0 | +| | after | 2.1/6.8/10.6/38.6 | 2.0/6.2/11.7/38.1 | 16.6/16.8/17.1/18.2 | 3892 | 0 | +| guide.typ | before | 6.8/13.2/17.7/17.9 | 4.3/9.0/15.6/17.7 | 4.4/9.2/11.3/13.3 | 119 | 0 | +| | after | 2.6/7.9/13.3/19.3 | 2.0/7.1/12.5/15.6 | 16.5/16.8/18.3/23.7 | 119 | 0 | +| unicode.txt | before | 6.9/9.8/15.6/53.9 | 4.1/8.7/11.7/21.0 | 4.4/9.3/11.6/13.1 | 4642 | 0 | +| | after | 2.1/6.9/17.3/55.2 | 1.9/6.3/11.2/22.0 | 16.6/16.8/17.0/18.4 | 4635 | 0 | +| big.log | before | 3.8/11.0/15.8/29.8 | 3.3/8.8/12.8/13.9 | 4.1/8.9/10.7/12.4 | 69343 | 0 | +| | after | 2.4/8.7/23.4/24.8 | 2.4/7.2/12.3/13.9 | 16.5/16.7/17.0/17.8 | 69269 | 0 | +| words.txt | before | 6.4/8.6/12.4/15.7 | 3.6/8.5/11.4/12.3 | 4.1/9.3/11.2/12.5 | 92633 | 0 | +| | after | 1.9/6.6/13.8/14.3 | 2.2/7.0/11.9/12.0 | 16.6/16.8/17.3/22.2 | 92628 | 0 | +| hugelines.txt | before | 6.7/10.0/16.5/177.6 | 6.0/9.3/12.3/177.1 | 7.0/15.7/18.6/18.6 | 12 | 0 | +| | after | 6.8/10.6/15.2/29.9 | 6.3/10.2/12.1/28.1 | 16.6/17.0/39.0/39.0 | 12 | 1 | +| minified.js! | before | 7.2/16.1/21.3/220.1 | 5.3/9.0/12.4/218.1 | 6.4/12.2/17.0/17.0 | 0 | 0 | +| | after | 7.2/17.3/22.3/27.3 | 5.0/8.7/12.4/25.4 | 16.6/16.8/16.9/16.9 | 0 | 0 | +| oneline.json! | before | 6.7/10.5/13.0/17.4 | 5.8/9.4/12.3/12.8 | 4.9/9.5/11.0/11.1 | 0 | 0 | +| | after | 6.4/10.2/20.0/38.1 | 5.3/8.9/12.7/37.6 | 16.6/16.8/16.9/16.9 | 0 | 0 | +| hugelines.txt! | before | 6.4/9.6/16.0/18.2 | 5.4/8.7/11.7/13.7 | 5.0/9.7/12.0/12.3 | 2 | 0 | +| | after | 5.6/9.4/13.6/16.5 | 3.6/8.1/11.5/13.4 | 16.6/16.8/17.0/17.2 | 2 | 0 | + +#### GUI ReleaseSafe: `panes` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| command-cat | before | 7.1/9.1/14.5/31.5 | 5.9/8.2/12.9/25.9 | 4.5/9.0/14.8/14.8 | 4668 | 0 | +| | after | 6.7/11.1/13.7/24.6 | 6.2/10.2/12.3/12.7 | 16.6/16.9/22.8/22.8 | 4616 | 0 | +| command-yes | before | 6.7/9.6/13.0/22.6 | 6.0/8.9/12.6/20.6 | 5.7/9.8/11.9/11.9 | 4855 | 0 | +| | after | 6.1/9.1/12.7/23.5 | 4.6/8.5/12.5/21.4 | 16.6/16.8/17.4/17.4 | 4924 | 0 | +| pager | before | 7.0/9.2/12.7/12.9 | 6.1/8.7/12.3/12.6 | 4.4/9.0/13.0/13.0 | 0 | 0 | +| | after | 6.9/9.7/14.3/14.6 | 5.5/9.2/12.4/14.6 | 16.6/16.8/17.3/17.3 | 0 | 0 | +| directory | before | 6.4/9.3/12.2/12.3 | 4.4/8.6/12.0/12.2 | 4.4/9.1/11.4/12.2 | 2 | 0 | +| | after | 5.6/8.7/12.4/12.5 | 3.5/7.6/11.9/12.4 | 16.6/16.8/17.7/18.0 | 2 | 0 | +| pdf | before | 6.9/16.1/44.7/44.9 | 6.4/13.3/31.5/44.8 | 3.9/9.1/9.5/9.5 | 0 | 0 | +| | after | 7.0/16.6/38.5/39.2 | 6.4/14.6/34.5/39.1 | 16.6/16.8/17.8/17.8 | 0 | 0 | +| image | before | 6.9/10.1/24.1/84.3 | 5.9/9.1/12.4/84.0 | 4.6/9.1/10.7/10.7 | 0 | 0 | +| | after | 6.9/9.0/12.7/14.1 | 6.4/8.9/12.4/28.5 | 16.6/16.8/43.2/43.2 | 0 | 1 | +| help | before | 6.8/8.8/12.1/12.6 | 3.5/8.2/11.5/12.5 | 4.2/8.8/11.5/12.4 | 69 | 0 | +| | after | 2.6/7.1/8.0/14.4 | 1.9/6.8/8.0/14.0 | 16.6/16.8/17.1/18.0 | 69 | 0 | +| changelog | before | 6.3/9.6/12.9/13.0 | 4.0/8.6/12.0/12.9 | 4.2/9.2/11.7/12.7 | 220 | 0 | +| | after | 1.8/6.8/13.7/14.3 | 1.8/6.4/11.2/14.3 | 16.6/16.8/17.3/18.3 | 220 | 0 | +| query-typing | before | 7.5/10.6/13.8/13.8 | 1.7/11.7/13.8/14.1 | 2.8/15.4/23.2/25.7 | 0 | 1 | +| | after | 7.3/9.3/12.4/12.4 | 1.9/7.9/12.3/12.6 | 16.6/17.0/22.9/22.9 | 17 | 0 | + +#### GUI ReleaseSafe: `longlines` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| w-held-minified.js-wrap | before | 3.0/7.9/9.4/9.4 | 3.2/8.1/9.4/9.9 | 4.1/9.1/10.5/11.0 | 0 | 0 | +| | after | 1.8/5.9/7.7/7.7 | 1.7/5.7/7.3/7.6 | 16.6/16.7/16.9/17.3 | 0 | 0 | +| e-held-minified.js-wrap | before | 3.1/8.3/9.3/9.3 | 3.1/8.0/9.2/11.3 | 4.1/9.0/10.0/12.4 | 0 | 0 | +| | after | 1.7/5.9/7.2/7.2 | 1.7/5.7/7.2/7.2 | 16.6/16.8/17.7/18.2 | 0 | 0 | +| l-held-minified.js-wrap | before | 6.6/10.1/11.7/11.7 | 3.3/8.5/11.3/11.6 | 4.2/9.2/10.3/12.0 | 0 | 0 | +| | after | 1.9/5.9/7.3/7.3 | 1.9/5.9/7.3/7.3 | 16.6/16.8/17.1/17.4 | 0 | 0 | +| dollar-zero-minified.js-wrap | before | 7.5/8.7/8.7/8.7 | 7.3/8.6/8.6/8.6 | - | 0 | 0 | +| | after | 7.5/7.7/7.7/7.7 | 3.2/7.7/11.4/11.4 | 16.6/16.9/16.9/16.9 | 0 | 0 | +| f-t-minified.js-wrap | before | 7.3/7.6/7.8/7.8 | 7.2/7.5/7.7/7.7 | - | 0 | 0 | +| | after | 7.2/7.5/9.0/9.0 | 4.6/11.2/11.6/12.0 | 14.5/16.7/17.9/18.0 | 0 | 0 | +| gl-gh-minified.js-wrap | before | 7.4/7.6/7.7/7.7 | 7.3/7.5/7.6/7.6 | - | 0 | 0 | +| | after | 7.4/8.1/8.4/8.4 | 5.0/11.0/11.4/11.4 | 13.9/16.7/18.7/18.7 | 0 | 0 | +| insert-end-minified.js-wrap | before | 7.2/11.0/12.7/12.7 | 7.0/10.7/12.6/12.6 | 5.7/9.8/10.6/10.6 | 0 | 0 | +| | after | 1.8/6.2/8.0/8.0 | 1.8/6.1/10.6/10.9 | 16.6/16.8/17.3/18.1 | 0 | 0 | +| insert-middle-minified.js-wrap | before | 171.7/177.5/185.4/185.4 | 7.3/174.3/184.4/184.4 | 5.2/9.8/10.3/10.3 | 0 | 0 | +| | after | 16.8/26.5/28.1/28.1 | 12.7/24.9/27.3/27.3 | 15.9/16.7/16.9/16.9 | 0 | 0 | +| sweep-L-W-minified.js-wrap | before | 7.1/11.5/212.2/212.2 | 6.9/10.2/14.1/210.2 | 5.5/9.4/12.9/12.9 | 0 | 0 | +| | after | 7.3/12.1/13.5/13.5 | 6.8/11.2/12.6/12.9 | 16.6/16.9/20.9/20.9 | 0 | 0 | +| w-held-oneline.json-wrap | before | 3.9/10.1/11.3/11.3 | 4.1/8.6/10.9/11.5 | 4.8/9.6/11.4/12.0 | 0 | 0 | +| | after | 1.8/6.0/13.3/13.3 | 1.8/5.7/7.3/13.2 | 16.6/16.8/17.0/17.6 | 0 | 0 | +| e-held-oneline.json-wrap | before | 3.2/7.8/9.0/9.0 | 3.2/8.2/9.4/11.1 | 4.1/9.2/10.6/12.2 | 0 | 0 | +| | after | 1.8/5.6/7.7/7.7 | 1.8/5.6/7.6/7.6 | 16.6/16.8/16.9/17.0 | 0 | 0 | +| l-held-oneline.json-wrap | before | 4.4/10.4/13.3/13.3 | 3.2/8.4/11.9/13.2 | 4.0/9.1/11.0/13.4 | 0 | 0 | +| | after | 1.9/6.1/7.5/7.5 | 1.8/6.0/7.4/7.5 | 16.6/16.8/17.2/17.4 | 0 | 0 | +| dollar-zero-oneline.json-wrap | before | 7.6/8.0/8.0/8.0 | 7.4/7.7/7.7/7.7 | - | 0 | 0 | +| | after | 9.0/9.4/9.4/9.4 | 2.3/8.9/10.8/10.8 | 16.5/16.9/17.0/17.0 | 0 | 0 | +| f-t-oneline.json-wrap | before | 7.4/7.6/9.2/9.2 | 7.3/7.5/9.1/9.1 | - | 0 | 0 | +| | after | 7.3/8.8/9.3/9.3 | 4.6/10.4/11.7/12.3 | 14.7/16.7/17.0/17.4 | 0 | 0 | +| gl-gh-oneline.json-wrap | before | 7.5/7.6/7.6/7.6 | 7.3/7.4/7.5/7.5 | - | 0 | 0 | +| | after | 7.5/7.7/8.6/8.6 | 4.0/10.6/11.5/11.5 | 14.5/16.6/16.9/16.9 | 0 | 0 | +| insert-end-oneline.json-wrap | before | 7.4/10.8/12.8/12.8 | 7.2/10.6/12.9/12.9 | 7.8/10.3/14.0/14.0 | 0 | 0 | +| | after | 1.8/6.0/7.4/7.4 | 1.8/5.9/11.1/11.3 | 16.6/16.8/17.0/17.0 | 0 | 0 | +| insert-middle-oneline.json-wrap | before | 193.1/199.8/207.9/207.9 | 5.2/195.5/206.4/206.4 | 4.0/9.3/13.6/13.6 | 0 | 0 | +| | after | 21.3/29.0/37.7/37.7 | 18.1/25.4/36.7/36.7 | 16.6/16.9/17.9/17.9 | 0 | 0 | +| sweep-L-W-oneline.json-wrap | before | 7.2/11.3/31.8/31.8 | 6.8/9.3/12.2/12.5 | 4.4/9.3/10.1/10.5 | 6 | 0 | +| | after | 7.7/12.1/21.5/21.5 | 6.9/11.0/12.6/21.5 | 16.6/16.8/16.9/16.9 | 6 | 0 | +| w-held-hugelines.txt-wrap | before | 3.2/8.5/11.8/11.8 | 3.2/8.2/10.2/12.2 | 4.2/9.1/10.5/13.3 | 0 | 0 | +| | after | 1.8/5.8/10.7/10.7 | 1.8/5.5/7.4/10.6 | 16.6/16.8/17.3/17.9 | 0 | 0 | +| e-held-hugelines.txt-wrap | before | 5.1/7.3/11.7/11.7 | 4.1/8.5/11.3/11.9 | 4.5/9.5/12.1/12.9 | 0 | 0 | +| | after | 3.7/7.3/12.6/12.6 | 2.4/7.1/12.5/12.5 | 16.6/16.8/18.1/18.1 | 0 | 0 | +| l-held-hugelines.txt-wrap | before | 7.3/11.6/13.0/13.0 | 7.1/11.4/12.9/12.9 | - | 0 | 0 | +| | after | 7.2/11.4/13.4/13.4 | 7.1/11.2/13.2/13.2 | - | 0 | 0 | +| dollar-zero-hugelines.txt-wrap | before | 7.3/7.4/7.4/7.4 | 7.1/7.2/7.2/7.2 | - | 0 | 0 | +| | after | 7.3/7.3/7.3/7.3 | 6.0/10.4/11.0/11.0 | 15.6/16.6/16.7/16.7 | 0 | 0 | +| f-t-hugelines.txt-wrap | before | 7.2/7.5/7.6/7.6 | 7.1/7.3/7.5/7.5 | - | 0 | 0 | +| | after | 7.2/7.4/9.2/9.2 | 4.4/10.9/11.7/11.9 | 14.6/16.7/16.9/16.9 | 0 | 0 | +| gl-gh-hugelines.txt-wrap | before | 7.4/7.6/7.6/7.6 | 7.2/7.4/7.5/7.5 | - | 0 | 0 | +| | after | 7.4/7.9/10.8/10.8 | 4.6/10.6/11.2/11.2 | 14.8/16.8/17.7/17.7 | 0 | 0 | +| insert-end-hugelines.txt-wrap | before | 7.4/10.6/12.1/12.1 | 7.2/10.5/12.0/12.0 | - | 0 | 0 | +| | after | 2.1/7.4/8.0/8.0 | 2.2/7.3/10.7/10.8 | 16.6/16.8/16.9/17.0 | 0 | 0 | +| insert-middle-hugelines.txt-wrap | before | 7.9/10.7/13.0/13.0 | 7.2/10.2/12.1/12.1 | - | 0 | 0 | +| | after | 7.9/12.9/13.5/13.5 | 7.2/12.2/12.4/12.4 | - | 0 | 0 | +| sweep-L-W-hugelines.txt-wrap | before | 7.8/12.3/14.9/14.9 | 7.0/11.5/13.8/14.8 | 5.8/10.8/19.9/22.0 | 0 | 0 | +| | after | 7.7/11.9/13.1/13.1 | 7.1/12.1/13.6/14.6 | 16.7/16.9/20.1/20.1 | 0 | 0 | +| w-held-minified.js-nowrap | before | 7.1/16.3/28.5/28.5 | 3.5/8.2/10.2/13.7 | 4.5/9.2/10.9/11.3 | 0 | 0 | +| | after | 2.7/15.9/22.6/22.6 | 2.1/3.9/12.7/12.7 | 16.6/16.8/17.9/17.9 | 0 | 0 | +| e-held-minified.js-nowrap | before | 15.5/19.6/24.7/24.7 | 4.4/8.4/10.1/10.1 | - | 0 | 0 | +| | after | 15.2/18.8/23.0/23.0 | 4.1/8.2/9.4/9.4 | - | 0 | 0 | +| l-held-minified.js-nowrap | before | 15.7/20.7/27.7/27.7 | 4.3/8.4/11.3/11.3 | - | 0 | 0 | +| | after | 15.3/19.6/24.2/24.2 | 3.9/8.9/9.9/9.9 | - | 0 | 0 | +| dollar-zero-minified.js-nowrap | before | 9.2/10.1/10.1/10.1 | 9.0/9.9/9.9/9.9 | - | 0 | 0 | +| | after | 9.3/10.4/10.4/10.4 | 3.7/9.1/10.2/10.2 | 16.6/16.8/16.9/16.9 | 0 | 0 | +| f-t-minified.js-nowrap | before | 8.9/9.1/9.9/9.9 | 8.7/9.0/9.8/9.8 | - | 0 | 0 | +| | after | 8.7/9.0/9.7/9.7 | 3.3/8.8/10.7/11.0 | 16.0/16.7/17.9/18.3 | 0 | 0 | +| gl-gh-minified.js-nowrap | before | 9.1/9.2/10.4/10.4 | 8.9/9.1/10.3/10.3 | - | 0 | 0 | +| | after | 8.9/9.2/9.3/9.3 | 2.8/8.9/9.7/9.7 | 16.1/16.8/18.2/18.2 | 0 | 0 | +| insert-end-minified.js-nowrap | before | 8.8/12.1/13.8/13.8 | 8.5/11.0/13.7/13.7 | 4.5/8.9/11.9/11.9 | 0 | 0 | +| | after | 2.1/7.3/9.0/9.0 | 2.2/7.1/9.1/9.4 | 16.6/16.8/16.9/17.1 | 0 | 0 | +| insert-middle-minified.js-nowrap | before | 185.1/192.3/201.4/201.4 | 3.4/172.0/182.2/182.2 | 4.0/8.8/9.4/9.4 | 0 | 0 | +| | after | 16.1/26.7/29.1/29.1 | 8.5/15.2/18.4/18.4 | 16.6/16.9/17.2/17.2 | 0 | 0 | +| sweep-L-W-minified.js-nowrap | before | 11.2/19.6/26.4/26.4 | 7.0/10.2/13.9/14.2 | 5.6/9.6/11.6/12.2 | 0 | 0 | +| | after | 11.9/20.0/26.9/26.9 | 3.9/10.9/13.9/26.2 | 16.6/16.8/17.1/17.1 | 1 | 0 | +| w-held-oneline.json-nowrap | before | 8.8/16.9/21.6/21.6 | 3.3/7.9/8.9/13.2 | 4.2/8.9/9.9/10.6 | 0 | 0 | +| | after | 8.1/20.2/23.4/23.4 | 2.3/5.8/9.3/9.3 | 16.5/16.7/19.7/19.7 | 0 | 0 | +| e-held-oneline.json-nowrap | before | 15.8/20.7/24.4/24.4 | 4.5/8.0/9.4/9.4 | - | 0 | 0 | +| | after | 15.7/20.7/24.5/24.5 | 3.8/6.3/8.5/8.5 | - | 0 | 0 | +| l-held-oneline.json-nowrap | before | 15.7/19.1/29.3/29.3 | 3.6/7.4/9.1/9.1 | - | 0 | 0 | +| | after | 15.8/20.5/25.1/25.1 | 3.8/7.4/10.1/10.1 | - | 0 | 0 | +| dollar-zero-oneline.json-nowrap | before | 9.9/9.9/9.9/9.9 | 9.6/9.7/9.7/9.7 | - | 0 | 0 | +| | after | 9.8/10.2/10.2/10.2 | 4.5/9.6/12.6/12.6 | 16.4/16.8/17.8/17.8 | 0 | 0 | +| f-t-oneline.json-nowrap | before | 9.7/9.8/10.0/10.0 | 9.6/9.7/9.9/9.9 | - | 0 | 0 | +| | after | 9.4/9.6/10.1/10.1 | 3.2/9.4/13.1/13.2 | 16.1/16.8/18.2/18.6 | 0 | 0 | +| gl-gh-oneline.json-nowrap | before | 9.6/9.9/10.0/10.0 | 9.5/9.7/9.8/9.8 | - | 0 | 0 | +| | after | 9.6/10.3/10.4/10.4 | 2.7/9.4/10.2/10.2 | 16.5/16.8/22.1/22.1 | 0 | 0 | +| insert-end-oneline.json-nowrap | before | 9.5/13.3/15.2/15.2 | 9.2/11.7/15.1/15.1 | 5.2/9.5/12.7/12.7 | 0 | 0 | +| | after | 2.3/7.3/10.9/10.9 | 2.3/7.0/9.9/10.8 | 16.6/16.8/17.0/17.8 | 0 | 0 | +| insert-middle-oneline.json-nowrap | before | 209.8/216.8/218.7/218.7 | 3.0/195.5/196.9/196.9 | 4.0/9.0/9.4/9.4 | 0 | 0 | +| | after | 23.1/29.0/35.4/35.4 | 10.3/21.1/28.7/28.7 | 16.6/16.8/17.9/17.9 | 0 | 0 | +| sweep-L-W-oneline.json-nowrap | before | 10.3/14.9/24.9/24.9 | 6.6/11.0/14.2/14.8 | 4.4/9.3/14.3/14.4 | 0 | 0 | +| | after | 10.0/15.6/21.7/21.7 | 4.9/11.6/15.0/15.5 | 16.6/16.8/18.2/18.2 | 0 | 0 | +| w-held-hugelines.txt-nowrap | before | 12.8/18.8/22.8/22.8 | 4.5/8.1/11.5/12.7 | 4.2/8.9/9.9/11.2 | 0 | 0 | +| | after | 9.8/18.4/20.3/20.3 | 2.4/7.9/11.2/11.2 | 16.5/16.8/18.2/18.2 | 0 | 0 | +| e-held-hugelines.txt-nowrap | before | 15.7/20.0/20.9/20.9 | 6.0/9.7/11.9/11.9 | - | 0 | 0 | +| | after | 14.9/19.2/20.8/20.8 | 5.6/9.7/10.7/10.7 | - | 0 | 0 | +| l-held-hugelines.txt-nowrap | before | 15.4/20.1/25.1/25.1 | 5.3/10.0/13.7/13.7 | - | 0 | 0 | +| | after | 15.6/19.4/21.8/21.8 | 5.2/9.2/11.3/11.3 | - | 0 | 0 | +| dollar-zero-hugelines.txt-nowrap | before | 9.7/9.8/9.8/9.8 | 9.5/9.7/9.7/9.7 | - | 0 | 0 | +| | after | 9.4/9.4/9.4/9.4 | 3.1/8.5/9.3/9.3 | 16.6/16.8/16.9/16.9 | 0 | 0 | +| f-t-hugelines.txt-nowrap | before | 9.4/10.4/11.4/11.4 | 9.3/10.3/11.2/11.2 | - | 0 | 0 | +| | after | 9.2/9.4/9.9/9.9 | 2.8/9.0/9.4/9.8 | 16.3/16.7/16.8/17.7 | 0 | 0 | +| gl-gh-hugelines.txt-nowrap | before | 9.4/9.9/10.1/10.1 | 9.3/9.7/9.9/9.9 | - | 0 | 0 | +| | after | 9.3/9.9/10.9/10.9 | 3.0/9.2/10.7/10.7 | 16.3/16.7/17.0/17.0 | 0 | 0 | +| insert-end-hugelines.txt-nowrap | before | 9.6/13.7/15.1/15.1 | 9.0/12.6/14.9/14.9 | 6.0/9.3/10.3/10.3 | 0 | 0 | +| | after | 2.3/7.1/9.4/9.4 | 2.3/6.8/9.2/9.2 | 16.6/16.7/16.8/16.8 | 0 | 0 | +| insert-middle-hugelines.txt-nowrap | before | 18.4/22.5/26.1/26.1 | 4.7/8.8/10.6/10.6 | 5.0/9.2/10.0/10.0 | 0 | 0 | +| | after | 17.0/19.9/23.0/23.0 | 5.9/8.6/12.4/12.4 | 16.6/16.9/17.1/17.1 | 0 | 0 | +| sweep-L-W-hugelines.txt-nowrap | before | 11.9/18.7/24.0/24.0 | 6.2/9.1/14.4/14.5 | 4.2/9.0/9.8/9.8 | 0 | 0 | +| | after | 10.2/18.1/22.5/22.5 | 7.0/11.1/14.1/14.5 | 16.6/16.9/17.1/17.1 | 0 | 0 | + +#### GUI Debug: `scroll` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| notches | before | 8.2/14.4/14.4/14.4 | 3.4/7.8/9.3/14.3 | 4.4/8.6/10.1/10.4 | 7 | 0 | +| | after | 3.5/19.8/19.8/19.8 | 3.0/3.5/19.8/19.8 | 16.7/17.0/17.6/17.6 | 7 | 0 | +| spin | before | 3.6/8.8/15.8/15.8 | 3.5/8.6/14.0/15.7 | 4.2/8.9/12.7/14.1 | 35 | 0 | +| | after | 4.3/8.4/20.4/20.4 | 4.3/7.7/20.4/20.4 | 10.1/16.7/17.1/17.1 | 34 | 0 | +| pages | before | 15.4/25.7/40.2/40.2 | 15.0/25.2/32.8/32.8 | - | 3787 | 0 | +| | after | 15.0/22.0/29.7/29.7 | 3.0/7.1/17.6/21.3 | 16.6/16.8/17.3/18.0 | 3607 | 0 | +| retarget | before | 16.7/33.3/33.3/33.3 | 16.3/32.9/32.9/32.9 | - | 150 | 0 | +| | after | 9.6/23.7/23.7/23.7 | 3.0/6.2/23.2/23.2 | 16.6/16.8/16.8/16.8 | 92 | 0 | +| cursor | before | 12.2/15.6/16.2/16.2 | 6.5/11.9/15.4/15.5 | 5.6/9.7/12.5/15.0 | 0 | 0 | +| | after | 3.8/14.9/18.4/18.4 | 3.6/6.3/17.1/17.7 | 16.6/16.8/17.2/18.0 | 0 | 0 | + +#### GUI Debug: `stress` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| spin | before | 3.6/8.9/25.4/33.7 | 3.6/8.8/17.2/33.7 | 4.0/9.3/16.7/33.7 | 188 | 3 | +| | after | 3.7/7.9/13.1/23.3 | 3.6/7.3/11.9/23.2 | 8.2/13.1/16.7/16.8 | 175 | 0 | +| held-ctrl-d | before | 8.3/33.2/45.9/45.9 | 8.1/32.8/45.5/45.5 | - | 539 | 0 | +| | after | 4.3/8.5/24.4/24.4 | 3.7/7.5/12.6/24.0 | 16.6/17.2/18.4/23.1 | 508 | 0 | +| held-j | before | 11.9/15.6/30.7/30.7 | 11.5/15.2/30.3/30.3 | - | 35 | 0 | +| | after | 3.6/8.3/25.0/25.0 | 3.3/7.3/12.2/24.7 | 16.6/16.8/17.9/22.4 | 33 | 0 | +| held-pagedown | before | 9.7/38.3/63.4/63.4 | 9.7/38.0/63.1/63.1 | - | 758 | 0 | +| | after | 4.8/13.1/111.1/111.1 | 4.6/8.7/82.3/111.1 | 16.6/17.5/83.3/111.2 | 703 | 8 | +| far | before | 15.2/56.1/65.8/65.8 | 14.8/32.4/35.9/35.9 | - | 64673 | 0 | +| | after | 15.3/30.0/39.0/39.0 | 3.2/8.7/22.6/23.3 | 16.6/16.8/17.1/17.1 | 60139 | 0 | + +#### GUI Debug: `jumps` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| counted-G-big | before | 13.0/41.0/46.9/46.9 | 6.9/20.5/40.0/40.0 | 4.6/9.2/12.0/12.0 | 9607 | 0 | +| | after | 12.4/26.7/32.5/32.5 | 3.0/11.1/19.3/24.9 | 16.6/16.8/17.0/17.0 | 9013 | 0 | +| pages-up-big | before | 18.7/43.6/56.7/56.7 | 18.3/43.2/56.3/56.3 | - | 1784 | 0 | +| | after | 20.1/28.3/46.7/46.7 | 5.0/8.7/27.9/46.2 | 16.6/16.8/22.3/22.4 | 1709 | 0 | +| search-n-big | before | 12.7/14.8/33.3/33.3 | 4.3/9.3/14.2/27.8 | 4.6/9.3/18.2/19.2 | 1254 | 0 | +| | after | 11.9/14.5/24.7/24.7 | 4.3/9.5/14.0/14.0 | 16.6/16.8/22.7/24.4 | 1255 | 0 | +| rail-big | before | 8.2/37.9/50.1/50.1 | 3.5/7.9/37.0/49.3 | 4.4/8.7/10.4/10.9 | 3032 | 0 | +| | after | 9.0/35.6/38.7/38.7 | 3.2/7.1/34.9/38.0 | 16.6/16.8/22.3/22.6 | 3030 | 0 | +| query-ctrl-n-big | before | 22.2/39.4/40.3/40.3 | 7.2/21.8/38.3/38.9 | 7.1/15.5/31.1/31.1 | 628 | 2 | +| | after | 7.0/22.4/28.3/28.3 | 3.6/8.8/18.9/19.4 | 16.6/16.8/26.4/27.4 | 727 | 3 | +| star-big | before | 12.8/36.9/36.9/36.9 | 7.2/12.3/19.6/19.6 | 8.2/10.1/17.2/17.2 | 853 | 0 | +| | after | 11.6/44.7/44.7/44.7 | 3.1/11.0/21.8/21.8 | 16.6/16.9/17.0/17.0 | 853 | 0 | +| jumplist-big | before | 33.4/41.0/41.4/41.4 | 8.1/32.9/41.0/41.0 | 15.9/20.3/21.2/21.2 | 4759 | 0 | +| | after | 17.9/23.4/23.5/23.5 | 3.0/12.4/23.0/23.0 | 16.6/16.8/18.4/20.1 | 7394 | 0 | +| insert-big | before | 9.3/14.9/29.9/247.9 | 6.5/13.5/23.3/247.4 | 11.8/23.0/31.6/35.5 | 42 | 12 | +| | after | 10.3/17.0/30.5/280.9 | 3.4/11.4/22.9/280.4 | 16.6/19.1/26.5/33.4 | 58 | 13 | +| counted-G-small | before | 13.4/26.4/26.7/26.7 | 12.6/25.0/26.1/26.1 | - | 384 | 0 | +| | after | 11.4/22.9/29.3/29.3 | 3.9/9.7/27.8/27.8 | 16.6/16.8/18.3/18.3 | 363 | 0 | +| pages-up-small | before | 21.8/34.4/36.4/36.4 | 21.1/33.6/35.6/35.6 | - | 78 | 0 | +| | after | 23.0/35.3/35.9/35.9 | 3.1/7.7/34.6/35.2 | 16.6/16.8/17.4/17.9 | 75 | 0 | +| search-n-small | before | 15.2/20.5/25.3/25.3 | 3.2/14.4/20.2/24.5 | 4.0/9.0/31.3/31.3 | 44 | 1 | +| | after | 16.2/17.5/21.1/21.1 | 3.0/16.0/21.2/21.2 | 16.6/16.9/31.3/31.3 | 45 | 1 | +| rail-small | before | 14.3/16.1/18.2/18.2 | 14.1/15.1/18.2/18.2 | - | 71 | 0 | +| | after | 14.5/17.5/21.8/21.8 | 6.8/16.0/20.3/20.3 | 16.6/16.8/17.0/17.0 | 72 | 0 | +| query-ctrl-n-small | before | 15.0/17.0/19.5/19.5 | 4.2/14.3/17.4/17.9 | 4.8/9.1/19.0/19.0 | 91 | 0 | +| | after | 12.8/17.4/17.4/17.4 | 3.4/13.6/16.7/16.7 | 16.6/16.8/25.3/25.3 | 94 | 1 | +| star-small | before | 15.9/28.3/28.3/28.3 | 6.5/14.1/27.5/27.5 | 4.7/8.8/13.5/13.5 | 166 | 0 | +| | after | 17.3/19.5/19.5/19.5 | 3.0/12.1/18.5/18.5 | 16.6/16.8/17.1/17.1 | 155 | 0 | +| look-small | before | 26.1/26.1/26.1/26.1 | 24.7/24.7/24.7/24.7 | - | 0 | 0 | +| | after | 15.4/20.6/20.6/20.6 | 7.7/14.3/20.4/20.4 | 16.7/16.8/16.9/16.9 | 81 | 0 | +| jumplist-small | before | 16.3/28.9/29.2/29.2 | 9.8/25.2/28.3/28.3 | 16.7/18.8/21.2/21.2 | 81 | 0 | +| | after | 17.1/21.5/27.1/27.1 | 4.7/12.1/20.8/26.3 | 16.6/17.0/18.8/19.7 | 87 | 0 | +| insert-small | before | 13.1/19.4/32.8/41.8 | 7.7/17.0/29.2/41.5 | 13.0/24.1/34.0/38.9 | 27 | 13 | +| | after | 9.6/20.6/28.4/61.6 | 4.9/14.0/23.4/60.6 | 16.4/18.5/32.4/73.9 | 37 | 35 | +| look-new-pane | before | 14.9/14.9/14.9/14.9 | 8.2/8.7/8.8/8.8 | 16.8/17.3/17.9/17.9 | 0 | 0 | +| | after | 24.9/24.9/24.9/24.9 | 18.4/18.4/18.4/18.4 | - | 0 | 0 | + +#### GUI Debug: `kinds` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| generated-parser.c | before | 7.3/22.4/29.5/103.2 | 3.6/11.7/24.9/86.5 | 4.2/8.7/10.1/13.0 | 3787 | 0 | +| | after | 3.9/7.9/26.6/39.3 | 3.2/6.8/17.6/31.5 | 16.5/16.9/18.4/18.8 | 3789 | 0 | +| commands.rs | before | 7.4/21.6/32.5/33.8 | 3.8/11.8/30.0/33.4 | 4.4/8.9/10.8/15.1 | 1694 | 0 | +| | after | 4.3/8.7/23.0/35.4 | 3.8/8.0/12.8/18.8 | 16.5/17.2/18.5/23.3 | 1690 | 0 | +| tables.py | before | 6.8/25.3/32.2/77.5 | 3.6/12.0/29.5/69.8 | 4.2/8.7/14.5/16.6 | 2444 | 0 | +| | after | 3.9/8.9/25.5/26.7 | 3.2/7.8/17.2/24.8 | 16.5/16.9/17.9/23.1 | 2442 | 0 | +| jquery.js | before | 7.6/18.8/28.0/1979.3 | 4.3/12.1/23.3/1958.4 | 4.2/8.7/10.6/12.6 | 2217 | 0 | +| | after | 3.8/8.4/27.9/119.7 | 3.2/7.1/14.6/98.3 | 16.5/16.9/17.6/17.8 | 2149 | 0 | +| minified.js | before | 8.4/18.7/29.4/34.0 | 4.1/12.4/17.2/17.5 | 4.4/8.4/9.1/9.1 | 0 | 0 | +| | after | 7.7/19.3/28.9/32.5 | 4.3/13.1/16.6/18.4 | 16.6/16.8/17.2/17.2 | 0 | 0 | +| grammar.json | before | 7.8/17.3/23.9/1870.4 | 3.9/12.2/21.5/1850.4 | 4.4/8.7/10.1/17.2 | 2351 | 0 | +| | after | 3.5/8.4/26.5/84.4 | 3.2/7.3/14.2/61.4 | 16.5/16.8/17.4/18.4 | 2279 | 0 | +| oneline.json | before | 7.2/16.2/45.4/92.1 | 6.0/13.0/27.4/76.5 | 4.5/9.1/45.4/45.4 | 4 | 1 | +| | after | 7.8/14.1/180.6/189.0 | 6.5/13.1/78.9/188.1 | 16.6/16.8/16.9/16.9 | 4 | 0 | +| CHANGELOG.md | before | 10.7/58.2/72.2/72.5 | 4.7/12.8/66.5/72.5 | 4.4/8.9/58.8/72.5 | 715 | 7 | +| | after | 7.2/60.5/74.0/75.3 | 4.7/17.0/70.5/75.1 | 16.6/18.1/73.5/75.4 | 713 | 31 | +| cascade.html | before | 8.5/17.8/25.9/119.6 | 4.0/13.8/19.6/83.9 | 4.2/8.8/10.6/11.3 | 643 | 0 | +| | after | 3.9/8.6/19.7/72.3 | 3.3/7.0/18.1/36.4 | 16.5/16.8/18.8/22.8 | 642 | 0 | +| simdutf.cpp | before | 6.4/29.0/58.8/65.4 | 3.3/11.2/52.7/64.7 | 4.2/8.6/9.6/12.8 | 9852 | 0 | +| | after | 4.0/12.9/113.9/115.2 | 3.8/7.9/55.9/114.8 | 16.5/16.8/56.5/115.3 | 9862 | 9 | +| parser.ts | before | 8.6/17.7/25.6/27.0 | 3.7/13.4/19.8/26.0 | 4.2/8.8/10.4/13.8 | 1776 | 0 | +| | after | 3.7/8.8/21.8/22.2 | 3.1/7.0/16.2/21.1 | 16.5/16.9/18.9/22.6 | 1775 | 0 | +| fcnal-test.sh | before | 8.1/17.7/27.8/30.8 | 4.0/11.9/21.7/27.1 | 4.2/8.8/11.1/14.0 | 1034 | 0 | +| | after | 4.0/8.7/18.6/82.3 | 3.5/7.3/14.4/62.3 | 16.6/16.8/18.1/23.2 | 1034 | 0 | +| data.go | before | 8.6/18.7/24.3/42.6 | 3.8/13.6/21.5/40.0 | 4.2/8.8/12.8/19.1 | 3897 | 0 | +| | after | 4.2/9.7/19.1/42.0 | 3.4/7.4/17.0/39.4 | 16.5/16.9/22.8/24.1 | 3898 | 0 | +| guide.typ | before | 7.8/31.1/43.8/52.2 | 4.0/11.4/37.3/50.9 | 4.4/9.1/33.2/37.4 | 117 | 6 | +| | after | 4.9/24.8/46.6/54.8 | 3.9/11.3/37.1/53.5 | 16.5/16.8/40.5/46.7 | 117 | 21 | +| unicode.txt | before | 8.7/19.2/92.4/435.3 | 4.2/10.3/17.4/146.9 | 4.4/8.9/10.2/11.5 | 4510 | 0 | +| | after | 4.0/9.2/92.9/438.8 | 3.2/6.8/16.3/146.3 | 16.5/16.8/17.7/18.2 | 4505 | 0 | +| big.log | before | 8.3/17.6/61.1/188.2 | 4.2/12.7/21.5/25.7 | 4.3/8.7/9.9/14.9 | 69103 | 0 | +| | after | 6.6/14.8/73.4/201.2 | 4.8/11.2/15.8/24.4 | 16.5/17.0/24.5/28.9 | 69008 | 3 | +| words.txt | before | 7.9/15.7/22.7/27.6 | 3.3/11.4/16.4/17.7 | 4.1/8.7/10.2/16.5 | 92552 | 0 | +| | after | 3.3/8.5/25.1/47.8 | 3.0/7.1/15.1/17.6 | 16.5/16.8/17.7/19.0 | 92274 | 0 | +| hugelines.txt | before | 8.9/15.3/34.3/1973.2 | 7.0/13.3/16.5/1963.1 | 5.3/16.7/25.9/25.9 | 12 | 1 | +| | after | 7.9/15.8/33.0/96.5 | 6.2/13.8/17.4/90.4 | 16.7/18.9/22.1/22.1 | 12 | 0 | +| minified.js! | before | 9.1/21.0/43.3/1875.3 | 5.8/15.0/24.5/1852.3 | 5.0/11.7/17.4/17.4 | 0 | 0 | +| | after | 8.4/21.5/46.2/87.9 | 5.0/14.6/21.4/64.6 | 16.6/16.8/17.0/17.0 | 0 | 0 | +| oneline.json! | before | 7.8/18.2/47.5/48.0 | 6.6/12.7/16.8/48.0 | 7.5/9.3/48.1/48.1 | 0 | 1 | +| | after | 7.6/17.1/72.2/193.8 | 7.0/12.9/21.4/182.3 | 16.6/16.8/22.5/22.5 | 0 | 0 | +| hugelines.txt! | before | 8.1/17.8/33.0/41.8 | 6.1/11.4/16.6/18.4 | 6.3/10.2/11.8/12.7 | 2 | 0 | +| | after | 6.6/18.7/32.3/46.7 | 5.6/11.3/14.9/22.2 | 16.6/16.9/23.9/26.1 | 2 | 1 | + +#### GUI Debug: `panes` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| command-cat | before | 8.9/19.7/34.8/35.0 | 4.6/9.1/15.7/27.5 | 7.0/37.5/58.1/58.1 | 4509 | 5 | +| | after | 7.8/19.3/36.5/45.4 | 4.1/9.2/17.9/30.8 | 16.6/37.9/53.8/53.8 | 4501 | 6 | +| command-yes | before | 8.0/17.0/27.5/34.5 | 6.6/14.5/17.5/24.1 | 4.4/34.9/44.9/44.9 | 4616 | 7 | +| | after | 7.6/15.7/34.5/35.0 | 6.4/13.6/17.8/22.8 | 16.6/34.5/58.8/58.8 | 4545 | 7 | +| pager | before | 7.5/14.6/18.6/20.2 | 6.5/13.7/17.1/18.0 | 4.3/8.7/46.2/46.2 | 0 | 1 | +| | after | 8.6/16.2/19.7/19.8 | 7.6/14.8/19.0/19.2 | 16.6/16.9/47.3/47.3 | 0 | 1 | +| directory | before | 7.6/15.3/18.7/19.2 | 5.0/12.6/17.7/18.6 | 4.7/9.2/14.5/16.6 | 2 | 0 | +| | after | 5.4/14.4/18.6/24.6 | 3.9/12.9/17.3/21.6 | 16.6/16.8/17.1/17.1 | 2 | 0 | +| pdf | before | 7.7/57.3/138.0/190.3 | 6.7/13.8/113.8/174.4 | 4.3/8.9/13.5/13.5 | 0 | 0 | +| | after | 8.0/59.7/155.2/161.8 | 8.1/41.0/134.9/161.5 | 16.6/16.8/16.9/16.9 | 0 | 0 | +| image | before | 7.5/16.5/128.7/304.3 | 6.8/15.2/18.7/301.1 | 5.4/9.1/10.4/10.4 | 0 | 0 | +| | after | 7.9/14.2/17.2/18.3 | 6.8/13.9/17.0/133.0 | 16.7/17.0/146.3/146.3 | 0 | 1 | +| help | before | 7.8/14.4/18.8/19.8 | 5.2/12.4/17.3/18.2 | 4.7/8.8/12.2/16.3 | 69 | 0 | +| | after | 3.3/12.7/17.2/17.4 | 3.0/7.9/16.1/17.2 | 16.5/16.8/17.5/18.7 | 69 | 0 | +| changelog | before | 8.1/16.7/19.3/20.2 | 3.8/12.9/18.2/19.5 | 4.3/8.9/10.6/14.2 | 220 | 0 | +| | after | 3.9/8.7/16.2/25.1 | 3.7/7.7/14.6/23.7 | 16.6/16.8/17.4/22.5 | 220 | 0 | +| query-typing | before | 13.1/16.8/41.6/41.6 | 6.5/12.4/38.2/102.2 | 7.6/17.3/27.9/108.3 | 0 | 2 | +| | after | 13.4/50.3/266.2/266.2 | 3.1/13.0/262.6/262.6 | 16.6/17.0/62.1/62.1 | 17 | 2 | + +#### GUI Debug: `longlines` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| w-held-minified.js-wrap | before | 3.6/8.6/19.8/19.8 | 3.3/8.2/9.1/19.0 | 4.2/9.0/9.7/10.4 | 0 | 0 | +| | after | 3.5/7.4/12.3/12.3 | 3.2/7.2/10.8/11.6 | 16.6/16.9/17.4/17.4 | 0 | 0 | +| e-held-minified.js-wrap | before | 3.7/11.5/15.0/15.0 | 3.3/8.1/13.9/14.4 | 4.2/9.0/10.3/11.4 | 0 | 0 | +| | after | 3.3/7.3/8.9/8.9 | 3.1/6.9/8.5/8.8 | 16.6/16.8/17.0/17.1 | 0 | 0 | +| l-held-minified.js-wrap | before | 8.1/17.0/19.1/19.1 | 4.6/10.3/17.6/18.4 | 4.7/9.2/11.6/13.4 | 0 | 0 | +| | after | 3.2/7.4/8.6/8.6 | 3.1/7.2/8.5/8.5 | 16.6/16.7/17.5/17.7 | 0 | 0 | +| dollar-zero-minified.js-wrap | before | 7.3/7.4/7.4/7.4 | 6.5/6.6/6.6/6.6 | - | 0 | 0 | +| | after | 14.6/14.7/14.7/14.7 | 2.8/9.0/13.7/13.7 | 16.6/16.8/17.4/17.4 | 0 | 0 | +| f-t-minified.js-wrap | before | 14.3/16.7/16.9/16.9 | 13.6/16.1/16.2/16.2 | - | 0 | 0 | +| | after | 14.4/20.7/20.7/20.7 | 3.0/13.8/20.1/20.1 | 16.4/16.8/17.6/17.7 | 0 | 0 | +| gl-gh-minified.js-wrap | before | 14.0/16.4/16.5/16.5 | 13.3/15.6/15.9/15.9 | - | 0 | 0 | +| | after | 13.8/20.2/20.4/20.4 | 3.2/13.1/19.7/19.7 | 16.5/16.7/17.3/17.3 | 0 | 0 | +| insert-end-minified.js-wrap | before | 14.9/18.5/20.1/20.1 | 12.1/17.1/19.5/19.5 | 7.1/9.8/10.9/10.9 | 0 | 0 | +| | after | 3.3/8.6/14.6/14.6 | 3.1/8.3/13.6/13.8 | 16.5/16.8/17.3/18.2 | 0 | 0 | +| insert-middle-minified.js-wrap | before | 14.1/1994.4/1994.4/1994.4 | 6.9/13.5/1963.0/1963.0 | 6.7/11.1/11.5/11.5 | 0 | 0 | +| | after | 82.9/83.5/95.1/95.1 | 79.0/81.3/84.2/84.2 | 16.4/16.8/17.0/17.0 | 0 | 0 | +| sweep-L-W-minified.js-wrap | before | 13.0/19.3/1858.0/1858.0 | 3.6/12.4/18.7/1848.9 | 4.4/8.7/10.0/10.0 | 0 | 0 | +| | after | 13.4/17.0/71.2/71.2 | 12.4/15.5/60.7/84.4 | 16.6/16.8/84.5/84.5 | 0 | 1 | +| w-held-oneline.json-wrap | before | 3.8/8.3/9.3/9.3 | 3.3/7.8/8.6/9.1 | 4.1/8.8/9.3/9.8 | 0 | 0 | +| | after | 3.7/8.1/19.4/19.4 | 3.4/7.4/12.6/18.4 | 16.6/16.9/17.5/22.5 | 0 | 0 | +| e-held-oneline.json-wrap | before | 3.7/8.1/11.7/11.7 | 3.3/7.8/8.4/11.3 | 4.2/8.8/9.3/9.8 | 0 | 0 | +| | after | 3.6/7.2/9.1/9.1 | 3.4/7.0/8.5/8.9 | 16.6/16.9/17.1/17.9 | 0 | 0 | +| l-held-oneline.json-wrap | before | 8.1/18.0/21.3/21.3 | 3.7/8.6/18.9/20.5 | 4.3/8.9/10.8/13.0 | 0 | 0 | +| | after | 3.7/7.9/9.2/9.2 | 3.4/7.4/9.0/9.0 | 16.7/16.9/17.6/22.5 | 0 | 0 | +| dollar-zero-oneline.json-wrap | before | 7.6/12.9/12.9/12.9 | 6.8/12.0/12.0/12.0 | - | 0 | 0 | +| | after | 18.1/18.7/18.7/18.7 | 2.9/16.3/17.7/17.7 | 16.7/16.8/16.9/16.9 | 0 | 0 | +| f-t-oneline.json-wrap | before | 14.2/17.3/17.6/17.6 | 13.4/16.4/16.7/16.7 | - | 0 | 0 | +| | after | 18.8/20.1/20.3/20.3 | 5.1/18.0/19.4/19.5 | 15.5/16.8/16.9/17.0 | 0 | 0 | +| gl-gh-oneline.json-wrap | before | 13.8/16.8/17.0/17.0 | 12.9/15.9/16.1/16.1 | - | 0 | 0 | +| | after | 19.8/20.4/20.6/20.6 | 6.7/18.1/19.7/19.7 | 15.4/16.8/17.2/17.2 | 0 | 0 | +| insert-end-oneline.json-wrap | before | 15.4/18.1/21.5/21.5 | 13.4/17.2/20.7/20.7 | 8.6/14.1/20.7/20.7 | 0 | 0 | +| | after | 3.3/8.2/20.3/20.3 | 3.1/8.1/17.5/19.4 | 16.6/16.8/18.0/18.2 | 0 | 0 | +| insert-middle-oneline.json-wrap | before | 15.1/1887.6/1887.6/1887.6 | 7.1/18.2/1844.0/1844.0 | 7.8/14.6/17.4/17.4 | 0 | 0 | +| | after | 82.1/177.2/182.1/182.1 | 14.4/171.6/176.3/176.3 | 16.6/16.8/16.8/16.8 | 0 | 0 | +| sweep-L-W-oneline.json-wrap | before | 15.4/23.1/49.8/49.8 | 3.5/11.2/18.3/19.6 | 4.4/8.6/10.5/10.6 | 6 | 0 | +| | after | 13.9/18.3/167.2/167.2 | 10.2/15.2/19.4/167.0 | 16.6/16.8/167.2/167.2 | 5 | 1 | +| w-held-hugelines.txt-wrap | before | 3.4/8.6/21.4/21.4 | 3.3/8.2/9.1/20.3 | 4.3/9.0/10.2/13.5 | 0 | 0 | +| | after | 3.3/7.7/11.9/11.9 | 3.2/7.4/10.8/11.3 | 16.6/16.8/17.2/17.8 | 0 | 0 | +| e-held-hugelines.txt-wrap | before | 8.0/14.5/20.0/20.0 | 3.8/9.3/18.5/18.9 | 4.4/9.2/10.8/11.6 | 0 | 0 | +| | after | 6.0/17.2/21.2/21.2 | 4.2/14.8/19.9/19.9 | 16.6/16.8/17.0/17.0 | 0 | 0 | +| l-held-hugelines.txt-wrap | before | 14.4/18.8/20.4/20.4 | 13.4/17.8/19.4/19.4 | - | 0 | 0 | +| | after | 14.0/16.8/20.8/20.8 | 13.0/15.7/19.7/19.7 | - | 0 | 0 | +| dollar-zero-hugelines.txt-wrap | before | 15.7/16.6/16.6/16.6 | 14.5/15.5/15.5/15.5 | - | 0 | 0 | +| | after | 18.7/19.3/19.3/19.3 | 7.1/17.6/18.2/18.2 | 16.5/16.8/16.8/16.8 | 0 | 0 | +| f-t-hugelines.txt-wrap | before | 16.1/16.4/16.8/16.8 | 15.1/15.3/15.7/15.7 | - | 0 | 0 | +| | after | 20.1/20.3/22.6/22.6 | 4.8/19.1/20.5/21.6 | 14.7/16.8/16.9/17.3 | 0 | 0 | +| gl-gh-hugelines.txt-wrap | before | 13.9/16.9/16.9/16.9 | 12.9/15.7/15.8/15.8 | - | 0 | 0 | +| | after | 18.8/19.6/20.0/20.0 | 6.8/15.4/19.0/19.0 | 15.1/16.8/17.3/17.3 | 0 | 0 | +| insert-end-hugelines.txt-wrap | before | 15.4/19.2/21.1/21.1 | 14.4/18.2/20.1/20.1 | - | 0 | 0 | +| | after | 3.3/8.1/18.4/18.4 | 3.2/7.6/10.2/17.3 | 16.6/16.8/16.9/17.3 | 0 | 0 | +| insert-middle-hugelines.txt-wrap | before | 17.6/21.3/26.2/26.2 | 13.0/16.9/20.2/20.2 | - | 0 | 0 | +| | after | 16.7/21.7/24.6/24.6 | 12.2/16.5/19.2/19.2 | - | 0 | 0 | +| sweep-L-W-hugelines.txt-wrap | before | 14.3/17.8/32.3/32.3 | 8.5/16.1/20.0/26.1 | 7.4/16.7/18.3/18.3 | 0 | 0 | +| | after | 14.0/18.6/30.0/30.0 | 11.4/15.1/19.1/30.0 | 16.7/16.8/17.0/17.0 | 0 | 0 | +| w-held-minified.js-nowrap | before | 16.8/32.8/34.0/34.0 | 15.6/15.8/27.7/27.7 | 16.7/16.9/33.3/33.3 | 0 | 5 | +| | after | 14.3/29.1/30.6/30.6 | 9.5/13.5/20.8/20.8 | 16.6/17.1/32.3/32.3 | 0 | 4 | +| e-held-minified.js-nowrap | before | 28.0/31.1/33.5/33.5 | 11.6/14.4/17.1/17.1 | - | 0 | 0 | +| | after | 25.9/30.0/32.7/32.7 | 9.5/13.7/16.4/16.4 | - | 0 | 0 | +| l-held-minified.js-nowrap | before | 27.5/31.5/33.0/33.0 | 11.0/15.2/16.4/16.4 | - | 0 | 0 | +| | after | 25.3/29.3/30.6/30.6 | 8.9/13.0/14.3/14.3 | - | 0 | 0 | +| dollar-zero-minified.js-nowrap | before | 24.5/25.0/25.0/25.0 | 23.4/23.8/23.8/23.8 | - | 0 | 0 | +| | after | 23.3/24.4/24.4/24.4 | 8.5/13.3/23.2/23.2 | 16.6/17.0/18.0/18.0 | 0 | 0 | +| f-t-minified.js-nowrap | before | 29.4/35.6/36.6/36.6 | 28.4/34.6/36.2/36.2 | - | 0 | 0 | +| | after | 31.3/31.5/31.6/31.6 | 8.6/30.2/30.5/30.6 | 16.5/16.8/17.9/18.1 | 0 | 0 | +| gl-gh-minified.js-nowrap | before | 24.5/35.6/35.7/35.7 | 23.5/34.5/34.6/34.6 | - | 0 | 0 | +| | after | 21.9/31.0/31.8/31.8 | 9.2/20.8/30.8/30.8 | 16.6/16.7/17.4/17.4 | 0 | 0 | +| insert-end-minified.js-nowrap | before | 19.4/25.7/35.6/35.6 | 18.4/24.3/34.5/34.5 | 16.7/17.9/17.9/17.9 | 0 | 0 | +| | after | 8.8/14.5/23.9/23.9 | 8.6/12.7/22.5/22.8 | 16.6/16.8/22.4/22.6 | 0 | 0 | +| insert-middle-minified.js-nowrap | before | 16.6/1994.8/1994.8/1994.8 | 13.9/18.2/1955.8/1955.8 | 15.3/18.5/30.3/30.3 | 0 | 1 | +| | after | 166.7/251.2/253.8/253.8 | 8.6/153.7/166.3/166.3 | 16.5/16.8/18.0/18.0 | 0 | 0 | +| sweep-L-W-minified.js-nowrap | before | 24.7/2780.7/2780.7/2780.7 | 15.6/16.3/1963.0/1963.0 | 16.7/16.8/16.8/16.8 | 0 | 0 | +| | after | 16.4/26.3/84.3/84.3 | 11.0/14.2/18.3/77.0 | 16.6/16.9/17.1/17.1 | 1 | 0 | +| w-held-oneline.json-nowrap | before | 32.7/33.7/34.4/34.4 | 15.3/15.7/24.8/24.8 | 16.7/17.8/33.9/33.9 | 0 | 5 | +| | after | 32.8/33.5/34.7/34.7 | 15.1/15.4/22.0/22.0 | 16.7/18.0/33.4/33.4 | 0 | 5 | +| e-held-oneline.json-nowrap | before | 33.3/33.7/51.7/51.7 | 13.7/14.0/14.9/14.9 | - | 0 | 0 | +| | after | 33.3/33.5/52.7/52.7 | 13.7/13.9/14.0/14.0 | - | 0 | 0 | +| l-held-oneline.json-nowrap | before | 33.3/33.5/52.6/52.6 | 13.4/13.7/14.9/14.9 | - | 0 | 0 | +| | after | 33.3/33.5/51.0/51.0 | 13.7/13.9/14.9/14.9 | - | 0 | 0 | +| dollar-zero-oneline.json-nowrap | before | 26.1/33.4/33.4/33.4 | 17.3/25.3/25.3/25.3 | - | 0 | 0 | +| | after | 30.5/33.3/33.3/33.3 | 16.6/22.0/30.7/30.7 | 16.7/16.8/17.2/17.2 | 0 | 0 | +| f-t-oneline.json-nowrap | before | 27.2/35.5/39.1/39.1 | 26.2/34.5/38.1/38.1 | - | 0 | 0 | +| | after | 30.8/31.0/31.2/31.2 | 16.5/29.6/30.3/30.3 | 16.7/16.8/17.1/17.4 | 0 | 0 | +| gl-gh-oneline.json-nowrap | before | 25.8/27.6/35.3/35.3 | 24.8/27.0/34.2/34.2 | - | 0 | 0 | +| | after | 31.7/32.6/32.7/32.7 | 15.8/30.5/31.6/31.6 | 16.6/16.8/16.8/16.8 | 0 | 0 | +| insert-end-oneline.json-nowrap | before | 21.8/26.4/35.2/35.2 | 20.5/25.0/34.2/34.2 | 16.6/16.8/16.8/16.8 | 0 | 0 | +| | after | 16.6/18.2/32.8/32.8 | 16.4/16.6/31.3/31.7 | 16.7/16.9/18.2/19.0 | 0 | 0 | +| insert-middle-oneline.json-nowrap | before | 16.7/1891.8/1891.8/1891.8 | 15.6/16.7/1853.1/1853.1 | 16.7/16.9/34.5/34.5 | 0 | 1 | +| | after | 124.1/318.2/319.3/319.3 | 16.4/179.1/180.3/180.3 | 16.7/16.7/16.9/16.9 | 0 | 0 | +| sweep-L-W-oneline.json-nowrap | before | 16.8/2801.3/2801.3/2801.3 | 15.6/15.8/16.7/1844.0 | 16.7/16.8/17.0/17.0 | 0 | 0 | +| | after | 16.4/33.2/70.5/70.5 | 13.4/16.8/26.4/31.8 | 16.6/16.9/17.5/17.5 | 0 | 0 | +| w-held-hugelines.txt-nowrap | before | 22.3/27.4/27.8/27.8 | 15.3/16.0/16.8/16.8 | 16.8/25.6/27.8/27.9 | 0 | 11 | +| | after | 22.4/26.9/31.7/31.7 | 15.1/16.0/27.1/27.1 | 16.7/22.7/27.6/27.6 | 0 | 3 | +| e-held-hugelines.txt-nowrap | before | 22.5/27.5/28.8/28.8 | 11.4/16.3/17.0/17.0 | 22.3/27.4/28.8/28.8 | 0 | 17 | +| | after | 22.4/26.7/28.1/28.1 | 11.4/15.2/17.0/17.0 | - | 0 | 0 | +| l-held-hugelines.txt-nowrap | before | 22.0/27.4/28.1/28.1 | 10.8/15.8/16.7/17.0 | 21.8/24.2/28.1/28.1 | 0 | 16 | +| | after | 22.1/26.4/27.6/27.6 | 10.9/15.3/16.4/16.4 | - | 0 | 0 | +| dollar-zero-hugelines.txt-nowrap | before | 16.6/16.7/16.7/16.7 | 15.6/15.8/16.5/20.6 | 16.7/16.8/17.3/21.7 | 0 | 0 | +| | after | 15.6/30.4/30.4/30.4 | 13.9/16.1/29.2/29.2 | 16.6/16.8/16.9/16.9 | 0 | 0 | +| f-t-hugelines.txt-nowrap | before | 16.6/16.8/16.9/16.9 | 15.6/16.0/16.6/16.7 | 16.7/16.8/17.0/17.5 | 0 | 0 | +| | after | 30.7/30.9/31.4/31.4 | 14.8/29.6/29.9/30.4 | 16.6/16.8/22.3/22.6 | 0 | 0 | +| gl-gh-hugelines.txt-nowrap | before | 10.9/16.7/16.8/16.8 | 15.6/15.8/16.9/20.7 | 16.6/16.8/18.0/21.7 | 0 | 0 | +| | after | 16.8/31.4/31.6/31.6 | 15.0/16.7/30.6/30.6 | 16.6/16.8/22.7/22.7 | 0 | 0 | +| insert-end-hugelines.txt-nowrap | before | 16.5/16.8/17.1/17.1 | 15.6/16.4/16.8/16.9 | 16.6/16.8/17.1/17.9 | 0 | 0 | +| | after | 16.5/18.3/31.8/31.8 | 16.3/16.6/29.8/30.8 | 16.6/16.9/22.7/22.7 | 0 | 0 | +| insert-middle-hugelines.txt-nowrap | before | 26.2/29.0/29.4/29.4 | 11.6/15.7/16.2/16.4 | 16.6/26.9/29.2/29.4 | 0 | 40 | +| | after | 24.4/29.0/37.4/37.4 | 10.7/16.3/16.9/16.9 | 16.6/17.1/22.3/22.3 | 0 | 0 | +| sweep-L-W-hugelines.txt-nowrap | before | 16.2/25.8/30.4/30.4 | 12.6/15.7/16.5/18.3 | 16.2/25.6/30.0/30.5 | 0 | 30 | +| | after | 21.0/25.8/30.4/30.4 | 14.1/18.1/29.3/29.7 | 16.6/16.8/16.9/16.9 | 0 | 0 | + +#### tty ReleaseSafe: `scroll` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | bytes/frame p50/max | +|---|---|---|---|---|---|---|---| +| all | before | 2.6/3.0/8.8/8.8 | 0.4/1.4/2.8/8.7 | 0.5/1.9/3.1/16.5 | 1449 | 0 | 105/15264 | +| | after | 2.4/3.0/8.1/8.1 | 2.2/2.7/7.9/8.0 | 15.8/16.9/18.6/18.6 | 1455 | 0 | 120/15264 | + +#### tty ReleaseSafe: `stress` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | bytes/frame p50/max | +|---|---|---|---|---|---|---|---| +| all | before | 2.6/11.4/23.2/26.1 | 1.0/2.7/20.1/26.0 | 2.0/2.6/5.2/16.7 | 9811 | 0 | 174/13383 | +| | after | 1.3/2.8/5.9/14.6 | 1.1/2.7/4.9/13.1 | 15.5/16.6/17.6/17.6 | 9807 | 0 | 132/13383 | + +#### tty ReleaseSafe: `jumps` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | bytes/frame p50/max | +|---|---|---|---|---|---|---|---| +| all | before | 1.6/6.0/22.0/22.7 | 0.4/0.8/2.8/22.7 | 0.4/1.5/2.8/16.7 | 2190 | 0 | 108/15264 | +| | after | 1.6/3.6/15.8/17.4 | 1.1/2.6/7.3/17.3 | 15.8/16.8/18.4/19.1 | 2189 | 0 | 100/15264 | + +#### tty Debug: `scroll` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | bytes/frame p50/max | +|---|---|---|---|---|---|---|---| +| all | before | 9.8/14.8/60.9/60.9 | 1.9/5.4/14.7/45.2 | 2.0/2.0/13.3/24.9 | 1452 | 0 | 86/15264 | +| | after | 7.3/14.1/36.2/36.2 | 5.6/11.8/25.2/27.9 | 15.5/19.8/20.8/20.8 | 1454 | 0 | 128/15264 | + +#### tty Debug: `stress` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | bytes/frame p50/max | +|---|---|---|---|---|---|---|---| +| all | before | 3.5/29.0/73.5/103.4 | 2.6/13.2/58.9/103.0 | 3.0/3.2/18.7/24.0 | 9825 | 0 | 180/13383 | +| | after | 2.4/12.8/69.9/195.7 | 2.3/11.0/66.3/195.5 | 15.6/19.2/24.9/24.9 | 9825 | 0 | 6859/13383 | + +#### tty Debug: `jumps` + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | bytes/frame p50/max | +|---|---|---|---|---|---|---|---| +| all | before | 26.1/43.9/74.5/78.0 | 2.1/22.9/44.8/77.5 | 2.1/2.3/15.7/40.8 | 2189 | 1 | 108/15264 | +| | after | 24.5/37.8/63.1/70.3 | 4.9/27.5/42.9/68.7 | 15.7/18.5/24.2/39.9 | 2175 | 1 | 101/15264 | + +## The coordinator's latency rows, answered + +- **pages-up-big** (p90 8.8 -> 24): real. The paint-ahead's upward stretch + stopped two lines short of the view's own bottom (it was "two views out", + the AFTER rows counted from the far end), so a half page up missed it and + painted on the frame (11-17 ms). The stretch is now the view itself and + three more the way it goes, both ways; re-measured (two interleaved + rounds and the final batch): p90 8.8-11.0 against 9.7-19.1 before, frame + work p90 6.0 against 14.1; the p99 left (15-20 ms) is the first page up + after `ge`, which paints on the frame in both (the paint-ahead was + looking down). +- **notches p90/p99**: the wheel takes the drawn-at-once branch (its SDL + event sets `input_seen` as a key's does: the nine notches into a running + glide answer in 1.7-2.0 ms against 2.7-4.7 before). The p90 of ten + samples is the first notch after 1.2 s idle: 13.3 against 9.8, n=1, the + CPU and GPU waking in both (its upload 4.7 ms, its fence 2.4). +- **small-file jumps +2 ms**: not reproducible: two more interleaved rounds + put after both above and below before (search-n-small 8.6/7.2 against + 9.1/10.4, rail-small 8.6/7.0 against 8.9/12.1). Per frame, an input after + idle pays the soft present's upload at a low clock (4.7 ms against 0.8 + warm) in both builds; that is the spread. +- **insert-big max**: the 200-line paste's frame (a far, stitched slide and + its paint), 31-37 ms in both builds. +- **rows/s that changed meaning**: the `scroll` demo's before ran `G` (a + no-op without a count; the script was fixed to `ge` in anim 3, not in + 1b, so before and after ran different scripts). Moved into 1b, both + rebuilt and re-run: the tables below are the same script. `jumplist`'s + rows/s counts how far the jumps went, which depends on what earlier + phases left in the jumplist; before's `look-big` phase drew no frames + (its Looks resolved in the query pane), so its jumplist held fewer far + places. Compare its latency and work, not its rows/s. + +## Open questions and positions + +1. **The soft present on Wayland is the ReleaseSafe frame's tail.** Every + native-Wayland GUI presents through SDL_Renderer so WindowOpacity can be + background-only, whatever the setting: a GPU fence wait and a 6.7 MB + upload a frame, and the first frame after idle pays both at a low clock. + With the GPU swapchain (X11) the scroll is 0.34 ms of work p50. Position: + claim the GPU swapchain when a session starts at WindowOpacity 100 (the + author's config) and say "needs a restart" below 100. +2. **Debug is slow where tree-sitter allocates**: a third of the Debug + stress run was the DebugAllocator's stack capture per tree-sitter + allocation. Position: a size-class pool for tree-sitter in safe builds, + leak-checked by counting. +3. **The spin** costs a core while something moves (CPU 2.0 -> 7.3 s over + the 18 s scroll demo, ReleaseSafe). Position: keep; asleep, the clock + that cannot be trusted costs the latency the author ranked first. +4. **Terminals and keys**: a terminal glides only under the wheel. Ctrl-d + in its normal mode could glide too when no output arrived that frame. + Position: next, with the stream test. +5. **The far jump's slide** shows the last frame's body sliding off and the + new one in, not what lies between. Position: keep; it reads as motion + and never shows anything that was not on screen. +6. **Long lines**: 16 KB round the caret is painted; the rest of a minified + line keeps its last colours. Typing in the middle of a 500 KB line is + now 18-22 ms a key in ReleaseSafe (was 173-213); what is left is the + text's splice and the wrap of the line. The no-wrap sideways scroll + snaps (a horizontal glide was not asked). Position: an incremental + whole-text parse is the real fix; not ponytail-sized. +7. **PDF first frames are not improved.** The bridge renders on the loop + through one MuPDF context and a one-page cache (30-38 ms RS, 110-184 + Debug, the page's content stream interpreted). Off the loop needs a + cloned fz_context per worker and locks round the document: a day's + work with the band-render design in the latency notes. Pictures are + done (decoded on a thread: first frame 90 -> 13 ms max RS, 296 ms -> + one frame later in Debug); a second open still decodes again (no cache: + a Restore is rare). +8. **The tty** has no vsync and no sub-cell motion: it is paced (a 16 ms + tick through its acks), it does not glide, and a scroll still rewrites + most rows (vaxis diffs cells; terminal scroll regions would move them + for a few bytes). Position: scroll regions, if the tty's bytes matter. -- cgit v1.3 From 408412838ce7bf3156ba8aa6f95057a72ebdd284 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 21:30:52 -0300 Subject: anim 9: a stream of inputs moves the view at its own rate: the picture's motion is one system (lag, speed, what feeds it) integrated in one place; a held key, a spun wheel, a held Ctrl-d feed it at their rate instead of an ease a line; the spring settles it once they stop, never past its mark --- docs/next-anim.md | 25 ++++++++ src/gui/gui.zig | 179 ++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 166 insertions(+), 38 deletions(-) (limited to 'docs/next-anim.md') diff --git a/docs/next-anim.md b/docs/next-anim.md index 9f43a232..1acdeacf 100644 --- a/docs/next-anim.md +++ b/docs/next-anim.md @@ -163,6 +163,31 @@ keeps the rows that left for the gap, and kicks the spring. test checks). - The caret and the glide quad ride the picture (`glideLift`). +### The view's motion is one system (anim 9) + +The author watched sample 3 and saw a bounce a line under a held j: every +repeat restarted the spring's ease to its new target, so the picture sped +up and slowed down once an input. Now the picture's motion is one system +with its own state (`Glide`: its lag behind the text, its speed, and the +inputs that have been feeding it), integrated in one place every frame +(`Glide.advance`), and every scroll is an input into it (`Glide.kick`), +absorbed by what the system is doing: + +| the system is | an input comes | it does | +|---|---|---| +| at rest | any move (a j, a notch, a page, a jump) | the spring starts an ease from rest | +| easing | the same way, within 150 ms | the inputs are a stream now: it moves at their rate (rows an input over their spacing), a lag of an input or so behind, never easing to each | +| fed by a stream | another of the stream | the target moves on; the speed stays the stream's | +| fed by a stream | the inputs stop (none for 1.5 spacings) | the spring settles it, from the speed it has, never past its mark: the only ease-out | +| moving | an input the other way | the stream ends; the spring turns it through zero from its speed | +| moving | a jump past what two frames share | its rows are added (the stitched slide); the speed carries on | + +So a held j, a spun wheel and a held Ctrl-d are the same case (a stream), +a single j or notch the same ease as before. Every input, a repeat too, +is still drawn at once: in a stream the picture is on the stream's +straight line wherever a frame samples it (tried: holding repeats to the +next tick cost a held key 7 ms of latency for no evenness one could see). + ### The cursor (anim 4) The thin caret glides as the block does. A step of a cell or less eases diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 9c3a1256..8163581a 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -4175,7 +4175,10 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { // Paced: what came before the tick is in; wait out the rest of it, // unless an input came: its frame is drawn at once (the paced loop // never adds a tick to an input's latency), and the ticks after it - // run from it. + // run from it. A stream's repeat too: the picture it moves is on + // the stream's straight line wherever it is sampled, so drawing it + // between two ticks costs no evenness, and holding it to the tick + // cost a held key 7 ms of latency. if (paced and g.input_seen) tick = c.SDL_GetTicksNS(); // The tick is waited out polling, not asleep, as a game's frame // limiter spins: asleep between 60 Hz frames, the CPU's clock fell @@ -5044,13 +5047,30 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a /// draw in the gap. A move past what the two frames share (a page and more, /// G) has no rows between them to show: the picture comes from the last /// frame's body as if it lay just past the new one, one body away, so a -/// jump of any length reads as one body's slide. A move during a glide -/// adds to it, its speed carried: it retargets, it never queues. +/// jump of any length reads as one body's slide. +/// +/// The picture's motion is one system with its own state, integrated in +/// one place every frame (`advance`), and every scroll, whatever made it, +/// is an input into it (`kick`): it moves the target by the rows the core +/// moved and leaves the motion as it is. What the system was doing decides +/// how it is absorbed: inputs coming as a stream (each like the last, at a +/// steady spacing: a held key, a spun wheel) feed it, and it moves at the +/// stream's own rate, a lag of an input or so behind, never easing toward +/// each target (that was a bounce a line); an input into a resting view, +/// or against the way it moves, starts the spring from the speed it has +/// (an ease, a turn through zero); a jump mid-glide adds its rows with the +/// speed kept. The spring's settle only comes once the inputs stop. const Glide = struct { - spring: pardes.animation.Spring = .{}, /// The picture's offset from the core's rows now (rows; negative, the - /// picture still shows what is above). + /// picture still shows what is above), its speed (offset's rows a + /// second), and when it was last integrated. offset: f32 = 0, + speed: f32 = 0, + at_ns: u64 = 0, + /// What has been feeding it: the rows of the last inputs (down + /// positive), their spacing, the last's time, and how many came as one + /// stream. + feed: struct { rows: f32 = 0, gap_ns: u64 = 0, last_ns: u64 = 0, count: u16 = 0 } = .{}, now_ns: u64 = 0, pane: usize = 0, rect: pardes.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }, @@ -5078,21 +5098,22 @@ const Glide = struct { /// Each pane's view as the last loop step saw it (stepGlide): its /// serial, first line and file, so a view that moved since is found /// whatever moved it. - /// When the picture was last sampled (sample). - shown_ns: u64 = 0, seen: [pardes.MAX_PANES]struct { serial: u32 = 0, line: i64 = 0, file: u64 = 0, revision: u32 = 0 } = @splat(.{}), /// How far the picture may lag, in bodies: the rows kept past each /// edge, so a jump made while one glides carries on from where it is. const reach = 2; const bodies_per_s: f32 = 15; + /// Inputs this close, each the way the last went, are one stream. + const stream_ns = 150 * std.time.ns_per_ms; fn moving(glide: *const Glide) bool { - return !glide.spring.settled or glide.pending; + return glide.offset != 0 or glide.speed != 0 or glide.pending; } fn stop(glide: *Glide) void { - glide.spring = .{}; + glide.speed = 0; + glide.feed = .{}; glide.offset = 0; glide.pending = false; glide.nabove = 0; @@ -5119,32 +5140,70 @@ const Glide = struct { return glide.rect.w -| config.GUTTER; } - /// The core's rows moved by `rows` (down positive) since the last - /// frame: the picture now lags by as many, carrying its speed. + /// An input: the core's rows moved by `rows` (down positive) since the + /// last frame. The picture now lags by as many more, its speed as it was. fn kick(glide: *Glide, rows: f32, now_ns: u64, motion: pardes.animation.Motion) void { - // Follows input: the flavour's pace, half again, never overshooting. - var pace = motion; - pace.omega = motion.omega * 1.5; - glide.spring.carry(-rows, now_ns, pace); + glide.advance(now_ns, motion); // Never more than `reach` bodies behind: a flick past that jumps. const limit: f32 = @floatFromInt(@as(u32, glide.body_h) * reach); - const now = glide.spring.value(now_ns); - if (@abs(now) > limit) glide.spring.carry(std.math.clamp(now, -limit, limit) - now, now_ns, pace); - glide.offset = glide.spring.value(now_ns); - glide.shown_ns = now_ns; - } - - /// The picture at `now_ns`: the spring's, but never more than - /// `bodies_per_s` of the body a second from the last frame's (a body in - /// four frames at 60 Hz), so text that moves stays text one can read; - /// the spring slows below that before it lands, and the picture is on - /// it again by then. - fn sample(glide: *Glide, now_ns: u64) void { - const want = glide.spring.value(now_ns); - const dt: f32 = @floatCast(@as(f64, @floatFromInt(@min(now_ns -| glide.shown_ns, 2 * pardes.animation.frame_ns))) / std.time.ns_per_s); - glide.shown_ns = now_ns; - const cap = @as(f32, @floatFromInt(glide.body_h)) * bodies_per_s * dt; - glide.offset = std.math.clamp(want, glide.offset - cap, glide.offset + cap); + glide.offset = std.math.clamp(glide.offset - rows, -limit, limit); + const f = &glide.feed; + const like = f.count > 0 and (rows > 0) == (f.rows > 0) and now_ns -| f.last_ns < stream_ns; + if (like) { + const gap = now_ns -| f.last_ns; + f.gap_ns = if (f.count == 1) gap else (f.gap_ns + gap) / 2; + f.rows = (f.rows + rows) / 2; + f.count +|= 1; + } else f.* = .{ .rows = rows, .count = 1 }; + f.last_ns = now_ns; + } + + /// The system moved on to `now_ns`. Fed by a stream, at the stream's + /// rate (rows an input over their spacing), held a lag `lead` behind + /// the text so a late input never finds it stopped and the stream's end + /// never runs it past its mark; else on the flavour's spring at 1.5x + /// its pace, critically damped, from the speed it has. Never more than + /// `bodies_per_s` of the body a second, so moving text stays readable. + fn advance(glide: *Glide, now_ns: u64, motion: pardes.animation.Motion) void { + const dt: f32 = @floatCast(@as(f64, @floatFromInt(@min(now_ns -| glide.at_ns, 2 * pardes.animation.frame_ns))) / std.time.ns_per_s); + glide.at_ns = now_ns; + if (glide.offset == 0 and glide.speed == 0) return; + const omega = motion.omega * 1.5; + const cap = @as(f32, @floatFromInt(glide.body_h)) * bodies_per_s; + const toward: f32 = if (glide.offset < 0) 1 else -1; + const f = glide.feed; + if (f.count >= 2 and f.gap_ns > 0 and now_ns -| f.last_ns < f.gap_ns * 3 / 2) { + const gap: f32 = @floatCast(@as(f64, @floatFromInt(f.gap_ns)) / std.time.ns_per_s); + const rate = @abs(f.rows) / gap; + const lead = @max(@abs(f.rows), rate / omega); + // ponytail: a gentle pull to the lead (a tenth an input), so the + // per-frame step varies by a tenth; a stream's own jitter beyond + // that shows. An estimate of the input clock if it ever matters. + const v = std.math.clamp(rate + 0.1 / gap * (@abs(glide.offset) - lead), 0, cap); + const step = @min(v * dt, @abs(glide.offset)); + glide.offset += toward * step; + glide.speed = toward * v; + return; + } + const x = glide.offset; + // Coming to rest from a stream: never faster than the spring's own + // pace from here (omega a row of lag a second), so it eases in and + // does not pass its mark. + if (glide.speed * x < 0 and @abs(glide.speed) > omega * @abs(x)) glide.speed = std.math.sign(glide.speed) * omega * @abs(x); + const lead_v = glide.speed + omega * x; + const decay = @exp(-omega * dt); + var next = (x + lead_v * dt) * decay; + var speed = (glide.speed - omega * dt * lead_v) * decay; + if (@abs(next - x) > cap * dt) { + next = x + std.math.sign(next - x) * cap * dt; + speed = std.math.sign(next - x) * cap; + } + glide.offset = next; + glide.speed = speed; + if (@abs(next) < 5e-3 and @abs(speed) < 5e-2) { + glide.offset = 0; + glide.speed = 0; + } } /// Finds how far the pane's body rows moved, `dir` rows at a time, by @@ -5248,10 +5307,10 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { defer core.shell_continuous = glide.moving() or g.sel_glow.fading or g.hover_glow.fading; glide.now_ns = core.now_ns; glide.motion = pardes.animation.Motion.of(core.settings.motion); - if (!glide.spring.settled) { - _ = glide.spring.step(core.now_ns); + if (glide.offset != 0 or glide.speed != 0) { + glide.advance(core.now_ns, glide.motion); core.needs_frame = true; - if (glide.spring.settled) { + if (glide.offset == 0) { glide.offset = 0; glide.nabove = 0; glide.nbelow = 0; @@ -5465,7 +5524,7 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe now += 7 * ms; core.advance(now); stepGlide(&g, core, gpa); - try std.testing.expect(g.glide.spring.value(now) <= 1e-4); + try std.testing.expect(g.glide.offset <= 1e-4); if (frames > 200) return error.NeverSettled; } try std.testing.expect(frames > 5); @@ -5499,7 +5558,7 @@ const GlideRun = struct { _ = arena.reset(.retain_capacity); const s = try core.render(arena.allocator()); if (g.glide.pending) g.glide.measure(gpa, s); - if (g.glide.moving()) g.glide.sample(g.glide.now_ns); + if (g.glide.moving()) g.glide.advance(g.glide.now_ns, g.glide.motion); seq.offsets[frame] = g.glide.offset; seq.lines[frame] = @intCast(core.panes[core.active].?.file.?.scroll); } @@ -5594,6 +5653,50 @@ test "every scroll glides on one law: a half page, a page, the far jumps, a run for (off.offsets[0..off.frames]) |offset| try std.testing.expectEqual(@as(f32, 0), offset); } +test "a held key moves the view at the stream's own rate, never a bounce a line, and settles once it stops" { + const gpa = std.testing.allocator; + const core = try pardes.Pardes.init(gpa, .{ .cols = 100, .rows = 40 }); + defer core.deinit(); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(gpa); + for (0..3000) |i| try text.print(gpa, "{d:0>5} line {d} of the long file\n", .{ i, i * 7 % 13 }); + _ = try core.setTestFile(text.items); + core.settings.motion = .smooth; + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + core.advance(std.time.ns_per_s); + _ = try core.render(arena.allocator()); + var g: Gui = undefined; + g.glide = .{}; + defer g.glide.deinit(gpa); + g.scroll_notch = 0; + g.scroll_pane = null; + g.scroll_delta = 0; + g.scroll_lag = 0; + g.scroll_edge_len = 0; + g.sel_glow = .{}; + g.hover_glow = .{}; + // j held from the top: a repeat every second frame, the view following + // a line a repeat once the caret is at its last rows. + var script: [48]GlideRun.Step = undefined; + for (&script, 0..) |*step, i| step.* = .{ .frame = 20 + 2 * i, .key = .{ .cp = 'j', .text = "j" } }; + var seq: GlideRun = .{}; + try seq.play(&g, core, gpa, &arena, &script, 200); + // Inside the stream the picture moves every frame by about the same + // step: an input's rows over its spacing, not a spring's ease to each. + var least: f32 = std.math.inf(f32); + var most: f32 = 0; + for (90..110) |k| { + const step = (@as(f32, @floatFromInt(seq.lines[k])) + seq.offsets[k]) - (@as(f32, @floatFromInt(seq.lines[k - 1])) + seq.offsets[k - 1]); + least = @min(least, step); + most = @max(most, step); + } + try std.testing.expect(seq.lines[89] > 0 and least > 0.4 and most < 0.6); + // It comes to rest once the keys stop, never past its mark. + for (110..200) |k| try std.testing.expect(seq.offsets[k] <= 0); + try std.testing.expectEqual(@as(f32, 0), seq.offsets[199]); +} + fn resetScroll(g: *Gui) void { g.scroll_pane = null; g.scroll_delta = 0; @@ -6291,7 +6394,7 @@ fn renderFrame( if (surface.chrome.fx & 1 == 0 or surface.panelTracks().len != 0) g.sel_glow = .{ .now_ns = g.sel_glow.now_ns }; g.hover_glow.now_ns = g.sel_glow.now_ns; if (surface.chrome.fx & 2 == 0 or surface.panelTracks().len != 0) g.hover_glow = .{ .now_ns = g.sel_glow.now_ns }; - if (g.glide.moving()) g.glide.sample(g.glide.now_ns); + if (g.glide.moving()) g.glide.advance(g.glide.now_ns, g.glide.motion); cell_decor = CellDecor.of(chrome); plaque_through_len = 0; // G13: a body's dots follow its text at a quarter of its speed: its -- cgit v1.3 From 0dc2dc053af20d6811bfbe09ab31b762862a53a6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 21:30:52 -0300 Subject: anim 10: the caret is its own body: drawn from its own springs only, never carried by the text's glide (the ride-along deleted); its target is its cell as the view will settle, so a page leaves it still, a scroll that carries its line moves it there whole at the view's pace, a jump is one ease, a stream of steps lands each --- docs/next-anim.md | 25 ++++++++++++++++ src/FrameStats.zig | 12 +++++--- src/animation.zig | 42 +++++++++++++++++++-------- src/draw.zig | 73 +++++++++++++++++++++++++++++++++++++++------- src/gui/gui.zig | 85 +++++++++++++++++++++++++++++++++++------------------- 5 files changed, 181 insertions(+), 56 deletions(-) (limited to 'docs/next-anim.md') diff --git a/docs/next-anim.md b/docs/next-anim.md index 1acdeacf..a64bfaf4 100644 --- a/docs/next-anim.md +++ b/docs/next-anim.md @@ -182,6 +182,31 @@ absorbed by what the system is doing: | moving | an input the other way | the stream ends; the spring turns it through zero from its speed | | moving | a jump past what two frames share | its rows are added (the stitched slide); the speed carries on | +The caret is its own body (anim 10): its state is its own springs +(`CursorGlide`, screen cells as floats), integrated on the same tick, and +it is drawn from that state only, never from the text's glide (the ride +that lifted it with the glide's fractional lag is deleted: every motion +of the text had leaked into it). Its only coupling to the view is its +target: its cell in the view as it will be once settled (the core's view +is that one). + +| an input | the caret's target | it does | +|---|---|---| +| a page or half page, a scroll that keeps its screen row (Ctrl-f/b/d/u, PageDown/Up, a j or k at the edge row) | unchanged | not a pixel's move while the text slides under it | +| a move in a still view (h/j/k/l, w, a click, a typed character) | the new cell | the short ease | +| a stream of such moves (a held key, typing) | each new cell | lands on each, at the keys' rate | +| a scroll that carries its line (the wheel, Ctrl-o to a far place in view) | where its line will be | moves there whole, at the view's pace, and lands exactly | +| a jump that moves both (G, a Look) | the final cell | one ease, no trip with the old page | +| a terminal's output | its cell | lands with the output (which does not glide) | +| Motion off | the cell | there at once | + +While a glide moves the text the caret is drawn as its quad (from its +springs), not as a cell of the moving rows. Invariants, checked over every +frame of the scripted scroll and held-key runs (`GlideRun.checkCaret`): +while its cell stays and it is on it, its drawn row is identical frame to +frame; it only closes on its cell; it lands within half a second of its +last change. The blink keys off the last key or click, never a frame. + So a held j, a spun wheel and a held Ctrl-d are the same case (a stream), a single j or notch the same ease as before. Every input, a repeat too, is still drawn at once: in a stream the picture is on the stream's diff --git a/src/FrameStats.zig b/src/FrameStats.zig index 0b252ff9..ee5ee3f2 100644 --- a/src/FrameStats.zig +++ b/src/FrameStats.zig @@ -45,8 +45,10 @@ pub const Frame = struct { /// The shell had no image to draw into (a busy swapchain). skipped: bool = false, /// The shell's motion in it: a scroll's picture offset from the text, - /// rows (0 at rest). + /// rows (0 at rest), and where it drew the caret, its top in rows + /// (the jitter check: a caret on a fixed row must not wobble). scroll: f32 = 0, + caret: f32 = 0, /// From the first input this frame answers to its present's end, µs; /// 0 when it answers none. latency_us: u32 = 0, @@ -84,6 +86,7 @@ skipped: u64 = 0, /// What the shell sets while it draws the frame (Frame.scroll), and the /// pump (view). scroll: f32 = 0, +caret: f32 = 0, view: i32 = 0, /// The first input not yet answered by a drawn frame, monotonic ns. input_ns: u64 = 0, @@ -146,6 +149,7 @@ pub fn record(stats: *FrameStats, end_ns: u64, moving: bool, skipped: bool) void .moving = stats.armed, .skipped = skipped, .scroll = stats.scroll, + .caret = stats.caret, .latency_us = if (stats.input_ns == 0) 0 else @max(1, us.of(stats.input_ns, end_ns)), .view = stats.view, .zones = stats.zone_us, @@ -263,13 +267,13 @@ pub fn dump(stats: *const FrameStats, path: [:0]const u8) void { .phase => |name| write.line(fd, &buf, "# phase {s} {d:.1}\n", .{ name, @as(f64, @floatFromInt((stats.demo_ns + @as(u64, step.at_ms) * std.time.ns_per_ms) -| t0)) / std.time.ns_per_ms }), else => {}, }; - write.line(fd, &buf, "# start_ms\tupdate_us\trender_us\tpresent_us\tgap_us\tmoving\tskipped\tscroll\tlatency_us\tview", .{}); + write.line(fd, &buf, "# start_ms\tupdate_us\trender_us\tpresent_us\tgap_us\tmoving\tskipped\tscroll\tcaret\tlatency_us\tview", .{}); inline for (comptime std.enums.values(Zone)) |which| write.line(fd, &buf, "\t{t}_us", .{which}); write.line(fd, &buf, "\tshaped\trastered\tbytes\n", .{}); for (all) |part| for (part) |f| { - write.line(fd, &buf, "{d:.3}\t{d}\t{d}\t{d}\t{d}\t{d}\t{d}\t{d:.4}\t{d}\t{d}", .{ + write.line(fd, &buf, "{d:.3}\t{d}\t{d}\t{d}\t{d}\t{d}\t{d}\t{d:.4}\t{d:.4}\t{d}\t{d}", .{ @as(f64, @floatFromInt(f.start_ns -| t0)) / std.time.ns_per_ms, f.update_us, f.render_us, f.present_us, f.gap_us, - @intFromBool(f.moving), @intFromBool(f.skipped), f.scroll, f.latency_us, f.view, + @intFromBool(f.moving), @intFromBool(f.skipped), f.scroll, f.caret, f.latency_us, f.view, }); for (f.zones) |us| write.line(fd, &buf, "\t{d}", .{us}); write.line(fd, &buf, "\t{d}\t{d}\t{d}\n", .{ f.shaped, f.rastered, f.bytes }); diff --git a/src/animation.zig b/src/animation.zig index 63a40cbf..ae6f9ca0 100644 --- a/src/animation.zig +++ b/src/animation.zig @@ -964,6 +964,8 @@ pub const CursorGlide = struct { target: Box = .{}, from_centre: [2]f32 = .{ 0, 0 }, placed: bool = false, + /// When the last step (a move of a cell or less) came. + step_ns: u64 = 0, /// How much faster than the flavour's own pace a cursor moves: it /// follows input (§8.1: settles in 90-150 ms on the default). @@ -972,6 +974,9 @@ pub const CursorGlide = struct { pub const arc_from: f32 = 8; /// How much stiffer a step's spring is than a jump's. pub const step_pace: f32 = 1.5; + /// Steps this close are a stream (a held key, typing): each lands, the + /// caret at the keys' own rate, as an eased step a key would bounce. + pub const stream_ns: u64 = 150 * std.time.ns_per_ms; fn cornersOf(box: Box) [4][2]f32 { return .{ .{ box.x, box.y }, .{ box.x + box.w, box.y }, .{ box.x + box.w, box.y + box.h }, .{ box.x, box.y + box.h } }; @@ -982,16 +987,27 @@ pub const CursorGlide = struct { } /// Heads for `box` at `now_ns`. - pub fn aim(glide: *CursorGlide, box: Box, now_ns: u64, motion: Motion, snap: bool) void { + /// How a new mark is gone to: eased (a step, or a jump's smear and + /// bow), landed at once, or moved whole at a scroll's pace (the text + /// moved under it, not the caret). + pub const How = enum { ease, land, rigid }; + + pub fn aim(glide: *CursorGlide, box: Box, now_ns: u64, motion: Motion, how: How) void { // The same mark: nothing to do, unless a snap lands a glide under way. - if (glide.placed and std.meta.eql(box, glide.target) and !(snap and glide.moving())) return; + if (glide.placed and std.meta.eql(box, glide.target) and !(how == .land and glide.moving())) return; const to = cornersOf(box); const from_c = if (glide.placed) glide.centreAt(now_ns) else centre(box); const to_c = centre(box); const dx = to_c[0] - from_c[0]; const dy = to_c[1] - from_c[1]; const jump = @abs(dx) > 1.01 or @abs(dy) > 1.01; - const land = !glide.placed or snap or motion.instant; + // A step is measured mark to mark, not from where an ease under way + // has got to (a held key's steps read as jumps from there). + const last = centre(glide.target); + const one_step = glide.placed and @abs(to_c[0] - last[0]) <= 1.01 and @abs(to_c[1] - last[1]) <= 1.01; + const streaming = one_step and glide.step_ns != 0 and now_ns -| glide.step_ns < stream_ns; + if (one_step) glide.step_ns = now_ns; + const land = !glide.placed or how == .land or motion.instant or streaming; glide.from_centre = from_c; glide.target = box; glide.placed = true; @@ -999,9 +1015,11 @@ pub const CursorGlide = struct { // Leading: the corner ahead of the move, on the side it goes. const ahead = (point[0] - to_c[0]) * dx + (point[1] - to_c[1]) * dy; var own = motion; - own.omega *= if (jump) pace * (if (ahead > 0) 1 else motion.follow) else pace * step_pace; - // A step neither winds up nor overshoots: it is a caret moving. - if (!jump) { + own.omega *= if (how == .rigid) 1.5 else if (jump) pace * (if (ahead > 0) 1 else motion.follow) else pace * step_pace; + // A step neither winds up nor overshoots: it is a caret moving; + // nor a whole move with the text (rigid: at the view's pace, + // Glide's 1.5x, its corners together). + if (!jump or how == .rigid) { own.zeta = 1; own.anticipate = 0; } @@ -1121,10 +1139,10 @@ test "a cursor eases a cell at a time, keeps up with typing, and glides a jump, const smooth_motion = Motion.of(.smooth); var glide: CursorGlide = .{}; const cell: Box = .{ .x = 3, .y = 4, .w = 1, .h = 1 }; - glide.aim(cell, 0, smooth_motion, false); + glide.aim(cell, 0, smooth_motion, .ease); try std.testing.expect(!glide.moving()); // One cell over: eases there whole, no wider than a cell, in ~60 ms. - glide.aim(.{ .x = 4, .y = 4, .w = 1, .h = 1 }, ms, smooth_motion, false); + glide.aim(.{ .x = 4, .y = 4, .w = 1, .h = 1 }, ms, smooth_motion, .ease); try std.testing.expect(glide.moving()); var step_t: u64 = ms; while (glide.step(step_t)) : (step_t += ms) { @@ -1132,21 +1150,21 @@ test "a cursor eases a cell at a time, keeps up with typing, and glides a jump, try std.testing.expect(q[1][0] - q[0][0] <= 1.0 + 1e-3 and q[0][0] >= 3 - 1e-3 and q[0][0] <= 4 + 1e-3); } try std.testing.expect(step_t - ms >= 30 * ms and step_t - ms <= 90 * ms); - // At a keyboard's repeat it keeps up: about half a cell behind. + // At a keyboard's repeat the steps are a stream: each lands. var typed: f32 = 4; var key_t: u64 = step_t; for (0..20) |_| { typed += 1; - glide.aim(.{ .x = typed, .y = 4, .w = 1, .h = 1 }, key_t, smooth_motion, false); + glide.aim(.{ .x = typed, .y = 4, .w = 1, .h = 1 }, key_t, smooth_motion, .ease); key_t += 33 * ms; try std.testing.expect(typed - glide.sample(key_t, smooth_motion)[0][0] <= 0.6); } while (glide.step(key_t)) key_t += ms; // A jump of 30 cells: glides, the leading edge ahead of the trailing one. - glide.aim(cell, key_t, smooth_motion, true); + glide.aim(cell, key_t, smooth_motion, .land); const j0 = key_t; const far: Box = .{ .x = 34, .y = 4, .w = 1, .h = 1 }; - glide.aim(far, j0 + 2 * ms, smooth_motion, false); + glide.aim(far, j0 + 2 * ms, smooth_motion, .ease); try std.testing.expect(glide.moving()); const mid = glide.sample(j0 + 40 * ms, smooth_motion); const width = mid[1][0] - mid[0][0]; diff --git a/src/draw.zig b/src/draw.zig index 265e07c1..e3ab9f2a 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -239,8 +239,8 @@ fn glideCursor(p: *Pardes, s: *Surface) void { }; const motion = animation.Motion.of(p.settings.motion); // The thin insert-mode caret glides as the block does (a jump smears - // and bows, a step eases); only a scroll, below, lands it. - var snap = false; + // and bows, a step eases); a scroll moves it rigidly, below. + var how: animation.CursorGlide.How = .ease; var frame: PaneFrame = .{}; // In a column's or the workspace's tag the cursor is not the pane's, // and does not move with it. @@ -259,14 +259,14 @@ fn glideCursor(p: *Pardes, s: *Surface) void { // The pane moved in the layout: the springs move with it (its // own cursor's; one in a column's tag stays). if (inside) p.cursor_glide.shift(origin[0] - view.origin[0], origin[1] - view.origin[1]); - // Scrolled (a file's view, a terminal's output): the quad moves - // with the text and lands, never gliding against text that - // jumped (every Enter at a prompt scrolls one and moves the - // other). - if (inside and line != view.line) { - p.cursor_glide.shift(0, @floatFromInt(view.line - line)); - snap = true; - } + // Scrolled (a file's view, a terminal's output): the caret is its + // own body, drawn from its own springs only, never from the text's + // glide. Its mark is where it will be once the view settles (its + // cell now: the core's view is that one), so a page that keeps its + // row leaves it still, and a scroll that carries its line moves + // it there whole, at the view's pace, not as a jump's smear. A + // terminal's output scrolls it with no glide: it lands with it. + if (inside and line != view.line) how = if (pane.isTerminal()) .land else .rigid; } else if (view.serial != 0 and p.cursor_glide.placed) { // Focus moved (to another pane, or between a pane and a // column's or the workspace's tag): the glide starts where the @@ -290,7 +290,7 @@ fn glideCursor(p: *Pardes, s: *Surface) void { // A click that took focus places the cursor on its release; aimed at // the pane's old cursor meanwhile, it would glide there first. if (p.drag != .select) p.cursor_held = false; - if (!p.cursor_held) p.cursor_glide.aim(box, p.now_ns, motion, snap); + if (!p.cursor_held) p.cursor_glide.aim(box, p.now_ns, motion, how); _ = p.cursor_glide.step(p.now_ns); const moving = p.cursor_glide.moving(); if (!moving and !p.cursor_held) p.cursor_crossing = false; @@ -1971,6 +1971,57 @@ test "each Motion flavour reaches the lift as its own trajectory" { try std.testing.expect(peaks[2] <= 1.001 and peaks[3] > 1.25 and peaks[4] > peaks[3]); } +test "the caret is its own body: a page leaves it still under the moving text, a wheel scroll moves it whole to its line's new row" { + if (!builtins.capabilities.lift) return error.SkipZigTest; + const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 30 }); + defer p.deinit(); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(std.testing.allocator); + for (0..400) |i| try text.print(std.testing.allocator, "line {d}\n", .{i}); + const pane = try p.setTestFile(text.items); + p.settings.cursor_blink = false; + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + var now: u64 = std.time.ns_per_s; + p.advance(now); + // Mid-file, where a half page keeps the caret's row. + for ("200G") |ch| p.update(.{ .key = .{ .cp = ch, .text = &.{ch} } }); + _ = try p.render(arena.allocator()); + now += std.time.ns_per_s; + p.advance(now); + _ = arena.reset(.retain_capacity); + _ = try p.render(arena.allocator()); + // Ctrl-d: the caret moves with the view and keeps its screen row: it + // does not ride the glide, and it does not move. + const row_before = (try p.render(arena.allocator())).cursor.?.y; + p.update(.{ .key = .{ .cp = 'd', .ctrl = true } }); + now += 16 * std.time.ns_per_ms; + p.advance(now); + _ = arena.reset(.retain_capacity); + var s = try p.render(arena.allocator()); + try std.testing.expect(pane.file.?.scroll > 0); + try std.testing.expectEqual(row_before, s.cursor.?.y); + try std.testing.expectEqual(@as(u8, 0), s.chrome.cursor_glide & 1); + try std.testing.expectEqual(@as(f32, @floatFromInt(row_before)), s.chrome.cursor_quad[1]); + // The view scrolled with the caret on its line: it heads for the + // line's new row whole (every corner the same way), and lands on it. + pane.scrollBy(-3); + now += 16 * std.time.ns_per_ms; + p.advance(now); + _ = arena.reset(.retain_capacity); + s = try p.render(arena.allocator()); + const mark: f32 = @floatFromInt(s.cursor.?.y); + try std.testing.expect(s.chrome.cursor_glide & 1 != 0 and s.chrome.cursor_quad[1] < mark); + try std.testing.expectApproxEqAbs(s.chrome.cursor_quad[3] - s.chrome.cursor_quad[1], s.chrome.cursor_quad[5] - s.chrome.cursor_quad[7], 1e-4); + while (p.continuous()) { + now += 7 * std.time.ns_per_ms; + p.advance(now); + _ = arena.reset(.retain_capacity); + s = try p.render(arena.allocator()); + } + try std.testing.expectEqual(mark, s.chrome.cursor_quad[1]); +} + test "the focused cursor glides a jump, eases a step, the thin caret too, and is exact at rest" { if (!builtins.capabilities.lift) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 30 }); diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 8163581a..3f7dd7ca 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -5428,8 +5428,6 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde shifted.y_off -= glide.offset * layout.h; const kept = holdContext(g, surface, glide.pane, held, bh, layout); shifted.y_off += kept.lift; - const cursor_idx: u32 = if (surface.cursor) |cu| @as(u32, cu.y) * surface.cols + cu.x else std.math.maxInt(u32); - const cursor_bar = if (surface.cursor) |cu| cu.bar else false; var n: u32 = 0; // Only the rows the scissor shows: lagging a body or more, every body // row is past the edge, and drawing them all was twice the frame's @@ -5442,8 +5440,9 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde const row_cursor: ?usize = if (surface.cursor) |cu| if (cu.y == row) cu.x else null else null; var col = x0; while (col < x0 + bw) : (col += 1) { - const sidx: u32 = @as(u32, row) * surface.cols + col; - emitInstance(g, instances, base + n, col, row, shifted, win_w, win_h, null, cellFontRole(surface.at(col, row)), line, col, row_cursor, false, sidx == cursor_idx and !cursor_bar, page); + // No caret among the moving rows: it is drawn from its own + // springs (the quad), never carried by the text's glide. + emitInstance(g, instances, base + n, col, row, shifted, win_w, win_h, null, cellFontRole(surface.at(col, row)), line, col, row_cursor, false, false, page); n += 1; } } @@ -5545,6 +5544,8 @@ const GlideRun = struct { const Step = struct { frame: usize, key: pardes.Key }; offsets: [600]f32 = undefined, lines: [600]i64 = undefined, + carets: [600]f32 = undefined, + cells: [600]f32 = undefined, frames: usize = 0, fn play(seq: *GlideRun, g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator, arena: *std.heap.ArenaAllocator, script: []const Step, frames: usize) !void { @@ -5561,10 +5562,27 @@ const GlideRun = struct { if (g.glide.moving()) g.glide.advance(g.glide.now_ns, g.glide.motion); seq.offsets[frame] = g.glide.offset; seq.lines[frame] = @intCast(core.panes[core.active].?.file.?.scroll); + seq.carets[frame] = caretRow(g, s) orelse -1; + seq.cells[frame] = if (s.cursor) |cu| @floatFromInt(cu.y) else -1; } seq.frames = frames; } + /// The caret's invariants over the run: while its cell stays and it is + /// on it, it does not move a pixel; it only ever closes on its cell (a + /// twentieth of a row of play for a jump's bow); it lands within half a + /// second of its last change. + fn checkCaret(seq: *const GlideRun) !void { + var changed: usize = 0; + for (1..seq.frames) |k| { + if (seq.cells[k] < 0 or seq.cells[k - 1] < 0) continue; + if (seq.cells[k] != seq.cells[k - 1]) changed = k; + if (seq.cells[k] == seq.cells[k - 1] and seq.carets[k - 1] == seq.cells[k - 1]) try std.testing.expectEqual(seq.carets[k - 1], seq.carets[k]); + try std.testing.expect(@abs(seq.carets[k] - seq.cells[k]) <= @abs(seq.carets[k - 1] - seq.cells[k]) + 0.05); + if (k - changed == 30) try std.testing.expectEqual(seq.cells[k], seq.carets[k]); + } + } + /// Frames from `from` until the picture is still: the scroll's glide. fn settle(seq: *const GlideRun, from: usize) usize { var k = from; @@ -5618,6 +5636,7 @@ test "every scroll glides on one law: a half page, a page, the far jumps, a run }; var seq: GlideRun = .{}; try seq.play(&g, core, gpa, &arena, &script, 240); + try seq.checkCaret(); // Every one moves the picture on the frame it is drawn in, and the // picture lags by what the core moved (a far jump, by one body). var longest: usize = 0; @@ -5692,9 +5711,24 @@ test "a held key moves the view at the stream's own rate, never a bounce a line, most = @max(most, step); } try std.testing.expect(seq.lines[89] > 0 and least > 0.4 and most < 0.6); + // The caret stays on its row, the text moving under it: not a pixel's + // wobble (the glide's fractional lag never reaches it). + for (90..110) |k| try std.testing.expectEqual(seq.carets[89], seq.carets[k]); // It comes to rest once the keys stop, never past its mark. for (110..200) |k| try std.testing.expect(seq.offsets[k] <= 0); try std.testing.expectEqual(@as(f32, 0), seq.offsets[199]); + // Ctrl-d held, then PageDown held: the caret keeps its row the whole + // way, the pages moving under it. + var pages: [40]GlideRun.Step = undefined; + for (&pages, 0..) |*step, i| step.* = .{ .frame = 10 + 2 * i, .key = if (i < 20) .{ .cp = 'd', .ctrl = true } else .{ .cp = pardes.Key.page_down } }; + var held: GlideRun = .{}; + try held.play(&g, core, gpa, &arena, &pages, 100); + try held.checkCaret(); + try seq.checkCaret(); + // (The first of each may move it, one ease: from the last row to where + // a half page keeps it, and from there to a page's.) + for (30..50) |k| try std.testing.expectEqual(held.carets[30], held.carets[k]); + for (70..90) |k| try std.testing.expectEqual(held.carets[70], held.carets[k]); } fn resetScroll(g: *Gui) void { @@ -6427,12 +6461,15 @@ fn renderFrame( // while it glides or blinks. One or the other every frame (none only at // a blink's off half). const blink_alpha: f32 = if (blinkNow(g, chrome)) |b| b.alpha else 1; - const quad_mode = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or blink_alpha < 1); + // While a glide moves the text, the caret is its quad, drawn from its + // own springs, not a cell of the moving rows. + const quad_mode = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or blink_alpha < 1 or g.glide.offset != 0); g.cursor_quad_alpha = if (quad_mode) chrome.cursor_alpha * blink_alpha else 0; // The probe's view of this frame's motion (FrameStats.Frame). if (core) |p| { const probe = &@constCast(p).frames; probe.scroll = g.glide.offset; + probe.caret = caretRow(g, surface) orelse 0; } const cursors_shown = groups.tracks == 0 and !quad_mode; var overlay_count = buildOverlay(g, core, surface, sw, sh, debug_on); @@ -10713,37 +10750,32 @@ fn postSpare(surface: *const pardes.Surface, layout: CellLayout, out: *[Post.max const CursorBox = Post.Frame.Cursor; const max_cursors = 1 + pardes.MAX_PANES + pardes.MAX_TAG_LAYERS; +/// Where the frame draws the focused caret, its top in grid rows: from its +/// own springs (the quad's, while it moves or while a glide moves the text) +/// or its cell; never from the text's glide. The probe records it and the +/// glide tests hold its invariants. +fn caretRow(g: *const Gui, surface: *const pardes.Surface) ?f32 { + const chrome = &surface.chrome; + const cursor = surface.cursor orelse return null; + const quad = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or g.glide.offset != 0); + return if (quad) chrome.cursor_quad[1] else @floatFromInt(cursor.y); +} + /// Every cursor on the frame where it is drawn, in window pixels: the grid's /// where no layer has its cell, and each layer's at that layer's pitch. A bar /// is an eighth of its cell wide, a block the whole cell. -/// Where a scroll's glide draws grid cell (col, row): its pixels down from -/// where the grid has it (the picture lags the text), and whether it is -/// still in the gliding body at all; nothing moved off a glide. -fn glideLift(g: *const Gui, col: f32, row: f32, layout: CellLayout) struct { px: f32, shown: bool } { - const glide = &g.glide; - if (glide.offset == 0) return .{ .px = 0, .shown = true }; - const r = glide.rect; - const top: f32 = @floatFromInt(glide.body_y); - const bottom = top + @as(f32, @floatFromInt(glide.body_h)); - if (col < @as(f32, @floatFromInt(r.x + config.GUTTER)) or col >= @as(f32, @floatFromInt(r.x + r.w)) or row < top or row >= bottom) return .{ .px = 0, .shown = true }; - const at = row - glide.offset; - return .{ .px = -glide.offset * layout.h, .shown = at >= top and at + 1 <= bottom + 0.5 }; -} - fn cursorBoxes(g: *const Gui, surface: *const pardes.Surface, layout: CellLayout, win_h: f32, out: *[max_cursors]CursorBox) usize { const chrome = &surface.chrome; const page = chrome.page orelse bg_default; var n: usize = 0; if (surface.cursor) |cursor| { - // A scroll's glide carries the cursor with the text it is in. - const lift = glideLift(g, @floatFromInt(cursor.x), @floatFromInt(cursor.y), layout); - if (lift.shown and cursor.x < surface.cols and cursor.y < surface.rows and bodyLayerAt(surface, cursor.x, cursor.y) == null and tagLayerIn(surface.tagLayers(), cursor.x, cursor.y) == null) { + if (cursor.x < surface.cols and cursor.y < surface.rows and bodyLayerAt(surface, cursor.x, cursor.y) == null and tagLayerIn(surface.tagLayers(), cursor.x, cursor.y) == null) { const cell = &surface.cells[@as(usize, cursor.y) * surface.cols + cursor.x]; const role = cellFontRole(cell); const width: f32 = if (role == .tagline) @floatFromInt(g.tagline_width) else layout.w; const height = std.math.clamp(if (role == .tagline) @as(f32, @floatFromInt(g.tagline_height)) else layout.h, 1.0, layout.h); const x0 = @as(f32, @floatFromInt(cursor.x)) * layout.w; - const y0 = @as(f32, @floatFromInt(cursor.y)) * layout.h + @as(f32, @floatFromInt(taglineBandOffset(cursor.y, win_h, @intFromFloat(layout.h), @intFromFloat(height)))) + lift.px; + const y0 = @as(f32, @floatFromInt(cursor.y)) * layout.h + @as(f32, @floatFromInt(taglineBandOffset(cursor.y, win_h, @intFromFloat(layout.h), @intFromFloat(height)))); out[n] = .{ .x0 = x0, .y0 = y0, .x1 = x0 + if (cursor.bar) @max(dp(1), width / 8.0) else width, .y1 = y0 + height, .rgb = cursorColor(chrome, cell, role), .text = page, .bar = cursor.bar }; n += 1; } @@ -10816,13 +10848,8 @@ fn appendCursorGlide(g: *Gui, surface: *const pardes.Surface, builder: *OverlayB const layout = fixedCellLayout(g); var px: [4][2]f32 = undefined; var centre: [2]f32 = .{ 0, 0 }; - // A scroll's glide carries the quad with the text, by where its centre is. - var cell_centre: [2]f32 = .{ 0, 0 }; - for (0..4) |i| cell_centre = .{ cell_centre[0] + chrome.cursor_quad[i * 2] / 4, cell_centre[1] + chrome.cursor_quad[i * 2 + 1] / 4 }; - const lift = glideLift(g, cell_centre[0], cell_centre[1], layout); - if (!lift.shown) return; for (&px, 0..) |*point, i| { - point.* = .{ chrome.cursor_quad[i * 2] * layout.w, chrome.cursor_quad[i * 2 + 1] * layout.h + lift.px }; + point.* = .{ chrome.cursor_quad[i * 2] * layout.w, chrome.cursor_quad[i * 2 + 1] * layout.h }; centre[0] += point[0] / 4; centre[1] += point[1] / 4; } -- cgit v1.3 From 6e8a6a63d45b2caef7b649d358f836e6cc4134d6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 22:50:15 -0300 Subject: anim 11: a PDF's strip moves in the text's motion system: the integrator is animation.Follow (the Glide's, moved out), here the strip's lag behind document_scroll_y in pixels; whatever moves the core's position (a notch, a spin, PageDown, Ctrl-d/f, ge/gg, a Look at a page, Back, the rail) kicks it, a touchpad's fraction and a relayout move it directly; the pages a glide crosses render in its input's frame, a far jump's only where it comes to rest; a slow stream eases onto its mark (it ran into it at speed and passed it); pictures neither scroll nor pan --- docs/next-anim.md | 125 ++++++++++++++++++++++++++++++++++- src/FrameStats.zig | 73 +++++++++++++++++++- src/animation.zig | 137 ++++++++++++++++++++++++++++++++++++++ src/detached/wire.zig | 8 ++- src/gui/gui.zig | 158 ++++++++++++++------------------------------ src/pardes.zig | 8 ++- src/pdf_view.zig | 180 ++++++++++++++++++++++++++++++++++++++++++++++---- test/pdf.zig | 14 ++-- 8 files changed, 568 insertions(+), 135 deletions(-) (limited to 'docs/next-anim.md') diff --git a/docs/next-anim.md b/docs/next-anim.md index a64bfaf4..9c9610e7 100644 --- a/docs/next-anim.md +++ b/docs/next-anim.md @@ -25,6 +25,9 @@ Positions, not a verdict: argue with them. | anim 6 `xykrnoql` | the tty paced too, its acks and output waited through | | anim 7 `powlyrxv` | what the probe found: the spin, glide measure and emission, far-jump and long-line paints, the caret's sideways scroll, no join on the loop, pictures decoded off the loop | | anim 8 | this note | +| anim 9 `nqznmskw` | the view's motion is one system: a stream of inputs moves it at its own rate, the spring only settles it | +| anim 10 `umnwnrvn` | the caret is its own body: drawn from its own springs, never carried by the text's glide | +| anim 11 `knzzzknu` | the integrator is `animation.Follow`; a PDF's strip moves in it, in pixels; a slow stream eases onto its mark | Tests (one check each, `-Dtest-filter`): "frame stats: gaps into a motion count as jank ...", "every scroll glides on one law ...", "a cursor eases @@ -213,6 +216,64 @@ is still drawn at once: in a stream the picture is on the stream's straight line wherever a frame samples it (tried: holding repeats to the next tick cost a held key 7 ms of latency for no evenness one could see). +### A PDF's strip, the same system (anim 11) + +The integrator is `animation.Follow` now (the Glide's state and rules, +moved out; the text's Glide holds one, in rows). A PDF pane's strip holds +another, in pixels: the core's position is `document_scroll_y` as every +input leaves it, and the strip is drawn `follow.offset` from it +(`pdf_view.stripAt`, each frame at the core's clock). Whatever moved the +core's position since the last frame kicks it, so every way a PDF moves is +one input to the same rules, the text's table above unchanged: + +| input | the strip | +|---|---| +| a wheel notch (a line's pixels), a spin | eases; a spin is a stream, at its rate | +| PageDown/Up, Ctrl-d/u/f/b, held | a stream, at its rate (to the 15 bodies a second cap) | +| ge, gg, a Look at `file.pdf:12`, Back, a section in the outline | a jump: past a body, one body's slide, as a text's far jump | +| a click on the rail, a tick | eases | +| a touchpad's fraction (`pdf_scroll.glide` false) | follows, drawn where the core is the same frame | +| a resize, a fit or zoom change (a relayout) | there at once | +| a search's reveal (it moves the strip as it draws) | there at once | +| Motion off | there at once | + +Rendering stays on the loop (MuPDF; its first-frame and context work is +the open item it was). So that no frame of a glide waits on it, the pages +a glide crosses to its mark are rendered in its input's frame, where the +instant move rendered its destination; a jump past a body (`far`) renders +only where it comes to rest, and its slide comes in over what is there +(the page above the mark is not drawn for a slide of a tenth of a second: +that page was the input frame's whole extra cost). Drawn at the strip's +position, rounded only by the draw (`pixel_offset_y` keeps the +fraction). Pictures are fit to their body and neither scroll nor pan: +nothing there to move. + +**Why the slow PDF scroll read as jumps**: a wheel notch moved the strip a +whole line's pixels (25 here) in the one frame after it, and nothing in +between: at a slow turn, one 25 px jump a notch. The touchpad path was +never quantized (fractions all the way to the placement). Now a notch is +a kick, and the strip eases over ~6 frames. + +### Coming to rest (anim 9, 11) + +Found while measuring the PDF: a slow stream (notches 150 ms apart, just +inside the stream window) ran its constant rate into the mark, stopping +from 2.6 px a frame, and its last speed, never zeroed, then carried it +0.04 row past the mark and back. A stream is now never faster than the +spring's own pace from where it is (omega a unit of lag a second): it eases +onto each mark. The check: "a follow comes to rest without a snap" (a +spin, a page, and notches 144 ms apart: toward the mark only, onto it from +under a third of a pixel, past its fastest frame each step no longer than +the last); it fails on the old rule. + +Measured on every settle the runs have (frames after an input until the +view is still, speeds normalized by the frame's own time): before anim 9 +the old spring's tails were already monotonic; the anim 9+10 stream rule +had one rising tail in the scroll demo's notches (the stop from 2.6 px) +and a last step of 0.88 px; now, over the scroll, stress and PDF runs +(ReleaseSafe and Debug), no tail rises after its fastest frame and the +last step before rest is at most 0.06 px (text) and 0.05 px (PDF). + ### The cursor (anim 4) The thin caret glides as the block does. A step of a cell or less eases @@ -250,7 +311,7 @@ while the view stands still, nor for stretches over 512 KB. | a 200-line paste | one body's slide | a long jump | | terminal output | snaps | a stream would always lag | | terminal under the wheel | glides | the wheel's; keys in its normal mode snap (position 4) | -| PDF | its own scroll | untouched here | +| PDF | glides (its strip, in pixels, anim 11); a touchpad follows | the same rules as text | | no-wrap sideways scroll | snaps | horizontal glides were not asked; position 6 | ## Ponytail pass (on the stack, amended in place) @@ -853,6 +914,68 @@ the 2 s ones were few, the max falls 2801 -> 319. | all | before | 26.1/43.9/74.5/78.0 | 2.1/22.9/44.8/77.5 | 2.1/2.3/15.7/40.8 | 2189 | 1 | 108/15264 | | | after | 24.5/37.8/63.1/70.3 | 4.9/27.5/42.9/68.7 | 15.7/18.5/24.2/39.9 | 2175 | 1 | 101/15264 | +#### GUI: `pdf-scroll` (anim 11), before = anim 10 with the scenario, after = anim 11 + +ReleaseSafe, run 1 of 2 (`.scratch/runs9/v1-*`; run 2 within a few ms but far-jump max): + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| spin | before | 4.7/9.2/33.4/33.4 | 4.7/9.2/33.4/33.4 | - | 1073 | 0 | +| | after | 2.0/6.8/22.0/22.0 | 1.7/6.9/17.2/22.0 | 12.9/16.7/21.8/28.4 | 1009 | 1 | +| held-pagedown | before | 15.3/29.4/31.1/31.1 | 15.2/29.3/31.0/31.0 | - | 9092 | 0 | +| | after | 1.8/19.2/26.8/26.8 | 1.7/9.6/26.7/26.7 | 16.6/20.5/33.9/33.9 | 6359 | 5 | +| far-jump | before | 16.5/32.8/32.8/32.8 | 6.8/18.0/32.7/32.7 | 17.0/17.2/19.1/19.1 | 24126 | 0 | +| | after | 22.6/32.1/32.1/32.1 | 5.8/7.1/32.0/32.0 | 16.6/16.8/18.8/18.8 | 23744 | 0 | +| slow-notches | before | 7.1/7.1/7.1/7.1 | 8.8/9.8/9.8/9.8 | 16.8/17.4/17.4/17.4 | 83 | 0 | +| | after | 6.9/7.0/7.0/7.0 | 1.7/6.7/6.9/6.9 | 16.6/16.8/17.3/17.3 | 87 | 0 | +| slow-touch | before | 6.9/10.7/12.3/12.3 | 6.8/10.6/12.2/12.2 | - | 94 | 0 | +| | after | 6.8/11.0/12.4/12.5 | 6.7/10.9/12.4/12.4 | - | 94 | 0 | + +Debug (`w1-*`): + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| spin | before | 4.8/12.7/148.2/148.2 | 4.7/12.3/148.1/148.1 | - | 1074 | 0 | +| | after | 3.2/7.7/140.4/140.4 | 2.7/7.6/71.8/140.3 | 16.4/16.8/72.2/141.1 | 995 | 2 | +| held-pagedown | before | 78.5/115.5/115.5/115.5 | 78.3/115.3/115.3/115.3 | - | 8296 | 0 | +| | after | 10.1/121.7/127.6/127.6 | 6.5/98.4/127.5/127.5 | 16.6/98.6/141.2/141.2 | 6106 | 4 | +| far-jump | before | 45.4/84.2/84.2/84.2 | 6.2/45.1/83.9/83.9 | 16.6/17.7/18.7/18.7 | 24172 | 0 | +| | after | 51.4/86.9/86.9/86.9 | 6.1/8.5/86.7/86.7 | 16.6/17.5/20.8/20.8 | 23525 | 0 | +| slow-notches | before | 11.4/13.1/13.1/13.1 | 7.5/12.6/12.6/12.6 | 15.6/19.2/19.2/19.2 | 83 | 0 | +| | after | 18.3/19.0/19.0/19.0 | 2.7/11.9/18.5/18.5 | 16.6/16.9/19.2/19.2 | 88 | 0 | +| slow-touch | before | 7.3/11.8/14.1/17.8 | 7.0/11.5/13.8/17.3 | - | 94 | 0 | +| | after | 7.2/11.0/12.5/15.4 | 7.0/10.5/12.3/15.1 | - | 94 | 0 | + +The `panes` timedemo's pdf phase (`u1-*`, RS then Debug): + +| scenario | | latency ms p50/p90/p99/max | frame work ms | present gap ms (moving) | rows/s | late | +|---|---|---|---|---|---|---| +| pdf | before | 6.9/14.8/44.1/46.3 | 6.7/14.5/30.6/44.0 | 16.7/16.8/16.9/16.9 | 4678 | 0 | +| | after | 2.0/7.4/34.8/37.8 | 1.8/6.6/18.4/34.7 | 16.6/16.8/27.2/32.9 | 4678 | 9 | +| pdf | before | 7.6/57.1/149.4/158.8 | 6.3/18.0/142.1/149.3 | 16.6/16.8/17.9/17.9 | 4663 | 0 | +| | after | 3.2/16.2/144.5/155.5 | 2.8/7.2/125.0/144.4 | 16.5/16.8/134.0/149.4 | 4655 | 7 | + +Strip steps between presented frames (px, the probe's `scroll` column is +the strip's drawn y for a focused PDF; cell height 25): + +| phase | before | after | +|---|---|---| +| slow notches (one each 300 ms) | 25 px in one frame a notch, 7 of 7 steps whole lines | p10/p50/p90/max 0.04/0.8/6.8/7.2 px, none a whole line | +| slow touchpad (0.06 line a frame) | 1.5 px every frame | 1.5 px every frame (followed) | +| a spin's steps | 25 px each (a notch a frame, 100 at a burst) | 0.5/16/28/42, a stream | +| settle tails | none (nothing settled) | no rise after the fastest frame; last step <= 0.05 px | + +Latency: the spin and held PageDown answer sooner (the frame that answers +a key no longer renders the pages it moves to before showing it; they +render as the glide's input frames, a stream's, come). The far jumps +(ge, gg, a Look at a page, Back) answer within the before's spread in +ReleaseSafe (p50 16.5/17.8 -> 22.6/14.9 over two runs, max 32.8/31.7 -> +32.1/31.2); in Debug ge's frame renders what the before split between the +`g` prefix's frame (~20 ms, re-rendering pages left banded by a fling) and +ge's own (~40): the same total in one frame (60-67 ms). The `late` frames +are a held PageDown's input frames rendering a page while it moves (33 ms +gaps; before they were not moving frames, and took 30 ms to answer). + ## The coordinator's latency rows, answered - **pages-up-big** (p90 8.8 -> 24): real. The paint-ahead's upward stretch diff --git a/src/FrameStats.zig b/src/FrameStats.zig index ee5ee3f2..cf3b00d3 100644 --- a/src/FrameStats.zig +++ b/src/FrameStats.zig @@ -45,8 +45,9 @@ pub const Frame = struct { /// The shell had no image to draw into (a busy swapchain). skipped: bool = false, /// The shell's motion in it: a scroll's picture offset from the text, - /// rows (0 at rest), and where it drew the caret, its top in rows - /// (the jitter check: a caret on a fixed row must not wobble). + /// rows (0 at rest), or a focused PDF's strip as drawn, pixels down + /// the document; and where it drew the caret, its top in rows (the + /// jitter check: a caret on a fixed row must not wobble). scroll: f32 = 0, caret: f32 = 0, /// From the first input this frame answers to its present's end, µs; @@ -286,6 +287,8 @@ pub const Step = struct { act: union(enum) { /// Wheel notches, down positive, as a mouse's. wheel: i8, + /// A touchpad's scroll, lines down, a fraction (no notch). + touch: f32, key: pardes.Key, /// A named stretch of the run starts (the dump lists them). phase: []const u8, @@ -316,6 +319,7 @@ pub fn named(name: []const u8) ?[]const Step { if (std.mem.eql(u8, name, "stress")) return &stress; if (std.mem.eql(u8, name, "kinds")) return &kinds; if (std.mem.eql(u8, name, "panes")) return &panes; + if (std.mem.eql(u8, name, "pdf-scroll")) return &pdf_scroll; if (std.mem.eql(u8, name, "one")) return &one; if (std.mem.eql(u8, name, "jumps")) return &jumps; if (std.mem.eql(u8, name, "longlines")) return &longlines; @@ -449,6 +453,71 @@ fn scrollSet(steps: []Step, n: *usize, t: *u32) void { t.* += 500; } +/// A PDF's strip put through what moves it (anim 11): a wheel's notches, +/// then spun; PageDown held; the far jumps ge and gg; a Look at a page and +/// Back; then slow: a notch at a time, and a touchpad's drag a pixel or so +/// a frame. +pub const pdf_scroll = blk: { + @setEvalBranchQuota(20_000); + var steps: [512]Step = undefined; + var n: usize = 0; + var t: u32 = 1500; + const at = struct { + fn add(s: []Step, k: *usize, ms: u32, act: @FieldType(Step, "act")) void { + s[k.*] = .{ .at_ms = ms, .act = act }; + k.* += 1; + } + }; + at.add(&steps, &n, t, .{ .exec = "Look ../../docs/design.pdf" }); + t += 2000; + at.add(&steps, &n, t, .{ .phase = "spin" }); + for (0..6) |_| { + at.add(&steps, &n, t, .{ .wheel = 1 }); + t += 150; + } + for (0..60) |_| { + at.add(&steps, &n, t, .{ .wheel = 1 }); + t += 8; + } + t += 600; + for (0..30) |_| { + at.add(&steps, &n, t, .{ .wheel = -1 }); + t += 8; + } + t += 600; + at.add(&steps, &n, t, .{ .phase = "held-pagedown" }); + for (0..20) |_| { + at.add(&steps, &n, t, .{ .key = .{ .cp = pardes.Key.page_down } }); + t += 33; + } + t += 600; + at.add(&steps, &n, t, .{ .phase = "far-jump" }); + for ([_][]const u8{ "e", "g" }) |second| { + at.add(&steps, &n, t, .{ .key = .{ .cp = 'g', .text = "g" } }); + at.add(&steps, &n, t + 20, .{ .key = .{ .cp = second[0], .text = second } }); + t += 800; + } + at.add(&steps, &n, t, .{ .exec = "Look ../../docs/design.pdf:12" }); + t += 800; + at.add(&steps, &n, t, .{ .key = .{ .cp = 'o', .ctrl = true } }); + t += 800; + at.add(&steps, &n, t, .{ .phase = "slow-notches" }); + for (0..8) |_| { + at.add(&steps, &n, t, .{ .wheel = 1 }); + t += 300; + } + at.add(&steps, &n, t, .{ .phase = "slow-touch" }); + for (0..120) |_| { + at.add(&steps, &n, t, .{ .touch = 0.06 }); + t += 16; + } + t += 600; + at.add(&steps, &n, t, .{ .phase = "done" }); + at.add(&steps, &n, t, .end); + const out = steps[0..n].*; + break :blk out; +}; + /// `scrollSet` alone, on the file the session opened: one kind, for a /// profiler's run. pub const one = blk: { diff --git a/src/animation.zig b/src/animation.zig index ae6f9ca0..764aa0b3 100644 --- a/src/animation.zig +++ b/src/animation.zig @@ -949,6 +949,143 @@ test "a flavour's stretched pane lands exactly on its box, and a click finds the } } +/// A view that follows its input (anim 9, 11): the picture's offset from +/// the core's position now (in the view's own unit: rows of text, pixels of +/// a PDF strip; negative, the picture still shows what is above), its speed +/// (units a second), when it was last integrated, and what has been feeding +/// it. The text body (the GUI's Glide) and a PDF strip are each one. +pub const Follow = struct { + offset: f32 = 0, + speed: f32 = 0, + at_ns: u64 = 0, + /// The last inputs (down positive), their spacing, the last's time, and + /// how many came as one stream. + feed: struct { amount: f32 = 0, gap_ns: u64 = 0, last_ns: u64 = 0, count: u16 = 0 } = .{}, + + /// How far the picture may lag, in bodies (a flick past that jumps); + /// how fast it may move, in bodies a second, so moving text stays + /// readable. + pub const reach = 2; + pub const bodies_per_s: f32 = 15; + /// Inputs this close, each the way the last went, are one stream. + pub const stream_ns = 150 * std.time.ns_per_ms; + + /// What a view's size and the flavour make of the rules: the spring at + /// 1.5x the flavour's pace, the speed cap, the lag cap, and the offset + /// under which it is at rest (a tenth of a pixel, in its unit). + pub const Pace = struct { omega: f32, cap: f32, limit: f32, rest: f32 }; + + pub fn pace(motion: Motion, body: f32, rest: f32) Pace { + return .{ .omega = motion.omega * 1.5, .cap = body * bodies_per_s, .limit = body * reach, .rest = rest }; + } + + pub fn moving(follow: *const Follow) bool { + return follow.offset != 0 or follow.speed != 0; + } + + /// An input: the core moved `amount` (down positive). The picture now + /// lags by as much more, its speed as it was. + pub fn kick(follow: *Follow, amount: f32, now_ns: u64, p: Pace) void { + follow.advance(now_ns, p); + follow.offset = std.math.clamp(follow.offset - amount, -p.limit, p.limit); + const f = &follow.feed; + const like = f.count > 0 and (amount > 0) == (f.amount > 0) and now_ns -| f.last_ns < stream_ns; + if (like) { + const gap = now_ns -| f.last_ns; + f.gap_ns = if (f.count == 1) gap else (f.gap_ns + gap) / 2; + f.amount = (f.amount + amount) / 2; + f.count +|= 1; + } else f.* = .{ .amount = amount, .count = 1 }; + f.last_ns = now_ns; + } + + /// The system moved on to `now_ns`. Fed by a stream, at the stream's + /// rate (an input's amount over their spacing), held a lag `lead` + /// behind so a late input never finds it stopped and the stream's end + /// never runs it past its mark; else on the spring, critically damped, + /// from the speed it has. Never faster than `p.cap`. + pub fn advance(follow: *Follow, now_ns: u64, p: Pace) void { + const dt: f32 = @floatCast(@as(f64, @floatFromInt(@min(now_ns -| follow.at_ns, 2 * frame_ns))) / std.time.ns_per_s); + follow.at_ns = now_ns; + if (follow.offset == 0 and follow.speed == 0) return; + const omega = p.omega; + const toward: f32 = if (follow.offset < 0) 1 else -1; + const f = follow.feed; + if (f.count >= 2 and f.gap_ns > 0 and now_ns -| f.last_ns < f.gap_ns * 3 / 2) { + const gap: f32 = @floatCast(@as(f64, @floatFromInt(f.gap_ns)) / std.time.ns_per_s); + const rate = @abs(f.amount) / gap; + const lead = @max(@abs(f.amount), rate / omega); + // ponytail: a gentle pull to the lead (a tenth an input), so the + // per-frame step varies by a tenth; a stream's own jitter beyond + // that shows. An estimate of the input clock if it ever matters. + // A slow stream's lag runs out before its next input: never + // faster than the spring's own pace from there (omega a unit of + // lag a second), so it eases onto the mark, not into it at speed. + const v = std.math.clamp(rate + 0.1 / gap * (@abs(follow.offset) - lead), 0, @min(p.cap, omega * @abs(follow.offset))); + const step = @min(v * dt, @abs(follow.offset)); + follow.offset += toward * step; + follow.speed = if (follow.offset == 0) 0 else toward * v; + return; + } + const x = follow.offset; + // Coming to rest from a stream: never faster than the spring's own + // pace from here (omega a unit of lag a second), so it eases in and + // does not pass its mark. + if (follow.speed * x < 0 and @abs(follow.speed) > omega * @abs(x)) follow.speed = std.math.sign(follow.speed) * omega * @abs(x); + const lead_v = follow.speed + omega * x; + const decay = @exp(-omega * dt); + var next = (x + lead_v * dt) * decay; + var speed = (follow.speed - omega * dt * lead_v) * decay; + if (@abs(next - x) > p.cap * dt) { + next = x + std.math.sign(next - x) * p.cap * dt; + speed = std.math.sign(next - x) * p.cap; + } + follow.offset = next; + follow.speed = speed; + if (@abs(next) < p.rest and @abs(speed) < 10 * p.rest) follow.* = .{ .at_ns = now_ns }; + } +}; + +test "a follow comes to rest without a snap: past its fastest frame each step is shorter, the last under a tenth of a pixel" { + // A flick's spin (a stream of notches, then nothing), one page, and + // notches slow enough that each lag runs out before the next (its + // stream must ease onto each mark, never pass it). + const p = Follow.pace(.{}, 600, 0.1); + for ([_]struct { n: u16, gap_ms: u64 }{ .{ .n = 12, .gap_ms = 16 }, .{ .n = 1, .gap_ms = 16 }, .{ .n = 6, .gap_ms = 144 } }) |run| { + var f: Follow = .{}; + var now: u64 = std.time.ns_per_s; + for (0..run.n) |_| { + f.kick(if (run.n == 1) 600 else 25, now, p); + var waited: u64 = 0; + while (waited < run.gap_ms) : (waited += 8) { + now += 8 * std.time.ns_per_ms; + const was = f.offset; + f.advance(now, p); + // Toward its mark only, and onto it from under a pixel. + try std.testing.expect(f.offset <= 0 and f.offset >= was); + if (f.offset == 0) try std.testing.expect(-was <= 3 * p.rest); + } + } + var last: f32 = std.math.inf(f32); + var before = f.offset; + var frames: usize = 0; + var fastest: f32 = 0; + while (f.moving()) : (frames += 1) { + now += frame_ns; + f.advance(now, p); + const step = @abs(f.offset - before); + try std.testing.expect(@abs(f.offset) <= @abs(before)); + if (f.offset == 0) try std.testing.expect(step <= 3 * p.rest); + fastest = @max(fastest, step); + if (step < fastest) try std.testing.expect(step <= last); + last = step; + before = f.offset; + try std.testing.expect(frames < 120); + } + try std.testing.expect(last <= 0.1); + } +} + /// The focused cursor's quad (docs/render-pipeline.md §5.4), in grid cells: /// four corners, each on its own springs, so a jump smears along its path /// (the leading corners stiffer than the trailing ones, Motion.follow) and diff --git a/src/detached/wire.zig b/src/detached/wire.zig index 9890dc1a..0e141686 100644 --- a/src/detached/wire.zig +++ b/src/detached/wire.zig @@ -12,7 +12,7 @@ const ShaderAnimation = pardes.config.Runtime.ShaderAnimation; /// to be refused, which is what this number is for. /// 8: one layer type: a tag band carries all its rows (not a layer per /// line), and a frame carries the core's placed regions after its layers. -pub const version: u16 = 11; +pub const version: u16 = 12; /// The Chrome palette is carried field by field as its declaration lists /// them, so any change to it changes the wire: bump `version`, then this. @@ -980,6 +980,7 @@ pub fn encodeClient(out: []u8, msg: ClientMsg) Error![]const u8 { .pdf_scroll => |s| { try w.writeByte(s.pane); try w.writeInt(u32, @bitCast(s.delta_pixels), .little); + try w.writeByte(@intFromBool(s.glide)); }, .pinch => |v| try w.writeInt(u32, @bitCast(v), .little), .touch_scroll => |v| try w.writeInt(u32, @bitCast(v), .little), @@ -1043,7 +1044,7 @@ pub fn decodeClient(tag: u8, payload: []const u8) Error!ClientMsg { }, .paste => .{ .event = .{ .paste = try getSlice32(&r) } }, .command => .{ .event = .{ .command = try r.take(try r.takeInt(u16, .little)) } }, - .pdf_scroll => .{ .event = .{ .pdf_scroll = .{ .pane = try getPane(&r), .delta_pixels = try getF32(&r) } } }, + .pdf_scroll => .{ .event = .{ .pdf_scroll = .{ .pane = try getPane(&r), .delta_pixels = try getF32(&r), .glide = try getBool(&r) } } }, .pinch => .{ .event = .{ .pinch = try getF32(&r) } }, .touch_scroll => .{ .event = .{ .touch_scroll = try getF32(&r) } }, .pointer_leave => .{ .event = .pointer_leave }, @@ -1297,9 +1298,10 @@ test "detached wire: every Event variant round-trips" { try testing.expectEqualStrings("clip", (try roundClient(&buf, .{ .event = .{ .paste = "clip" } })).event.paste); try testing.expectEqualStrings("Look /x", (try roundClient(&buf, .{ .event = .{ .command = "Look /x" } })).event.command); { - const got = (try roundClient(&buf, .{ .event = .{ .pdf_scroll = .{ .pane = 2, .delta_pixels = -12.5 } } })).event.pdf_scroll; + const got = (try roundClient(&buf, .{ .event = .{ .pdf_scroll = .{ .pane = 2, .delta_pixels = -12.5, .glide = false } } })).event.pdf_scroll; try testing.expectEqual(@as(u8, 2), got.pane); try testing.expectEqual(@as(f32, -12.5), got.delta_pixels); + try testing.expect(!got.glide); } try testing.expectEqual(@as(f32, 1.25), (try roundClient(&buf, .{ .event = .{ .pinch = 1.25 } })).event.pinch); try testing.expectEqual(@as(f32, -0.75), (try roundClient(&buf, .{ .event = .{ .touch_scroll = -0.75 } })).event.touch_scroll); diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 3f7dd7ca..94eabb6c 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -3617,6 +3617,7 @@ fn wheelAt(g: *Gui, in: *Input, w: WheelTurn, mc: MouseCell) void { in.post(.{ .pdf_scroll = .{ .pane = @intCast(id), .delta_pixels = -w.y * @as(f32, @floatFromInt(g.cell_h)), + .glide = notchOf(w.y, w.integer_y) != null, } }); } else if (!w.mods.shift and pane.isTerminal() and pardes.panes.terminal.ownsWheel(pane)) { // The program's (codex, htop, less): every whole @@ -4338,6 +4339,10 @@ fn runDemo(g: *Gui, in: *Input, core: *pardes.Pardes) void { core.frames.input(now); wheelAt(g, in, .{ .y = @floatFromInt(-notches), .integer_y = -notches }, .{ .col = r.x + r.w / 2, .row = r.y + r.h / 2 }); }, + .touch => |lines| { + core.frames.input(now); + wheelAt(g, in, .{ .y = -lines }, .{ .col = r.x + r.w / 2, .row = r.y + r.h / 2 }); + }, .key => |key| { core.frames.input(now); in.post(.{ .key = key }); @@ -5061,16 +5066,8 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a /// (an ease, a turn through zero); a jump mid-glide adds its rows with the /// speed kept. The spring's settle only comes once the inputs stop. const Glide = struct { - /// The picture's offset from the core's rows now (rows; negative, the - /// picture still shows what is above), its speed (offset's rows a - /// second), and when it was last integrated. - offset: f32 = 0, - speed: f32 = 0, - at_ns: u64 = 0, - /// What has been feeding it: the rows of the last inputs (down - /// positive), their spacing, the last's time, and how many came as one - /// stream. - feed: struct { rows: f32 = 0, gap_ns: u64 = 0, last_ns: u64 = 0, count: u16 = 0 } = .{}, + /// The picture's lag behind the core's rows and its motion (rows). + follow: pardes.animation.Follow = .{}, now_ns: u64 = 0, pane: usize = 0, rect: pardes.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }, @@ -5100,21 +5097,16 @@ const Glide = struct { /// whatever moved it. seen: [pardes.MAX_PANES]struct { serial: u32 = 0, line: i64 = 0, file: u64 = 0, revision: u32 = 0 } = @splat(.{}), - /// How far the picture may lag, in bodies: the rows kept past each - /// edge, so a jump made while one glides carries on from where it is. - const reach = 2; - const bodies_per_s: f32 = 15; - /// Inputs this close, each the way the last went, are one stream. - const stream_ns = 150 * std.time.ns_per_ms; + /// The rows kept past each edge, in bodies, so a jump made while one + /// glides carries on from where it is: as far as the picture may lag. + const reach = pardes.animation.Follow.reach; fn moving(glide: *const Glide) bool { - return glide.offset != 0 or glide.speed != 0 or glide.pending; + return glide.follow.moving() or glide.pending; } fn stop(glide: *Glide) void { - glide.speed = 0; - glide.feed = .{}; - glide.offset = 0; + glide.follow = .{ .at_ns = glide.follow.at_ns }; glide.pending = false; glide.nabove = 0; glide.nbelow = 0; @@ -5126,8 +5118,8 @@ const Glide = struct { /// The glide's lag in the core's lines: its rows, scaled by the lines /// they carried. fn lagLines(glide: *const Glide) f32 { - if (glide.rows_moved == 0) return glide.offset; - return glide.offset * glide.lines_moved / glide.rows_moved; + if (glide.rows_moved == 0) return glide.follow.offset; + return glide.follow.offset * glide.lines_moved / glide.rows_moved; } fn deinit(glide: *Glide, gpa: std.mem.Allocator) void { @@ -5140,70 +5132,18 @@ const Glide = struct { return glide.rect.w -| config.GUTTER; } - /// An input: the core's rows moved by `rows` (down positive) since the - /// last frame. The picture now lags by as many more, its speed as it was. + /// The rules at this body's size: a tenth of a pixel is 5e-3 rows. + fn pace(glide: *const Glide, motion: pardes.animation.Motion) pardes.animation.Follow.Pace { + return pardes.animation.Follow.pace(motion, @floatFromInt(glide.body_h), 5e-3); + } + + /// An input: the core's rows moved by `rows` (down positive). fn kick(glide: *Glide, rows: f32, now_ns: u64, motion: pardes.animation.Motion) void { - glide.advance(now_ns, motion); - // Never more than `reach` bodies behind: a flick past that jumps. - const limit: f32 = @floatFromInt(@as(u32, glide.body_h) * reach); - glide.offset = std.math.clamp(glide.offset - rows, -limit, limit); - const f = &glide.feed; - const like = f.count > 0 and (rows > 0) == (f.rows > 0) and now_ns -| f.last_ns < stream_ns; - if (like) { - const gap = now_ns -| f.last_ns; - f.gap_ns = if (f.count == 1) gap else (f.gap_ns + gap) / 2; - f.rows = (f.rows + rows) / 2; - f.count +|= 1; - } else f.* = .{ .rows = rows, .count = 1 }; - f.last_ns = now_ns; - } - - /// The system moved on to `now_ns`. Fed by a stream, at the stream's - /// rate (rows an input over their spacing), held a lag `lead` behind - /// the text so a late input never finds it stopped and the stream's end - /// never runs it past its mark; else on the flavour's spring at 1.5x - /// its pace, critically damped, from the speed it has. Never more than - /// `bodies_per_s` of the body a second, so moving text stays readable. + glide.follow.kick(rows, now_ns, glide.pace(motion)); + } + fn advance(glide: *Glide, now_ns: u64, motion: pardes.animation.Motion) void { - const dt: f32 = @floatCast(@as(f64, @floatFromInt(@min(now_ns -| glide.at_ns, 2 * pardes.animation.frame_ns))) / std.time.ns_per_s); - glide.at_ns = now_ns; - if (glide.offset == 0 and glide.speed == 0) return; - const omega = motion.omega * 1.5; - const cap = @as(f32, @floatFromInt(glide.body_h)) * bodies_per_s; - const toward: f32 = if (glide.offset < 0) 1 else -1; - const f = glide.feed; - if (f.count >= 2 and f.gap_ns > 0 and now_ns -| f.last_ns < f.gap_ns * 3 / 2) { - const gap: f32 = @floatCast(@as(f64, @floatFromInt(f.gap_ns)) / std.time.ns_per_s); - const rate = @abs(f.rows) / gap; - const lead = @max(@abs(f.rows), rate / omega); - // ponytail: a gentle pull to the lead (a tenth an input), so the - // per-frame step varies by a tenth; a stream's own jitter beyond - // that shows. An estimate of the input clock if it ever matters. - const v = std.math.clamp(rate + 0.1 / gap * (@abs(glide.offset) - lead), 0, cap); - const step = @min(v * dt, @abs(glide.offset)); - glide.offset += toward * step; - glide.speed = toward * v; - return; - } - const x = glide.offset; - // Coming to rest from a stream: never faster than the spring's own - // pace from here (omega a row of lag a second), so it eases in and - // does not pass its mark. - if (glide.speed * x < 0 and @abs(glide.speed) > omega * @abs(x)) glide.speed = std.math.sign(glide.speed) * omega * @abs(x); - const lead_v = glide.speed + omega * x; - const decay = @exp(-omega * dt); - var next = (x + lead_v * dt) * decay; - var speed = (glide.speed - omega * dt * lead_v) * decay; - if (@abs(next - x) > cap * dt) { - next = x + std.math.sign(next - x) * cap * dt; - speed = std.math.sign(next - x) * cap; - } - glide.offset = next; - glide.speed = speed; - if (@abs(next) < 5e-3 and @abs(speed) < 5e-2) { - glide.offset = 0; - glide.speed = 0; - } + glide.follow.advance(now_ns, glide.pace(motion)); } /// Finds how far the pane's body rows moved, `dir` rows at a time, by @@ -5307,11 +5247,11 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { defer core.shell_continuous = glide.moving() or g.sel_glow.fading or g.hover_glow.fading; glide.now_ns = core.now_ns; glide.motion = pardes.animation.Motion.of(core.settings.motion); - if (glide.offset != 0 or glide.speed != 0) { + if (glide.follow.offset != 0 or glide.follow.speed != 0) { glide.advance(core.now_ns, glide.motion); core.needs_frame = true; - if (glide.offset == 0) { - glide.offset = 0; + if (glide.follow.offset == 0) { + glide.follow.offset = 0; glide.nabove = 0; glide.nbelow = 0; glide.lines_moved = 0; @@ -5425,16 +5365,16 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde g.scroll_body_y = y0; g.scroll_body_h = bh; var shifted = layout; - shifted.y_off -= glide.offset * layout.h; + shifted.y_off -= glide.follow.offset * layout.h; const kept = holdContext(g, surface, glide.pane, held, bh, layout); shifted.y_off += kept.lift; var n: u32 = 0; // Only the rows the scissor shows: lagging a body or more, every body // row is past the edge, and drawing them all was twice the frame's // instances for the length of a long glide. - const lag: u16 = @intFromFloat(@min(@floor(@abs(glide.offset)), @as(f32, @floatFromInt(bh)))); - var row = y0 + kept.rows + if (glide.offset > 0) lag else 0; - const row_end = y0 + bh - if (glide.offset < 0) lag else 0; + const lag: u16 = @intFromFloat(@min(@floor(@abs(glide.follow.offset)), @as(f32, @floatFromInt(bh)))); + var row = y0 + kept.rows + if (glide.follow.offset > 0) lag else 0; + const row_end = y0 + bh - if (glide.follow.offset < 0) lag else 0; while (row < row_end) : (row += 1) { const line = surface.cells[@as(usize, row) * surface.cols ..][0..surface.cols]; const row_cursor: ?usize = if (surface.cursor) |cu| if (cu.y == row) cu.x else null else null; @@ -5448,13 +5388,13 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde } // The gap: rows past the top while the picture lags a move down, past // the bottom for one up; as many as it opens. - const gap: u16 = @intFromFloat(@min(@ceil(@abs(glide.offset)), @as(f32, @floatFromInt(@as(u32, bh) * Glide.reach)))); - const nkept = if (glide.offset < 0) glide.nabove else glide.nbelow; - const rows = if (glide.offset < 0) glide.above else glide.below; + const gap: u16 = @intFromFloat(@min(@ceil(@abs(glide.follow.offset)), @as(f32, @floatFromInt(@as(u32, bh) * Glide.reach)))); + const nkept = if (glide.follow.offset < 0) glide.nabove else glide.nbelow; + const rows = if (glide.follow.offset < 0) glide.above else glide.below; for (0..@min(gap, nkept)) |i| { const cells = rows[i * bw ..][0..bw]; // Row -1 - i above the body, or bh + i below it, in grid rows. - const at_row: i32 = if (glide.offset < 0) @as(i32, y0) - 1 - @as(i32, @intCast(i)) else @as(i32, y0) + bh + @as(i32, @intCast(i)); + const at_row: i32 = if (glide.follow.offset < 0) @as(i32, y0) - 1 - @as(i32, @intCast(i)) else @as(i32, y0) + bh + @as(i32, @intCast(i)); var at = shifted; // emitInstance takes an unsigned row: move the layout instead. at.y_off += @as(f32, @floatFromInt(at_row - @as(i32, y0))) * layout.h; @@ -5514,7 +5454,7 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe g.glide.measure(gpa, s); // Its two rows: the picture two rows behind, the rows that left kept, // nearest first. - try std.testing.expectApproxEqAbs(@as(f32, -2), g.glide.offset, 1e-4); + try std.testing.expectApproxEqAbs(@as(f32, -2), g.glide.follow.offset, 1e-4); try std.testing.expectEqual(@as(u16, 2), g.glide.nabove); try std.testing.expect(sameRow(g.glide.above[0 .. r.w - config.GUTTER], row_before)); // Frame by frame it comes back, never past, and settles. @@ -5523,11 +5463,11 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe now += 7 * ms; core.advance(now); stepGlide(&g, core, gpa); - try std.testing.expect(g.glide.offset <= 1e-4); + try std.testing.expect(g.glide.follow.offset <= 1e-4); if (frames > 200) return error.NeverSettled; } try std.testing.expect(frames > 5); - try std.testing.expectEqual(@as(f32, 0), g.glide.offset); + try std.testing.expectEqual(@as(f32, 0), g.glide.follow.offset); try std.testing.expect(!core.shell_continuous); // Motion off: a notch lands at once. core.settings.motion = .off; @@ -5560,7 +5500,7 @@ const GlideRun = struct { const s = try core.render(arena.allocator()); if (g.glide.pending) g.glide.measure(gpa, s); if (g.glide.moving()) g.glide.advance(g.glide.now_ns, g.glide.motion); - seq.offsets[frame] = g.glide.offset; + seq.offsets[frame] = g.glide.follow.offset; seq.lines[frame] = @intCast(core.panes[core.active].?.file.?.scroll); seq.carets[frame] = caretRow(g, s) orelse -1; seq.cells[frame] = if (s.cursor) |cu| @floatFromInt(cu.y) else -1; @@ -5809,7 +5749,7 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 { g.scroll_held_px = 0; - if (g.glide.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page, held); + if (g.glide.follow.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page, held); const scroll_pane = g.scroll_pane orelse return 0; if (g.scroll_lag == 0) return 0; for (surface.panelTracks()) |track| @@ -6436,7 +6376,7 @@ fn renderFrame( if (chrome.fx & 8 != 0 and chrome.decor_dots != null) for (surface.regionList()) |region| { if (region.kind != .body or cell_decor.nbodies == cell_decor.bodies.len) continue; var rows: f32 = @floatFromInt(region.line); - if (g.glide.moving() and g.glide.pane == region.owner) rows += g.glide.offset; + if (g.glide.moving() and g.glide.pane == region.owner) rows += g.glide.follow.offset; const period = cell_decor.uniforms[4]; cell_decor.bodies[cell_decor.nbodies] = bodyPixels(region, layout); cell_decor.shifts[cell_decor.nbodies] = @mod(-rows * layout.h * 0.25, period); @@ -6463,12 +6403,14 @@ fn renderFrame( const blink_alpha: f32 = if (blinkNow(g, chrome)) |b| b.alpha else 1; // While a glide moves the text, the caret is its quad, drawn from its // own springs, not a cell of the moving rows. - const quad_mode = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or blink_alpha < 1 or g.glide.offset != 0); + const quad_mode = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or blink_alpha < 1 or g.glide.follow.offset != 0); g.cursor_quad_alpha = if (quad_mode) chrome.cursor_alpha * blink_alpha else 0; // The probe's view of this frame's motion (FrameStats.Frame). if (core) |p| { const probe = &@constCast(p).frames; - probe.scroll = g.glide.offset; + // A focused PDF's strip is the core's (pdf_view.draw). + const pdf_focus = if (p.panes[p.active]) |pane| pane.hasPdf() else false; + if (!pdf_focus) probe.scroll = g.glide.follow.offset; probe.caret = caretRow(g, surface) orelse 0; } const cursors_shown = groups.tracks == 0 and !quad_mode; @@ -6726,7 +6668,7 @@ fn renderFrame( for (groups.items[0..groups.len], 0..) |group, index| std.debug.assert(cell_next[index] == group.cell_start + group.cell_count); // The body's context rows, which its scroll leaves where they are. - const scrolling: ?usize = if (g.glide.offset != 0) g.glide.pane else g.scroll_pane; + const scrolling: ?usize = if (g.glide.follow.offset != 0) g.glide.pane else g.scroll_pane; const held: u16 = if (core) |p| if (scrolling) |id| if (p.panes[id]) |pane| pane.context_rows else 0 else 0 else 0; shifted = emitScrollRows(g, instances, cell_total, surface, layout, win_w, win_h, page, held); // Over a theme's plaques a see-through cell with no ink blends to @@ -9620,7 +9562,7 @@ fn paneDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ti if (rail.thumb_h != 0 and rail.thumb_span > 0) { // In pixels, not rows, and with the picture while it glides // or lags behind the core's rows (both in rows of the body). - const lag: f32 = if (g.glide.offset != 0 and g.glide.pane == rail.owner) + const lag: f32 = if (g.glide.follow.offset != 0 and g.glide.pane == rail.owner) g.glide.lagLines() else if (g.scroll_pane != null and g.scroll_pane.? == rail.owner) g.scroll_lag else 0; const track_px = body_y1 - y0; @@ -10261,13 +10203,13 @@ test "the scrollbar thumb moves by the pixel and follows a glide" { // A line of a thousand moves it a fraction of a row, not 0 or 20 px. try std.testing.expect(at11 > at10 and at11 - at10 < 1); g.glide.pane = core.active; - g.glide.offset = -1; + g.glide.follow.offset = -1; try std.testing.expectApproxEqAbs(at10, try thumb.top(&g, core), 1e-3); // A wrapped line: the picture moved two rows for the one line, and the // thumb lags the line, not two. g.glide.lines_moved = 1; g.glide.rows_moved = 2; - g.glide.offset = -2; + g.glide.follow.offset = -2; try std.testing.expectApproxEqAbs(at10, try thumb.top(&g, core), 1e-3); } @@ -10757,7 +10699,7 @@ const max_cursors = 1 + pardes.MAX_PANES + pardes.MAX_TAG_LAYERS; fn caretRow(g: *const Gui, surface: *const pardes.Surface) ?f32 { const chrome = &surface.chrome; const cursor = surface.cursor orelse return null; - const quad = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or g.glide.offset != 0); + const quad = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or g.glide.follow.offset != 0); return if (quad) chrome.cursor_quad[1] else @floatFromInt(cursor.y); } diff --git a/src/pardes.zig b/src/pardes.zig index 0f3f87f2..829a7bfd 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -3690,7 +3690,9 @@ pub const Event = union(enum) { command: []const u8, /// Native shells may preserve sub-cell wheel distance in physical pixels. /// TTY button events still enter through the ordinary mouse path. - pdf_scroll: struct { pane: u8, delta_pixels: f32 }, + /// `glide`: a wheel's notch, which the strip glides; a touchpad's + /// fraction is followed as it comes. + pdf_scroll: struct { pane: u8, delta_pixels: f32, glide: bool = true }, pinch: f32, touch_scroll: f32, /// The host pointer left the drawable area. Unlike an out-of-range motion, @@ -6164,7 +6166,7 @@ pub const Pardes = struct { if (scroll.pane < MAX_PANES) { if (p.panes[scroll.pane]) |pane| { if (pane.hasPdf() and p.native_images) - _ = panes.Pdf.scrollPane(p, pane, @floatCast(scroll.delta_pixels)); + _ = panes.Pdf.scrollPane(p, pane, @floatCast(scroll.delta_pixels), scroll.glide); } } } @@ -7737,7 +7739,7 @@ pub const Pardes = struct { /// is for the stepped animations, which count frames of `frame_ns`. pub fn continuous(p: *const Pardes) bool { for (p.lifts) |spring| if (!spring.settled) return true; - return p.cursor_glide.moving() or p.shell_continuous; + return p.cursor_glide.moving() or p.shell_continuous or panes.Pdf.moving(p); } /// For shells that only need a yes or no: macOS and the board, which diff --git a/src/pdf_view.zig b/src/pdf_view.zig index 2a89ef01..37e4b216 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -197,6 +197,81 @@ test "PDF selections retain their owning page across page focus" { try std.testing.expectEqual(@as(usize, 0), state.selection_text.len); } +test "a PDF strip glides a notch and a page to their marks, eased and never past them, and follows a touchpad's fraction at once" { + if (comptime !enabled) return; + const gpa = std.testing.allocator; + var state = try State.open(gpa, "docs/design.pdf", 1); + defer state.deinit(gpa); + const view: Viewport = .{ .pixel_w = 800, .pixel_h = 600 }; + const motion = pardes.animation.Motion.of(.smooth); + ensureLayout(&state, view); + var now: u64 = std.time.ns_per_s; + try std.testing.expectEqual(state.document_scroll_y, stripAt(&state, view, motion, now)); + for ([_]f64{ 20, 600 }) |step| { + const from = state.document_scroll_y; + _ = scrollDocument(&state, view, step); + const mark = state.document_scroll_y; + // The input's frame still shows where it was; then it eases in. + var shown = stripAt(&state, view, motion, now); + try std.testing.expectEqual(from, shown); + var last_step: f64 = 0; + var peaked = false; + for (0..60) |_| { + now += pardes.animation.frame_ns; + const next = stripAt(&state, view, motion, now); + const moved = next - shown; + try std.testing.expect(moved >= 0 and next <= mark); + // Past its fastest, each frame's step is no longer than the last. + if (moved < last_step) peaked = true; + if (peaked) try std.testing.expect(moved <= last_step + 1e-9); + last_step = moved; + shown = next; + } + try std.testing.expectEqual(mark, shown); + try std.testing.expect(!state.follow.moving()); + try std.testing.expect(last_step <= 1); + } + // A touchpad's fraction: drawn where the core is, the same frame. + const from = state.document_scroll_y; + _ = scrollDocument(&state, view, 0.25); + state.direct_y += state.document_scroll_y - from; + try std.testing.expectEqual(from + 0.25, stripAt(&state, view, motion, now)); +} + +test "a PDF glide renders the pages it crosses in its input's frame, but a far jump's only where it comes to rest" { + if (comptime !enabled) return; + const gpa = std.testing.allocator; + var state = try State.open(gpa, "docs/design.pdf", 1); + defer state.deinit(gpa); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const view: Viewport = .{ .pixel_w = 400, .pixel_h = 300 }; + const motion = pardes.animation.Motion.of(.smooth); + const key: TintKey = .{ .mode = .disabled, .colors = undefined }; + const none: HighlightInput = .{ .hover_color = .{ 0, 0, 0 }, .selection_color = .{ 0, 0, 0 } }; + ensureLayout(&state, view); + const frame = struct { + fn f(st: *State, a: *std.heap.ArenaAllocator, m: pardes.animation.Motion, k: TintKey, h: HighlightInput) void { + const v: Viewport = .{ .pixel_w = 400, .pixel_h = 300 }; + const shown = stripAt(st, v, m, std.time.ns_per_s); + st.document_scroll_y = shown; + _ = renderFrame(st, std.testing.allocator, a.allocator(), v, pardes.pdf_raster_policy, k, h, st.drawn_y - shown, st.far); + st.document_scroll_y = st.drawn_y; + } + }.f; + frame(&state, &arena, motion, key, none); + // A body down, onto page one's lower part: what it crosses is drawn. + _ = scrollDocument(&state, view, 300); + frame(&state, &arena, motion, key, none); + try std.testing.expect(!state.far and rasterForPage(&state, 0) != null); + // Far, to page three: only it; the slide comes in over page two's place. + state.document_scroll_y = @floatFromInt(state.page_starts[3]); + frame(&state, &arena, motion, key, none); + try std.testing.expect(state.far); + try std.testing.expect(rasterForPage(&state, 3) != null); + try std.testing.expect(rasterForPage(&state, 2) == null); +} + pub const Raster = if (enabled) struct { valid: bool = false, page: usize = 0, @@ -249,6 +324,15 @@ pub const State = if (enabled) struct { layout_fit: FitMode = .width, layout_valid: bool = false, document_scroll_y: f64 = 0, + /// The strip as drawn lags `document_scroll_y` by `follow` (anim 11, + /// the text's motion system, in pixels): `drawn_y` is where the core + /// stood at the last frame, `direct_y` what moved it since that the + /// picture takes as it comes (a touchpad, a relayout). + follow: pardes.animation.Follow = .{}, + drawn_y: f64 = 0, + direct_y: f64 = 0, + /// The last kick was a jump past a body (renderFrame's `far`). + far: bool = false, scroll_to_page_pending: bool = true, rasters: [raster_max]Raster = undefined, rasters_len: usize = 0, @@ -869,23 +953,28 @@ fn pageAtOffset(state: *const State, offset: f64) usize { return if (y >= end and lo + 1 < state.page_count) lo + 1 else lo; } -fn pageVisible(state: *const State, page: usize, viewport: Viewport) bool { +fn pageVisible(state: *const State, page: usize, y: f64, h: f64) bool { if (comptime !enabled) return false; - const top = @as(f64, @floatFromInt(state.page_starts[page])) - state.document_scroll_y; + const top = @as(f64, @floatFromInt(state.page_starts[page])) - y; const bottom = top + @as(f64, @floatFromInt(state.page_heights[page])); - return bottom > 0 and top < @as(f64, @floatFromInt(viewport.pixel_h)); + return bottom > 0 and top < h; } pub fn visiblePages(state: *const State, viewport: Viewport) VisiblePages { + return pagesOver(state, state.document_scroll_y, @floatFromInt(viewport.pixel_h)); +} + +/// The pages over the strip from `y`, `h` pixels down. +fn pagesOver(state: *const State, y: f64, h: f64) VisiblePages { if (comptime !enabled) return .{}; var out: VisiblePages = .{}; - var page = pageAtOffset(state, state.document_scroll_y); - if (page > 0 and pageVisible(state, page - 1, viewport)) page -= 1; + var page = pageAtOffset(state, y); + if (page > 0 and pageVisible(state, page - 1, y, h)) page -= 1; out.first = page; while (page < state.page_count) : (page += 1) { - const top = @as(f64, @floatFromInt(state.page_starts[page])) - state.document_scroll_y; - if (top >= @as(f64, @floatFromInt(viewport.pixel_h))) break; - if (pageVisible(state, page, viewport)) out.len += 1; + const top = @as(f64, @floatFromInt(state.page_starts[page])) - y; + if (top >= h) break; + if (pageVisible(state, page, y, h)) out.len += 1; } return out; } @@ -1496,18 +1585,31 @@ pub fn renderFrame( policy: RasterPolicy, tint_key: TintKey, highlight_input: HighlightInput, + path: f64, + far: bool, ) VisiblePages { if (comptime !enabled) return .{}; ensureLayout(state, viewport); state.resolveSearch(gpa); const highlights = buildHighlights(state, arena, highlight_input) catch Highlights{}; const request = renderRequest(viewport, policy, state.fit); - var visible = visiblePages(state, viewport); + // ponytail: every page the glide crosses to its mark (`path` pixels + // on) renders now, in the input's frame, so no frame of the glide + // waits on MuPDF (it renders on the loop). A far jump's slide (`far`) + // comes in over what is there, none of the page above its mark, which + // would cost the input's frame a page; a render thread would draw it. + const span = struct { + fn f(st: *const State, view: Viewport, along: f64, from_rest: bool) VisiblePages { + const h: f64 = @floatFromInt(view.pixel_h); + return if (from_rest) pagesOver(st, st.document_scroll_y + along, h) else pagesOver(st, st.document_scroll_y + @min(0, along), h + @abs(along)); + } + }.f; + var visible = span(state, viewport, path, far); reconcile(state, gpa, request, tint_key, highlights, visible, viewport); rearmSearchReveal(state, viewport); revealSearch(state, viewport, activeGeometry(state, viewport)); - visible = visiblePages(state, viewport); + visible = span(state, viewport, path, far); reconcile(state, gpa, request, tint_key, highlights, visible, viewport); return visible; } @@ -1898,6 +2000,7 @@ pub fn ensureLayout(state: *State, viewport: Viewport) void { if (comptime !enabled) return; const tz = tracy.zone(@src(), "pdf.ensure_layout"); defer tz.end(); + var relaid = false; if (state.layout_valid and !state.scroll_to_page_pending and !state.layout_anchor_pending and (state.layout_viewport_w != viewport.pixel_w or @@ -1919,6 +2022,7 @@ pub fn ensureLayout(state: *State, viewport: Viewport) void { state.layout_viewport_h = viewport.pixel_h; state.layout_fit = state.fit; state.layout_valid = true; + relaid = true; if (state.scroll_to_page_pending) { state.document_scroll_y = @floatFromInt(state.page_starts[state.page]); state.scroll_to_page_pending = false; @@ -1933,6 +2037,12 @@ pub fn ensureLayout(state: *State, viewport: Viewport) void { consumeOutlineReveal(state, viewport); const max_scroll = @as(f64, @floatFromInt(state.document_height -| viewport.pixel_h)); state.document_scroll_y = std.math.clamp(state.document_scroll_y, 0, max_scroll); + // A new layout is not a scroll: the picture is drawn there at once. + if (relaid) { + state.follow = .{}; + state.drawn_y = state.document_scroll_y; + state.direct_y = 0; + } } pub const WordProbe = if (enabled) struct { @@ -2688,23 +2798,55 @@ pub fn panPane( return panPixels(state, placed, axis, direction, display_pixels); } -pub fn scrollPane(core: *pardes.Pardes, pane: *pardes.Pane, delta_pixels: f64) bool { +/// `glide`: a notch, which the strip glides; else a touchpad's fraction, +/// which it follows as it comes. +pub fn scrollPane(core: *pardes.Pardes, pane: *pardes.Pane, delta_pixels: f64, glide: bool) bool { if (comptime !enabled) return false; const tz = tracy.zone(@src(), "pdf.scroll_notch"); defer tz.end(); const state = &(pane.pdf orelse return false); const view = ensurePaneLayout(core, pane) orelse return false; + const from = state.document_scroll_y; const result = scrollDocument(state, view, delta_pixels) orelse return false; + if (!glide) state.direct_y += state.document_scroll_y - from; if (result.active_page != state.page) activatePage(core, pane, result.active_page, false); return true; } +/// Where the strip is drawn this frame (anim 11): what moved the core's +/// position since the last frame kicks its follow, as a scroll kicks the +/// text's, all but what moved it directly; the follow then moves on to now. +fn stripAt(state: *State, view: Viewport, motion: pardes.animation.Motion, now_ns: u64) f64 { + const pace = pardes.animation.Follow.pace(motion, @floatFromInt(view.pixel_h), 0.1); + const moved = state.document_scroll_y - state.drawn_y - state.direct_y; + state.drawn_y = state.document_scroll_y; + state.direct_y = 0; + if (motion.instant) { + state.follow = .{}; + } else if (moved != 0) { + // A move past a body slides one, as a text's far jump does (G6): + // the pages between are rendered for the slide, not crossed. + const body: f64 = @floatFromInt(view.pixel_h); + state.far = @abs(moved) > body; + state.follow.kick(@floatCast(std.math.clamp(moved, -body, body)), now_ns, pace); + } else state.follow.advance(now_ns, pace); + const max_scroll = @as(f64, @floatFromInt(state.document_height -| view.pixel_h)); + return std.math.clamp(state.drawn_y + state.follow.offset, 0, max_scroll); +} + +/// A PDF strip is still on its way to where the core stands. +pub fn moving(core: *const pardes.Pardes) bool { + if (comptime !enabled) return false; + for (core.panes) |slot| if (slot) |pane| if (pane.pdf) |state| if (state.follow.moving()) return true; + return false; +} + pub fn verticalWheel(core: *pardes.Pardes, pane: *pardes.Pane, direction: i8) void { if (comptime !enabled) return; if (!core.native_images) return stepPanePage(core, pane, direction); const rows: u32 = @intCast(@max(1, config.wheel_rows)); const pixels = scaledStep(core.cell_pixels.h, rows); - _ = scrollPane(core, pane, @as(f64, @floatFromInt(pixels)) * direction); + _ = scrollPane(core, pane, @as(f64, @floatFromInt(pixels)) * direction, true); } pub fn horizontalWheel(core: *pardes.Pardes, pane: *pardes.Pane, direction: i8) void { @@ -2730,6 +2872,14 @@ pub fn draw( const state = &(pane.pdf orelse return false); const view = paneViewport(core, pane) orelse return false; const key = TintKey{ .mode = state.tint, .colors = tintColors(core) }; + ensureLayout(state, view); + // Drawn where the strip's follow is; the core's position comes back + // after (`drawn_y`), unless a search's reveal moved it as it drew, + // which is then drawn there at once. + const shown = stripAt(state, view, pardes.animation.Motion.of(core.settings.motion), core.now_ns); + state.document_scroll_y = shown; + defer state.document_scroll_y = state.drawn_y; + if (pane_id == core.active) core.frames.scroll = @floatCast(shown); const visible = renderFrame( state, core.pdf_gpa, @@ -2738,7 +2888,13 @@ pub fn draw( pardes.pdf_raster_policy, key, highlightInput(core, pane_id, pane), + state.drawn_y - shown, + state.far, ); + if (state.document_scroll_y != shown) { + state.follow = .{}; + state.drawn_y = state.document_scroll_y; + } var placed_any = false; var page = visible.first; const visible_end = visible.first + visible.len; diff --git a/test/pdf.zig b/test/pdf.zig index d4efdfaf..5f7ebc52 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -774,6 +774,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { .rows = 24, }); defer p.deinit(); + p.settings.motion = .off; // placements, not the glide (anim 11) const pane = p.panes[0].?; try std.testing.expect(hasPdf(pane)); try std.testing.expect(pane.pdf.?.page_count > 1); @@ -822,7 +823,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { // SDL's raw dy path retains fractions in the placement itself; it does // not leave native pixels fixed while only the underlying cells slide. - p.update(.{ .pdf_scroll = .{ .pane = 0, .delta_pixels = 0.25 } }); + p.update(.{ .pdf_scroll = .{ .pane = 0, .delta_pixels = 0.25, .glide = false } }); try std.testing.expectEqual(@as(f64, 0.25), pane.pdf.?.document_scroll_y); _ = frame.reset(.retain_capacity); const fractional = try p.render(frame.allocator()); @@ -940,7 +941,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" { page0_revision, panes.Pdf.rasterForPage(&pane.pdf.?, 0).?.revision, ); - try std.testing.expect(panes.Pdf.scrollPane(p, pane, 1)); + try std.testing.expect(panes.Pdf.scrollPane(p, pane, 1, false)); try std.testing.expectEqual(@as(usize, 1), pane.pdf.?.page); try std.testing.expectEqual( page1_revision, @@ -1142,7 +1143,7 @@ test "a fling's banded pages show the reader exactly what whole pages would" { // is counted the way a wheel batch counts it. pv.document_scroll_y = 0; pv.scroll_travel = 0; - try std.testing.expect(panes.Pdf.scrollPane(p, pane, landing)); + try std.testing.expect(panes.Pdf.scrollPane(p, pane, landing, false)); _ = frame.reset(.retain_capacity); const flung = try p.render(frame.allocator()); try std.testing.expect(flung.nimages >= 2); @@ -1261,7 +1262,7 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh defer gpa.free(middle); var middle_y: usize = 0; for ([_]f64{ 0, @round(max_scroll / 2), max_scroll }, 0..) |at, step| { - _ = panes.Pdf.scrollPane(p, pane, at - pv.document_scroll_y); + _ = panes.Pdf.scrollPane(p, pane, at - pv.document_scroll_y, false); pv.scroll_travel = 0; // read, not flung _ = frame.reset(.retain_capacity); const surface = try p.render(frame.allocator()); @@ -1291,7 +1292,7 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh // Straight back to the middle from the foot: the rows rendered afresh // are the very rows rendered on the way down, so no seam moves with the // path a reader took. - _ = panes.Pdf.scrollPane(p, pane, @round(max_scroll / 2) - pv.document_scroll_y); + _ = panes.Pdf.scrollPane(p, pane, @round(max_scroll / 2) - pv.document_scroll_y, false); pv.scroll_travel = 0; _ = frame.reset(.retain_capacity); const again = (try p.render(frame.allocator())).images[0].?; @@ -1305,7 +1306,7 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh middle[(common_top - middle_y) * stride .. (common_end - middle_y) * stride], again.rgba[(common_top - again_y) * stride .. (common_end - again_y) * stride], ); - _ = panes.Pdf.scrollPane(p, pane, max_scroll - pv.document_scroll_y); + _ = panes.Pdf.scrollPane(p, pane, max_scroll - pv.document_scroll_y, false); pv.scroll_travel = 0; _ = frame.reset(.retain_capacity); const foot = try gpa.dupe(u8, (try p.render(frame.allocator())).images[0].?.rgba); @@ -1663,6 +1664,7 @@ test "PDF tint and tinted theme changes rebuild every visible raster only" { .rows = 24, }); defer p.deinit(); + p.settings.motion = .off; // placements, not the glide (anim 11) const pane = p.panes[0].?; const pv = &pane.pdf.?; p.native_images = true; -- cgit v1.3 From 706b9d98fdce29a58ffe5a8a5417d6b2810e6d2c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 23:16:11 -0300 Subject: anim 12: the tty runs the GUI's motion system: the view's glide moves to src/glide.zig (Glide, its step: find the view that moved, snapshot, measure, kick), the GUI keeps only its wheel notches and its pixel draw; the tty steps it each loop and draws it at whole rows (glide.shifted: the position rounded, never the step, the rows that left in the gap, a caret whose line rode the scroll carried with it, one that kept its row left still); rows that only disagree glide the core's lines instead of snapping; the snapshot harness's virtual clock runs a frame a wake while it moves --- docs/next-anim.md | 59 +++++++- src/glide.zig | 415 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/gui.zig | 279 +----------------------------------- src/pardes.zig | 2 + src/tty/tty.zig | 27 +++- 5 files changed, 505 insertions(+), 277 deletions(-) create mode 100644 src/glide.zig (limited to 'docs/next-anim.md') diff --git a/docs/next-anim.md b/docs/next-anim.md index 9c9610e7..e1d7e14f 100644 --- a/docs/next-anim.md +++ b/docs/next-anim.md @@ -28,6 +28,7 @@ Positions, not a verdict: argue with them. | anim 9 `nqznmskw` | the view's motion is one system: a stream of inputs moves it at its own rate, the spring only settles it | | anim 10 `umnwnrvn` | the caret is its own body: drawn from its own springs, never carried by the text's glide | | anim 11 `knzzzknu` | the integrator is `animation.Follow`; a PDF's strip moves in it, in pixels; a slow stream eases onto its mark | +| anim 12 `nqmoxkwz` | the tty runs the same glide (`src/glide.zig`), drawn at whole rows | Tests (one check each, `-Dtest-filter`): "frame stats: gaps into a motion count as jank ...", "every scroll glides on one law ...", "a cursor eases @@ -254,6 +255,62 @@ between: at a slow turn, one 25 px jump a notch. The touchpad path was never quantized (fractions all the way to the placement). Now a notch is a kick, and the strip eases over ~6 frames. +### The tty, the same system (anim 12) + +The glide is shared now (`src/glide.zig`: the Glide, and its step that +finds the view that moved, snapshots the body and measures the move); the +GUI keeps only its wheel notches and its pixel draw. The tty steps the same +glide each loop (`pollFrame`), integrates it on its 16 ms ticks, and draws +it at whole rows (`glide.shifted`): the body's rows moved by the offset +rounded, the position never the step, the rows that left in the gap. So a +flick's fast part moves several rows a tick as the body dictates and its +tail is one-row steps further and further apart: a deceleration in the +timing, not in the step. The end is the instant version's. The caret: one +whose line rode the scroll (a wheel's) is carried with its rows; one that +kept its row (a page, a held j at the bottom) stays on its cell, still. + +Checks: "the tty draws a glide at whole rows" (a flick and a spin: once +slowing, steps a tick never grow, one-row steps never closer together, to +where the core is; then j held on the bottom row: the caret's row is the +same every tick). The timedemos typed into a pty (160x50, `ttydemo.py`, +RS): past each glide's fastest tick, steps never grew in the decelerating +part of any of 24 (scroll) and 186 (stress) glides, and the ticks between +one-row steps never shrank; the only growth is at a stream's constant +speed, where the rounding alternates (5, 4, 5, 4 rows a tick at the 4.5 a +tick cap). Bytes: a tick costs a body repaint (p50 7.4-7.9 KB, max +13.4-15.3 KB, the before's max), so a glide costs its row steps' worth: +the scroll demo wrote 383 -> 990 KB, the stress demo 3.8 -> 7.1 MB. Terminal +scroll regions would make a one-row step a few bytes (position 8). + +| tty | | latency ms p50/p90/p99/max | frame work ms | moving gap ms | bytes/frame p50/max | +|---|---|---|---|---|---| +| RS scroll | before | 2.3/3.0/11.5/11.5 | 2.2/2.7/8.5/11.0 | 15.9/16.7/18.8/18.8 | 120/15264 | +| | after | 2.5/3.1/11.5/11.5 | 2.3/2.8/4.4/11.9 | 15.7/16.7/18.4/18.7 | 0/15264 | +| RS stress | before | 1.4/2.9/5.9/15.6 | 1.1/2.7/4.9/14.1 | 15.6/16.6/18.4/18.4 | 140/13383 | +| | after | 1.5/2.8/5.5/14.0 | 1.9/2.9/3.8/12.5 | 14.3/16.5/18.1/19.0 | 7363/13383 | +| Debug scroll | before | 9.4/14.5/28.7/28.7 | 6.0/13.0/21.2/36.2 | 15.5/19.0/21.7/21.7 | 128/15264 | +| | after | 6.0/13.8/44.0/44.0 | 6.1/9.9/17.0/27.3 | 15.5/19.6/24.9/26.0 | 0/15264 | +| Debug stress | before | 2.4/13.0/92.9/148.4 | 2.2/10.8/68.2/148.1 | 15.6/18.7/25.4/25.4 | 6858/13383 | +| | after | 2.8/10.3/90.5/180.3 | 2.7/7.7/56.7/180.2 | 12.8/17.6/65.0/180.4 | 7270/13383 | + +Found on the way (sample 1): at a spin's end the measure found no shift +under which the rows agreed (the colours painted ahead arrive as it +stops) and gave the glide up, a 1.6-row snap on the last frame, in the +merge head as in anim 9-11. When the core moved a few lines and the rows +only disagree, the lines are the rows' guess now: it glides them, and the +spin's settle is whole (33, 4, 1.8 ... 0.03 px, never growing). Re-measured +on the head (stress, RS): the caret under a held j moves 0.0 rows frame to +frame over the 144 frames the view moves; every settle's steps never grow +after its fastest frame, the last at most 0.05 px. The snapshot harness's +virtual clock moves a frame a wake while the glide moves (it only moved to +the next due wait, so a tty glide stood still there): all 110 scripts pass, +no golden changed. + +(The Debug maxima are single frames of highlight paint on the 1.6 MB +file, as before; ponytail: a terminal's scrollback under the tty's wheel +lands, it reaches the core as a mouse event the GUI's notch count does not +see.) + ### Coming to rest (anim 9, 11) Found while measuring the PDF: a slow stream (notches 150 ms apart, just @@ -1045,6 +1102,6 @@ gaps; before they were not moving frames, and took 30 ms to answer). one frame later in Debug); a second open still decodes again (no cache: a Restore is rare). 8. **The tty** has no vsync and no sub-cell motion: it is paced (a 16 ms - tick through its acks), it does not glide, and a scroll still rewrites + tick through its acks), it glides at whole rows (anim 12), and a scroll still rewrites most rows (vaxis diffs cells; terminal scroll regions would move them for a few bytes). Position: scroll regions, if the tty's bytes matter. diff --git a/src/glide.zig b/src/glide.zig new file mode 100644 index 00000000..1d128dd0 --- /dev/null +++ b/src/glide.zig @@ -0,0 +1,415 @@ +//! The view's glide (G6, anim 3, 9, 12): the text's picture following +//! its core's rows, one system on every shell. The GUI draws it at the +//! pixel; the tty at whole rows (`shifted`). + +const std = @import("std"); +const pardes = @import("pardes.zig"); +const config = @import("config.zig"); + +/// G6 (docs/render-pipeline.md §9.1): whatever scrolls a text (a wheel's +/// lines, Ctrl-d, a page, G, n, a Look) scrolls the core at once, so every +/// key and click acts on where the text is, and the picture glides there +/// on the Motion flavour's spring (critically damped: text never passes its +/// mark), every distance on the same law. How far the rows moved is +/// measured on the next frame against the last, a line wrapped over several +/// rows or a terminal's output included, and the rows that left are kept to +/// draw in the gap. A move past what the two frames share (a page and more, +/// G) has no rows between them to show: the picture comes from the last +/// frame's body as if it lay just past the new one, one body away, so a +/// jump of any length reads as one body's slide. +/// +/// The picture's motion is one system with its own state, integrated in +/// one place every frame (`advance`), and every scroll, whatever made it, +/// is an input into it (`kick`): it moves the target by the rows the core +/// moved and leaves the motion as it is. What the system was doing decides +/// how it is absorbed: inputs coming as a stream (each like the last, at a +/// steady spacing: a held key, a spun wheel) feed it, and it moves at the +/// stream's own rate, a lag of an input or so behind, never easing toward +/// each target (that was a bounce a line); an input into a resting view, +/// or against the way it moves, starts the spring from the speed it has +/// (an ease, a turn through zero); a jump mid-glide adds its rows with the +/// speed kept. The spring's settle only comes once the inputs stop. +pub const Glide = struct { + /// The picture's lag behind the core's rows and its motion (rows). + follow: pardes.animation.Follow = .{}, + now_ns: u64 = 0, + pane: usize = 0, + rect: pardes.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }, + body_y: u16 = 0, + body_h: u16 = 0, + /// A scroll made and not yet measured: its direction, and the body's + /// rows before it. + pending: bool = false, + dir: i8 = 0, + before: []pardes.Cell = &.{}, + /// The rows past the body's top (`above`) and bottom (`below`), nearest + /// first, `bw` cells each: what the gap shows while the picture lags. + above: []pardes.Cell = &.{}, + below: []pardes.Cell = &.{}, + nabove: u16 = 0, + nbelow: u16 = 0, + /// The core's lines a scroll moved, not yet measured; and what the + /// glide in flight has moved, in lines and in the picture's rows. A + /// wrapped line is several rows, and the thumb counts lines. + pending_lines: f32 = 0, + lines_moved: f32 = 0, + rows_moved: f32 = 0, + /// The caret's row as the last frame drew it, and whether the move + /// measured carried it with its line (a wheel's) or left it on its row + /// (a page, a held key's): the tty draws a carried caret with the rows. + caret_row: ?u16 = null, + caret_rides: bool = false, + /// The Motion flavour the last loop step read. + motion: pardes.animation.Motion = .{}, + /// Each pane's view as the last loop step saw it (stepGlide): its + /// serial, first line and file, so a view that moved since is found + /// whatever moved it. + seen: [pardes.MAX_PANES]struct { serial: u32 = 0, line: i64 = 0, file: u64 = 0, revision: u32 = 0 } = @splat(.{}), + + /// The rows kept past each edge, in bodies, so a jump made while one + /// glides carries on from where it is: as far as the picture may lag. + pub const reach = pardes.animation.Follow.reach; + + pub fn moving(glide: *const Glide) bool { + return glide.follow.moving() or glide.pending; + } + + pub fn stop(glide: *Glide) void { + glide.follow = .{ .at_ns = glide.follow.at_ns }; + glide.pending = false; + glide.nabove = 0; + glide.nbelow = 0; + glide.pending_lines = 0; + glide.lines_moved = 0; + glide.rows_moved = 0; + } + + /// The glide's lag in the core's lines: its rows, scaled by the lines + /// they carried. + pub fn lagLines(glide: *const Glide) f32 { + if (glide.rows_moved == 0) return glide.follow.offset; + return glide.follow.offset * glide.lines_moved / glide.rows_moved; + } + + pub fn deinit(glide: *Glide, gpa: std.mem.Allocator) void { + gpa.free(glide.before); + gpa.free(glide.above); + gpa.free(glide.below); + } + + pub fn bw(glide: *const Glide) u16 { + return glide.rect.w -| config.GUTTER; + } + + /// The rules at this body's size: a tenth of a pixel is 5e-3 rows. + pub fn pace(glide: *const Glide, motion: pardes.animation.Motion) pardes.animation.Follow.Pace { + return pardes.animation.Follow.pace(motion, @floatFromInt(glide.body_h), 5e-3); + } + + /// An input: the core's rows moved by `rows` (down positive). + pub fn kick(glide: *Glide, rows: f32, now_ns: u64, motion: pardes.animation.Motion) void { + glide.follow.kick(rows, now_ns, glide.pace(motion)); + } + + pub fn advance(glide: *Glide, now_ns: u64, motion: pardes.animation.Motion) void { + glide.follow.advance(now_ns, glide.pace(motion)); + } + + /// Finds how far the pane's body rows moved, `dir` rows at a time, by + /// the rows of `surface` against `before`; keeps the rows that left. + pub fn measure(glide: *Glide, gpa: std.mem.Allocator, surface: *const pardes.Surface) void { + glide.pending = false; + const w = glide.bw(); + const h = glide.body_h; + const x0 = glide.rect.x + config.GUTTER; + if (w == 0 or h == 0 or x0 + w > surface.cols or glide.body_y + h > surface.rows or glide.before.len < @as(usize, w) * h) return glide.stop(); + const now = struct { + fn row(s: *const pardes.Surface, x: u16, y: u16, n: u16) []const pardes.Cell { + return s.cells[@as(usize, y) * s.cols + x ..][0..n]; + } + }; + // The least shift under which the rows agree, but for a few: the + // cursor's line and its number's weight move with the scroll. The + // lines the core moved are tried first: unwrapped, they are the + // rows, and one pass over the body settles it (the search over + // every shift was 6 ms of the first frame of a page in Debug). + const agrees = struct { + fn at(gl: *const Glide, surf: *const pardes.Surface, x: u16, width: u16, height: u16, kk: u16) bool { + if (kk == 0 or kk + 3 > height) return false; + const allowed = @max(2, (height - kk) / 8); + var misses: usize = 0; + for (0..height - kk) |r| { + const rr: u16 = @intCast(r); + const old_row = gl.before[@as(usize, if (gl.dir > 0) rr + kk else rr) * width ..][0..width]; + const new_row = now.row(surf, x, gl.body_y + if (gl.dir > 0) rr else rr + kk, width); + if (!sameRow(old_row, new_row)) { + misses += 1; + if (misses > allowed) return false; + } + } + return true; + } + }; + const guess: u16 = @intFromFloat(@min(glide.pending_lines, @as(f32, @floatFromInt(h)))); + // A body's lines or more: every row moved off, none in common. + var shift: u16 = if (guess >= h) 0 else if (agrees.at(glide, surface, x0, w, h, guess)) guess else found: for (1..h) |k| { + if (agrees.at(glide, surface, x0, w, h, @intCast(k))) break :found @intCast(k); + } else 0; + // Rows that disagree under every shift though the core moved a few + // lines: their colours changed as they moved (a paint arriving as a + // spin stops). Unwrapped, the rows moved are the lines: glide those + // (it landed from wherever it was, a snap at a spin's end). + if (shift == 0 and guess > 0 and guess < h) shift = guess; + // None in common: a body's move from the last frame's body, if the + // lines moved are that many (rows that merely changed, a small + // scroll the rows cannot show, land at once). + if (shift == 0 and glide.pending_lines + 3 < @as(f32, @floatFromInt(h))) return glide.stop(); + const far = shift == 0; + if (far) shift = h; + glide.caret_rides = !far and if (glide.caret_row) |old| if (surface.cursor) |c| + @as(i32, c.y) == @as(i32, old) - @as(i32, shift) * glide.dir + else + false else false; + glide.rows_moved += @floatFromInt(shift); + glide.lines_moved += glide.pending_lines; + glide.pending_lines = 0; + // The rows that left: past the top going down, the bottom going up. + if (!glide.ensure(gpa)) return glide.stop(); + const keep = if (glide.dir > 0) &glide.above else &glide.below; + const count = if (glide.dir > 0) &glide.nabove else &glide.nbelow; + const kept = @min(count.*, h * reach - shift); + std.mem.copyBackwards(pardes.Cell, keep.*[@as(usize, shift) * w ..][0 .. @as(usize, kept) * w], keep.*[0 .. @as(usize, kept) * w]); + for (0..shift) |i| { + const src_row: usize = if (glide.dir > 0) shift - 1 - i else h - shift + i; + @memcpy(keep.*[i * w ..][0..w], glide.before[src_row * w ..][0..w]); + } + count.* = kept + shift; + // What came into view is no longer past the other edge. + const other = if (glide.dir > 0) &glide.below else &glide.above; + const other_n = if (glide.dir > 0) &glide.nbelow else &glide.nabove; + // ...and after a jump, the rows past it are another place's. + const dropped = if (far) other_n.* else @min(other_n.*, shift); + std.mem.copyForwards(pardes.Cell, other.*[0 .. @as(usize, other_n.* - dropped) * w], other.*[@as(usize, dropped) * w ..][0 .. @as(usize, other_n.* - dropped) * w]); + other_n.* -= dropped; + glide.kick(@as(f32, @floatFromInt(shift)) * @as(f32, @floatFromInt(glide.dir)), glide.now_ns, glide.motion); + } + + /// Finds the text whose view moved since the last loop step, however + /// it moved (the wheel, a key, a Look), and snapshots its body as the + /// last frame drew it (`core.surface`), so the frame about to be drawn + /// can measure the move (`measure`); moves the glide on to now. A + /// terminal's view glides only under the wheel (`wheeled`: its output + /// scrolls it at every line, and that is no glide); not one the shell + /// moves by the pixel (`direct`). + pub fn step(glide: *Glide, core: *pardes.Pardes, gpa: std.mem.Allocator, wheeled: ?usize, direct: ?usize) void { + glide.now_ns = core.now_ns; + glide.motion = pardes.animation.Motion.of(core.settings.motion); + if (glide.follow.moving()) { + glide.advance(core.now_ns, glide.motion); + core.needs_frame = true; + if (glide.follow.offset == 0) { + glide.nabove = 0; + glide.nbelow = 0; + glide.lines_moved = 0; + glide.rows_moved = 0; + } + } + // ponytail: one glide at a time, the focused pane's, else the one that + // moved most; a second pane scrolled in the same step lands. A glide a + // pane (and a scissor each) if two ever need to move together. + // The view that moved: the focused pane's, else the one that moved + // most; not one showing another file now. + const s = &core.surface; + var pick: ?usize = null; + var delta: i64 = 0; + for (core.panes, 0..) |slot, id| { + const pane = slot orelse { + glide.seen[id] = .{}; + continue; + }; + const line: i64 = if (pane.file) |f| @intCast(f.scroll) else if (pane.isTerminal()) pardes.panes.terminal.gridOffset(pane) else 0; + const file: u64 = if (pane.file) |f| std.hash.Wyhash.hash(0, f.path) else 0; + const revision: u32 = if (pane.file) |f| f.revision else 0; + const was = glide.seen[id]; + glide.seen[id] = .{ .serial = pane.serial, .line = line, .file = file, .revision = revision }; + if (was.serial != pane.serial or was.file != file or was.line == line or pane.collapsed or pane.hasPdf()) continue; + // Generated text rewritten as its view moved (a query pane's live + // rows, a +Search refilled, Callstack): the rows are another + // text's, not this one's moved; it lands. + if (pane.file) |f| if (f.output != null and revision != was.revision) continue; + if (pane.file == null and wheeled != id) continue; + if (direct == id) continue; + const moved = line - was.line; + if (pick) |best| if (best == core.active or (id != core.active and @abs(moved) <= @abs(delta))) continue; + pick = id; + delta = moved; + } + const id = pick orelse return; + const pane = core.panes[id].?; + const r = core.rects[id]; + if (r.h <= pane.tag_rows or r.w <= config.GUTTER) return; + const body_y = core.bodyTop(pane, r); + const body_h = r.h -| pane.tag_rows; + const w = r.w - config.GUTTER; + const x0 = r.x + config.GUTTER; + // The last frame drew this body where it is now: a pane that moved or + // was resized in the same step has no picture to glide from. + const drawn = for (s.regionList()) |region| { + if (region.kind == .body and region.owner == id and region.serial == pane.serial) break std.meta.eql(region.rect, pardes.Rect{ .x = x0, .y = body_y, .w = w, .h = body_h }); + } else false; + // A new pane or place: what was kept belongs to another picture. + if (glide.pane != id or !std.meta.eql(glide.rect, r) or glide.body_y != body_y or glide.body_h != body_h or glide.pending) glide.stop(); + glide.pane = id; + glide.rect = r; + glide.body_y = body_y; + glide.body_h = body_h; + if (glide.motion.instant or !drawn or x0 + w > s.cols or body_y + body_h > s.rows or s.cells.len == 0) return glide.stop(); + // The body as the last frame drew it, which the move is measured from. + const n = @as(usize, w) * body_h; + if (glide.before.len < n) glide.before = gpa.realloc(glide.before, n) catch &.{}; + if (glide.before.len < n) return glide.stop(); + for (0..body_h) |row| @memcpy(glide.before[row * w ..][0..w], s.cells[(@as(usize, body_y) + row) * s.cols + x0 ..][0..w]); + glide.pending = true; + glide.caret_row = if (s.cursor) |c| c.y else null; + glide.dir = @intCast(std.math.sign(delta)); + glide.pending_lines += @floatFromInt(@abs(delta)); + core.needs_frame = true; + } + + pub fn ensure(glide: *Glide, gpa: std.mem.Allocator) bool { + const n = @as(usize, glide.bw()) * glide.body_h * reach; + inline for (.{ &glide.above, &glide.below }) |buffer| if (buffer.len < n) { + const grown = gpa.realloc(buffer.*, n) catch return false; + buffer.* = grown; + }; + return true; + } +}; + +/// The tty's picture of the glide (anim 12): the body's rows moved by the +/// offset rounded to whole rows (the position rounded, never the step, so +/// a slowing glide's steps come further apart), the rows that left in the +/// gap it opens, and a caret whose line rode the scroll carried with it. +/// `surface` itself while nothing is shifted. +pub fn shifted(glide: *const Glide, arena: std.mem.Allocator, surface: *pardes.Surface) !*pardes.Surface { + for (surface.panelTracks()) |track| + if (track.active() and track.pane == glide.pane) return surface; + const k: i32 = @intFromFloat(@round(glide.follow.offset)); + const w = glide.bw(); + const h = glide.body_h; + const x0 = glide.rect.x + config.GUTTER; + const y0 = glide.body_y; + if (k == 0 or w == 0 or h == 0 or x0 + w > surface.cols or y0 + h > surface.rows) return surface; + const out = try arena.create(pardes.Surface); + out.* = surface.*; + out.cells = try arena.dupe(pardes.Cell, surface.cells); + const cols: usize = surface.cols; + for (0..h) |r| { + const from = @as(i32, @intCast(r)) + k; + const to = out.cells[(y0 + r) * cols + x0 ..][0..w]; + const kept: ?[]const pardes.Cell = if (from >= 0 and from < h) + surface.cells[(y0 + @as(usize, @intCast(from))) * cols + x0 ..][0..w] + else if (from < 0 and -from - 1 < glide.nabove) + glide.above[@as(usize, @intCast(-from - 1)) * w ..][0..w] + else if (from >= h and from - h < glide.nbelow) + glide.below[@as(usize, @intCast(from - h)) * w ..][0..w] + else + null; + if (kept) |cells| @memcpy(to, cells) else @memset(to, .{}); + } + if (out.cursor) |*c| if (glide.caret_rides and c.x >= x0 and c.x < x0 + w and c.y >= y0 and c.y < y0 + h) { + const y = @as(i32, c.y) - k; + if (y >= y0 and y < y0 + h) c.y = @intCast(y) else out.cursor = null; + }; + return out; +} + +pub fn sameRow(a: []const pardes.Cell, b: []const pardes.Cell) bool { + for (a, b) |x, y| { + if (x.default != y.default) return false; + if (x.default) continue; + if (!std.mem.eql(u8, x.grapheme(), y.grapheme()) or !std.meta.eql(x.style, y.style)) return false; + } + return true; +} + + +test "the tty draws a glide at whole rows: once a flick or a spin slows, its steps a tick never grow and its one-row steps come further apart, to where the core is" { + const gpa = std.testing.allocator; + const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 30, .tty_only = true }); + defer core.deinit(); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(gpa); + for (0..3000) |i| try text.print(gpa, "{d:0>5} line\n", .{i}); + _ = try core.setTestFile(text.items); + core.settings.motion = .smooth; + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + var glide: Glide = .{}; + defer glide.deinit(gpa); + var now: u64 = std.time.ns_per_s; + // One tick of the tty: its loop step, the frame, the picture. + const tick = struct { + fn f(c: *pardes.Pardes, g: *Glide, a: *std.heap.ArenaAllocator, t: u64) !i32 { + c.advance(t); + g.step(c, std.testing.allocator, null, null); + _ = a.reset(.retain_capacity); + const s = try c.render(a.allocator()); + if (g.pending) g.measure(std.testing.allocator, s); + if (g.moving()) g.advance(t, g.motion); + _ = try shifted(g, a.allocator(), s); + return @intFromFloat(@round(g.follow.offset)); + } + }.f; + _ = try tick(core, &glide, &arena, now); + for ([_]usize{ 4, 24 }) |notches| { + for (0..notches) |i| { + core.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = 20, .row = 10 } }); + if (i % 2 == 1) { + now += pardes.animation.frame_ns; + _ = try tick(core, &glide, &arena, now); + } + } + var drawn = try tick(core, &glide, &arena, now + pardes.animation.frame_ns); + now += pardes.animation.frame_ns; + var last_step: i32 = std.math.maxInt(i32); + var last_gap: usize = 0; + var since: usize = 0; + var ticks: usize = 0; + while (glide.moving()) : (ticks += 1) { + try std.testing.expect(ticks < 200); + now += pardes.animation.frame_ns; + const k = try tick(core, &glide, &arena, now); + const step = k - drawn; + drawn = k; + since += 1; + if (step == 0) continue; + // Toward the core, never past it, each step no longer than the last. + try std.testing.expect(step > 0 and k <= 0); + try std.testing.expect(step <= last_step); + if (step == 1 and last_step == 1) try std.testing.expect(since >= last_gap); + if (step == 1) last_gap = since; + last_step = step; + since = 0; + } + try std.testing.expectEqual(@as(i32, 0), drawn); + } + // j held on the bottom row: the text glides a row a key under a caret + // that stays on its cell (it does not ride: its row is kept). + const keys = struct { + fn j(c: *pardes.Pardes) void { + c.update(.{ .key = .{ .cp = 'j', .text = "j" } }); + } + }; + for (0..40) |_| keys.j(core); + now += std.time.ns_per_s; + _ = try tick(core, &glide, &arena, now); + const row = (core.surface.cursor orelse return error.NoCursor).y; + for (0..20) |i| { + if (i % 2 == 0) keys.j(core); + now += pardes.animation.frame_ns; + _ = try tick(core, &glide, &arena, now); + const out = try shifted(&glide, arena.allocator(), &core.surface); + try std.testing.expectEqual(row, (out.cursor orelse return error.NoCursor).y); + } +} diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 94eabb6c..13fd7905 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -5042,222 +5042,15 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a try std.testing.expectEqual(@as(i32, -1), g.scroll_notch); } -/// G6 (docs/render-pipeline.md §9.1): whatever scrolls a text (a wheel's -/// lines, Ctrl-d, a page, G, n, a Look) scrolls the core at once, so every -/// key and click acts on where the text is, and the picture glides there -/// on the Motion flavour's spring (critically damped: text never passes its -/// mark), every distance on the same law. How far the rows moved is -/// measured on the next frame against the last, a line wrapped over several -/// rows or a terminal's output included, and the rows that left are kept to -/// draw in the gap. A move past what the two frames share (a page and more, -/// G) has no rows between them to show: the picture comes from the last -/// frame's body as if it lay just past the new one, one body away, so a -/// jump of any length reads as one body's slide. -/// -/// The picture's motion is one system with its own state, integrated in -/// one place every frame (`advance`), and every scroll, whatever made it, -/// is an input into it (`kick`): it moves the target by the rows the core -/// moved and leaves the motion as it is. What the system was doing decides -/// how it is absorbed: inputs coming as a stream (each like the last, at a -/// steady spacing: a held key, a spun wheel) feed it, and it moves at the -/// stream's own rate, a lag of an input or so behind, never easing toward -/// each target (that was a bounce a line); an input into a resting view, -/// or against the way it moves, starts the spring from the speed it has -/// (an ease, a turn through zero); a jump mid-glide adds its rows with the -/// speed kept. The spring's settle only comes once the inputs stop. -const Glide = struct { - /// The picture's lag behind the core's rows and its motion (rows). - follow: pardes.animation.Follow = .{}, - now_ns: u64 = 0, - pane: usize = 0, - rect: pardes.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }, - body_y: u16 = 0, - body_h: u16 = 0, - /// A scroll made and not yet measured: its direction, and the body's - /// rows before it. - pending: bool = false, - dir: i8 = 0, - before: []pardes.Cell = &.{}, - /// The rows past the body's top (`above`) and bottom (`below`), nearest - /// first, `bw` cells each: what the gap shows while the picture lags. - above: []pardes.Cell = &.{}, - below: []pardes.Cell = &.{}, - nabove: u16 = 0, - nbelow: u16 = 0, - /// The core's lines a scroll moved, not yet measured; and what the - /// glide in flight has moved, in lines and in the picture's rows. A - /// wrapped line is several rows, and the thumb counts lines. - pending_lines: f32 = 0, - lines_moved: f32 = 0, - rows_moved: f32 = 0, - /// The Motion flavour the last loop step read. - motion: pardes.animation.Motion = .{}, - /// Each pane's view as the last loop step saw it (stepGlide): its - /// serial, first line and file, so a view that moved since is found - /// whatever moved it. - seen: [pardes.MAX_PANES]struct { serial: u32 = 0, line: i64 = 0, file: u64 = 0, revision: u32 = 0 } = @splat(.{}), - - /// The rows kept past each edge, in bodies, so a jump made while one - /// glides carries on from where it is: as far as the picture may lag. - const reach = pardes.animation.Follow.reach; - - fn moving(glide: *const Glide) bool { - return glide.follow.moving() or glide.pending; - } - - fn stop(glide: *Glide) void { - glide.follow = .{ .at_ns = glide.follow.at_ns }; - glide.pending = false; - glide.nabove = 0; - glide.nbelow = 0; - glide.pending_lines = 0; - glide.lines_moved = 0; - glide.rows_moved = 0; - } - - /// The glide's lag in the core's lines: its rows, scaled by the lines - /// they carried. - fn lagLines(glide: *const Glide) f32 { - if (glide.rows_moved == 0) return glide.follow.offset; - return glide.follow.offset * glide.lines_moved / glide.rows_moved; - } - - fn deinit(glide: *Glide, gpa: std.mem.Allocator) void { - gpa.free(glide.before); - gpa.free(glide.above); - gpa.free(glide.below); - } - - fn bw(glide: *const Glide) u16 { - return glide.rect.w -| config.GUTTER; - } - - /// The rules at this body's size: a tenth of a pixel is 5e-3 rows. - fn pace(glide: *const Glide, motion: pardes.animation.Motion) pardes.animation.Follow.Pace { - return pardes.animation.Follow.pace(motion, @floatFromInt(glide.body_h), 5e-3); - } - - /// An input: the core's rows moved by `rows` (down positive). - fn kick(glide: *Glide, rows: f32, now_ns: u64, motion: pardes.animation.Motion) void { - glide.follow.kick(rows, now_ns, glide.pace(motion)); - } - - fn advance(glide: *Glide, now_ns: u64, motion: pardes.animation.Motion) void { - glide.follow.advance(now_ns, glide.pace(motion)); - } - - /// Finds how far the pane's body rows moved, `dir` rows at a time, by - /// the rows of `surface` against `before`; keeps the rows that left. - fn measure(glide: *Glide, gpa: std.mem.Allocator, surface: *const pardes.Surface) void { - glide.pending = false; - const w = glide.bw(); - const h = glide.body_h; - const x0 = glide.rect.x + config.GUTTER; - if (w == 0 or h == 0 or x0 + w > surface.cols or glide.body_y + h > surface.rows or glide.before.len < @as(usize, w) * h) return glide.stop(); - const now = struct { - fn row(s: *const pardes.Surface, x: u16, y: u16, n: u16) []const pardes.Cell { - return s.cells[@as(usize, y) * s.cols + x ..][0..n]; - } - }; - // The least shift under which the rows agree, but for a few: the - // cursor's line and its number's weight move with the scroll. The - // lines the core moved are tried first: unwrapped, they are the - // rows, and one pass over the body settles it (the search over - // every shift was 6 ms of the first frame of a page in Debug). - const agrees = struct { - fn at(gl: *const Glide, surf: *const pardes.Surface, x: u16, width: u16, height: u16, kk: u16) bool { - if (kk == 0 or kk + 3 > height) return false; - const allowed = @max(2, (height - kk) / 8); - var misses: usize = 0; - for (0..height - kk) |r| { - const rr: u16 = @intCast(r); - const old_row = gl.before[@as(usize, if (gl.dir > 0) rr + kk else rr) * width ..][0..width]; - const new_row = now.row(surf, x, gl.body_y + if (gl.dir > 0) rr else rr + kk, width); - if (!sameRow(old_row, new_row)) { - misses += 1; - if (misses > allowed) return false; - } - } - return true; - } - }; - const guess: u16 = @intFromFloat(@min(glide.pending_lines, @as(f32, @floatFromInt(h)))); - // A body's lines or more: every row moved off, none in common. - var shift: u16 = if (guess >= h) 0 else if (agrees.at(glide, surface, x0, w, h, guess)) guess else found: for (1..h) |k| { - if (agrees.at(glide, surface, x0, w, h, @intCast(k))) break :found @intCast(k); - } else 0; - // None in common: a body's move from the last frame's body, if the - // lines moved are that many (rows that merely changed, a small - // scroll the rows cannot show, land at once). - if (shift == 0 and glide.pending_lines + 3 < @as(f32, @floatFromInt(h))) return glide.stop(); - const far = shift == 0; - if (far) shift = h; - glide.rows_moved += @floatFromInt(shift); - glide.lines_moved += glide.pending_lines; - glide.pending_lines = 0; - // The rows that left: past the top going down, the bottom going up. - if (!glide.ensure(gpa)) return glide.stop(); - const keep = if (glide.dir > 0) &glide.above else &glide.below; - const count = if (glide.dir > 0) &glide.nabove else &glide.nbelow; - const kept = @min(count.*, h * reach - shift); - std.mem.copyBackwards(pardes.Cell, keep.*[@as(usize, shift) * w ..][0 .. @as(usize, kept) * w], keep.*[0 .. @as(usize, kept) * w]); - for (0..shift) |i| { - const src_row: usize = if (glide.dir > 0) shift - 1 - i else h - shift + i; - @memcpy(keep.*[i * w ..][0..w], glide.before[src_row * w ..][0..w]); - } - count.* = kept + shift; - // What came into view is no longer past the other edge. - const other = if (glide.dir > 0) &glide.below else &glide.above; - const other_n = if (glide.dir > 0) &glide.nbelow else &glide.nabove; - // ...and after a jump, the rows past it are another place's. - const dropped = if (far) other_n.* else @min(other_n.*, shift); - std.mem.copyForwards(pardes.Cell, other.*[0 .. @as(usize, other_n.* - dropped) * w], other.*[@as(usize, dropped) * w ..][0 .. @as(usize, other_n.* - dropped) * w]); - other_n.* -= dropped; - glide.kick(@as(f32, @floatFromInt(shift)) * @as(f32, @floatFromInt(glide.dir)), glide.now_ns, glide.motion); - } - - fn ensure(glide: *Glide, gpa: std.mem.Allocator) bool { - const n = @as(usize, glide.bw()) * glide.body_h * reach; - inline for (.{ &glide.above, &glide.below }) |buffer| if (buffer.len < n) { - const grown = gpa.realloc(buffer.*, n) catch return false; - buffer.* = grown; - }; - return true; - } -}; +const Glide = pardes.glide.Glide; -fn sameRow(a: []const pardes.Cell, b: []const pardes.Cell) bool { - for (a, b) |x, y| { - if (x.default != y.default) return false; - if (x.default) continue; - if (!std.mem.eql(u8, x.grapheme(), y.grapheme()) or !std.meta.eql(x.style, y.style)) return false; - } - return true; -} - -/// Feeds a wheel's notches to the core, then finds the text whose view -/// moved since the last loop, however it moved (the wheel, a key, a Look), -/// and snapshots its body as the last frame drew it so the frame about to -/// be drawn can measure the move (Glide.measure); advances the glide and -/// asks for frames while it moves. +/// Feeds a wheel's notches to the core, then steps the glide (Glide.step) +/// and asks for frames while it moves. fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { const glide = &g.glide; // The glide runs on the core's continuous path: frames every loop, and // a virtual clock carried on. defer core.shell_continuous = glide.moving() or g.sel_glow.fading or g.hover_glow.fading; - glide.now_ns = core.now_ns; - glide.motion = pardes.animation.Motion.of(core.settings.motion); - if (glide.follow.offset != 0 or glide.follow.speed != 0) { - glide.advance(core.now_ns, glide.motion); - core.needs_frame = true; - if (glide.follow.offset == 0) { - glide.follow.offset = 0; - glide.nabove = 0; - glide.nbelow = 0; - glide.lines_moved = 0; - glide.rows_moved = 0; - } - } const notch = g.scroll_notch; g.scroll_notch = 0; var wheeled: ?usize = null; @@ -5284,67 +5077,9 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { } if (wheeled != null) core.needs_frame = true; } - // ponytail: one glide at a time, the focused pane's, else the one that - // moved most; a second pane scrolled in the same step lands. A glide a - // pane (and a scissor each) if two ever need to move together. - // The view that moved: the focused pane's, else the one that moved - // most. A text's whatever moved it; a terminal's only under the wheel - // (its output scrolls it at every line, and that is no glide); not one - // a touchpad is moving by the pixel, nor one showing another file now. - const s = &core.surface; - var pick: ?usize = null; - var delta: i64 = 0; - for (core.panes, 0..) |slot, id| { - const pane = slot orelse { - glide.seen[id] = .{}; - continue; - }; - const line: i64 = if (pane.file) |f| @intCast(f.scroll) else if (pane.isTerminal()) pardes.panes.terminal.gridOffset(pane) else 0; - const file: u64 = if (pane.file) |f| std.hash.Wyhash.hash(0, f.path) else 0; - const revision: u32 = if (pane.file) |f| f.revision else 0; - const was = glide.seen[id]; - glide.seen[id] = .{ .serial = pane.serial, .line = line, .file = file, .revision = revision }; - if (was.serial != pane.serial or was.file != file or was.line == line or pane.collapsed or pane.hasPdf()) continue; - // Generated text rewritten as its view moved (a query pane's live - // rows, a +Search refilled, Callstack): the rows are another - // text's, not this one's moved; it lands. - if (pane.file) |f| if (f.output != null and revision != was.revision) continue; - if (pane.file == null and wheeled != id) continue; - if (g.scroll_pane == id and (g.scroll_lag != 0 or g.scroll_delta != 0)) continue; - const moved = line - was.line; - if (pick) |best| if (best == core.active or (id != core.active and @abs(moved) <= @abs(delta))) continue; - pick = id; - delta = moved; - } - const id = pick orelse return; - const pane = core.panes[id].?; - const r = core.rects[id]; - if (r.h <= pane.tag_rows or r.w <= config.GUTTER) return; - const body_y = core.bodyTop(pane, r); - const body_h = r.h -| pane.tag_rows; - const w = r.w - config.GUTTER; - const x0 = r.x + config.GUTTER; - // The last frame drew this body where it is now: a pane that moved or - // was resized in the same step has no picture to glide from. - const drawn = for (s.regionList()) |region| { - if (region.kind == .body and region.owner == id and region.serial == pane.serial) break std.meta.eql(region.rect, pardes.Rect{ .x = x0, .y = body_y, .w = w, .h = body_h }); - } else false; - // A new pane or place: what was kept belongs to another picture. - if (glide.pane != id or !std.meta.eql(glide.rect, r) or glide.body_y != body_y or glide.body_h != body_h or glide.pending) glide.stop(); - glide.pane = id; - glide.rect = r; - glide.body_y = body_y; - glide.body_h = body_h; - if (glide.motion.instant or !drawn or x0 + w > s.cols or body_y + body_h > s.rows or s.cells.len == 0) return glide.stop(); - // The body as the last frame drew it, which the move is measured from. - const n = @as(usize, w) * body_h; - if (glide.before.len < n) glide.before = gpa.realloc(glide.before, n) catch &.{}; - if (glide.before.len < n) return glide.stop(); - for (0..body_h) |row| @memcpy(glide.before[row * w ..][0..w], s.cells[(@as(usize, body_y) + row) * s.cols + x0 ..][0..w]); - glide.pending = true; - glide.dir = @intCast(std.math.sign(delta)); - glide.pending_lines += @floatFromInt(@abs(delta)); - core.needs_frame = true; + // Not a view a touchpad is moving by the pixel. + const direct: ?usize = if (g.scroll_lag != 0 or g.scroll_delta != 0) g.scroll_pane else null; + glide.step(core, gpa, wheeled, direct); } /// The glide's picture: the pane's body rows moved by the offset, and in @@ -5456,7 +5191,7 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe // nearest first. try std.testing.expectApproxEqAbs(@as(f32, -2), g.glide.follow.offset, 1e-4); try std.testing.expectEqual(@as(u16, 2), g.glide.nabove); - try std.testing.expect(sameRow(g.glide.above[0 .. r.w - config.GUTTER], row_before)); + try std.testing.expect(pardes.glide.sameRow(g.glide.above[0 .. r.w - config.GUTTER], row_before)); // Frame by frame it comes back, never past, and settles. var frames: usize = 0; while (g.glide.moving()) : (frames += 1) { diff --git a/src/pardes.zig b/src/pardes.zig index 829a7bfd..a1d1eef8 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1,6 +1,7 @@ const std = @import("std"); pub const layout = @import("layout.zig"); pub const animation = @import("animation.zig"); +pub const glide = @import("glide.zig"); pub const FrameStats = @import("FrameStats.zig"); pub const Presentation = @import("Presentation.zig"); const uucode = @import("uucode"); @@ -483,6 +484,7 @@ test { _ = @import("Pipe.zig"); _ = @import("colors.zig"); _ = @import("surface.zig"); + _ = @import("glide.zig"); _ = @import("body_layer.zig"); _ = @import("draw.zig"); _ = @import("dump.zig"); // its tests ran nowhere before diff --git a/src/tty/tty.zig b/src/tty/tty.zig index b7bb2d54..c97ba4bf 100644 --- a/src/tty/tty.zig +++ b/src/tty/tty.zig @@ -1339,6 +1339,7 @@ fn localSession( }; pardes.lsp.setStatusSink(&sh, lspStatusSink); host_io.setExitWake(loop, wakeForExit); + defer sh.glide.deinit(gpa); defer { host_io.setExitWake(null, null); pardes.lsp.setStatusSink(null, null); @@ -1516,6 +1517,8 @@ const Shell = struct { tracks: []const pardes.animation.Track = &.{}, /// T2: the cursor's jump trail (JumpTrail). trail: JumpTrail = .{}, + /// The view's glide, the GUI's motion drawn at whole rows (anim 12). + glide: pardes.glide.Glide = .{}, /// T7: when each pane's view last moved (ThumbFlash). flash: ThumbFlash = .{}, /// PARDES_TEST_CLOCK's virtual time (host_io.testClock), and where the @@ -1540,6 +1543,7 @@ const Shell = struct { .now = clockNow, .present = present, .post_present = postPresent, + .poll_frame = stepGlide, }; const vtable: host_io.Host.VTable = .{ @@ -1611,7 +1615,9 @@ const Shell = struct { fn waitOnce(s: *Shell, wait: u32) void { var batch: usize = 0; if (wait != 0) { - s.wake_to = s.core.nextWake() orelse 0; + // A virtual clock moves a frame a wake while anything moves + // continuously (the glide), as the real one would. + s.wake_to = s.core.nextWake() orelse if (s.core.continuous()) s.core.now_ns + pardes.animation.frame_ns else 0; requestWake(s.io, wait); } pardes.turn.rest(); @@ -1789,8 +1795,17 @@ const Shell = struct { s.loop.postEvent(.files_changed) catch {}; } + /// ponytail: a terminal's scrollback under the wheel lands here (the + /// wheel reaches the core as a mouse event, not counted as the GUI's + /// notches are); `wheeled` from the mouse event if it should glide. + fn stepGlide(ctx: ?*anyopaque) void { + const s = of(ctx); + s.glide.step(s.core, s.gpa, null, null); + } + fn pollFrame(ctx: ?*anyopaque) void { const s = of(ctx); + stepGlide(ctx); s.core.native_image_patches = kitty_shm.load(.acquire); if (s.fs) |f| if (f.tick().pending) { _ = s.loop.tryPostEvent(.fs_ready) catch {}; @@ -1831,8 +1846,12 @@ const Shell = struct { const win = vx.window(); const truecolor = vx.caps.rgb or colortermTruecolor(); // Each of the shell's own motions below asks for frames while it runs. - s.core.shell_continuous = false; - const shadowed = chipShadows(s.frame.allocator(), surface, s.core, truecolor) catch surface; + if (s.glide.pending) s.glide.measure(s.gpa, canonical); + if (s.glide.moving()) s.glide.advance(s.core.now_ns, s.glide.motion); + s.core.shell_continuous = s.glide.moving(); + s.core.frames.scroll = @round(s.glide.follow.offset); + const glided = pardes.glide.shifted(&s.glide, s.frame.allocator(), surface) catch surface; + const shadowed = chipShadows(s.frame.allocator(), glided, s.core, truecolor) catch glided; const flashed = s.flash.apply(s.frame.allocator(), shadowed, s.core, truecolor) catch shadowed; const trailed = s.trail.apply(s.frame.allocator(), flashed, s.core, truecolor) catch flashed; paintCells(win, trailed.cells, trailed.cols, trailed.rows); @@ -1922,7 +1941,7 @@ const Shell = struct { vx.freeImage(s.tty.writer(), removed.value.id); if (stale_len < stale.len) break; } - if (surface.cursor) |cur| paintCursor(win, cur.x, cur.y, cur.bar); + if (glided.cursor) |cur| paintCursor(win, cur.x, cur.y, cur.bar); const tz_render = tracy.zone(@src(), "vx.render"); const before = s.tty.tty_writer.pos + s.tty.writer().end; vx.render(s.tty.writer()) catch {}; -- cgit v1.3