From 4bd81bbb42088e9d6f1441094e8feea23064a6c6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 22 Nov 2026 22:54:58 -0300 Subject: lanes: a change's lanes ride their lines' glide in a window: the window drew `Changes`' lanes (Surface.lanes: a strip a level in the gutter's lane cells, decor, not cells) at the rows their lines have in the core, with no lag, no cut to the body and nothing for the rows that left (dev/gui/gui.zig buildDecor's lane loop: the glide's rows, emitScrollRows, and the rail's thumb, paneDecor's lagLines, had the picture's lag; the lanes, added later, never did), so at every scroll (a wheel's notch, Ctrl-d, a page, a touchpad's fraction) the strips leapt to where their lines would be and the text glided in under them, on every frame of the glide (the user's "the animation for the things in the gutter makes them keep jumping", 2026-11-22; in a test window on core/echo.zig with `Changes pardes-installed-20261122..main`, a wheel's three notches: the glide's first frame has the text unmoved and every strip three rows up; a terminal is untouched, its lanes are cells); now `laneDecor` draws a scrolling body's lanes as emitScrollRows draws its rows: the lag less (a glide's offset, else scroll_lag; the lift of held context rows), cut on the CPU to the body under its held rows (the shifted rows' scissor), and the rows that left keep theirs in the gap: the glide remembers each frame's lanes with its cells (`last_lanes`) and moves a kept row's lanes with it as it moves its cells (`above_lanes`, `below_lanes`: a `RowLanes` a row, at most `Lane.levels`, now Lane's own, which jj.levels names), and a touchpad's edge row keeps its own (`scroll_edge_lanes`); remembered by the glide rather than made part of what a row is (a lane in Cell): the frontend's alone, nothing in the core, and nothing added to every cell of every frame for a layer most bodies never show; the scrolling body and the rows that left it are one function each for the rows and the lanes (`scrollBody`, `ScrollBody.leftRow`, `glideLeft`, out of emitScrollRows); at rest a strip is the same rectangle as before; nothing in the core's step changes; looked at mid-glide in the same window: an added line's green ground, a ghost row's red ground, a changed line's word grounds, a description row, Churn's cell after the line number and the `~` past the last line are cells and ride with their rows; Churn's strip on the rail maps the whole file and stands still under the moving thumb, as it should; a frame's cost with three lanes on each of 70 body rows (219 lanes; a scratch bench, glideFrame and buildDecor a frame, `perf stat -e instructions:u` at 2,000 and 6,000 frames, ReleaseFast): at rest 67,744 instructions against the base's 65,644 (+2,100: the lanes copied with the frame, 1,752 bytes, and the strips' loop), a glide's frame 81,472 against 65,832 (+15,640: every strip cut and moved, and the gap's), a frame with a scroll input 1,125,708 against 1,103,120 (+22,588, the measure's 1.1 million the most of it); the text timedemo's frame is 9.38 million (tree4): +0.02% at rest, +0.17% gliding; memory: the glide's kept rows' lanes, 26 bytes a row, 2 bodies' rows a side (3,640 bytes a side at 70 rows), allocated with the kept cells, and the last frame's lanes (8 bytes each) in a list that grows only past the most a frame has had: nothing allocated a frame; no frame later: the strips are computed in the frame they are drawn in, from what the glide already holds; the previous change's test passes; the gate against tree4 (gpu/lane-glide-g, load 5-10): 77/77 frames identical, gui unit-test 1710/1714 (the base's 1709/1713 and this test; its one failure the base's), perfab corpus2x +0.026% (noise 0.092%), pictures identical in all 10 runs, the 121 counts within 0.1% (largest image-frame on small +0.0057%); tui core-test 917/1074 (157 skipped), shell-test 1116/1119 (3 skipped), the base's Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/glide.zig | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) (limited to 'dev/glide.zig') diff --git a/dev/glide.zig b/dev/glide.zig index 711acb22..62e44bb7 100644 --- a/dev/glide.zig +++ b/dev/glide.zig @@ -39,9 +39,13 @@ pub const Glide = struct { 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. + /// first, `bw` cells each, and a change's lanes on each (Surface.lanes, + /// a pixel shell's strips in the gutter, not cells): what the gap shows + /// while the picture lags. above: []pardes.Cell = &.{}, below: []pardes.Cell = &.{}, + above_lanes: []RowLanes = &.{}, + below_lanes: []RowLanes = &.{}, nabove: u16 = 0, nbelow: u16 = 0, /// The core's lines a scroll moved, not yet measured; and what the @@ -64,8 +68,10 @@ pub const Glide = struct { /// not move, so a move is measured, and the rows that left are kept, /// below them. held: [pardes.MAX_PANES]u16 = @splat(0), - /// The last frame's cells, which a move is measured against. + /// The last frame's cells, which a move is measured against, and its + /// lanes, which the rows that left take with them. last: []pardes.Cell = &.{}, + last_lanes: std.ArrayList(pardes.Lane) = .empty, last_cols: u16 = 0, last_rows: u16 = 0, @@ -97,7 +103,10 @@ pub const Glide = struct { gpa.free(glide.before); gpa.free(glide.above); gpa.free(glide.below); + gpa.free(glide.above_lanes); + gpa.free(glide.below_lanes); gpa.free(glide.last); + glide.last_lanes.deinit(gpa); } pub fn bw(glide: *const Glide) u16 { @@ -188,6 +197,8 @@ pub const Glide = struct { glide.last_cols = surface.cols; glide.last_rows = surface.rows; glide.caret_row = if (surface.cursor) |c| c.y else null; + glide.last_lanes.clearRetainingCapacity(); + glide.last_lanes.appendSlice(gpa, surface.lanes.items) catch {}; } /// Finds how far the pane's body rows moved, `dir` rows at a time, by @@ -261,28 +272,56 @@ pub const Glide = struct { const src_row: usize = top + if (glide.dir > 0) shift - 1 - i else h - shift + i; @memcpy(keep.*[i * w ..][0..w], glide.before[src_row * w ..][0..w]); } + // Their lanes go with them, from the frame they left. + const keep_lanes = if (glide.dir > 0) glide.above_lanes else glide.below_lanes; + std.mem.copyBackwards(RowLanes, keep_lanes[shift..][0..kept], keep_lanes[0..kept]); + @memset(keep_lanes[0..shift], .{}); + for (glide.last_lanes.items) |lane| { + if (lane.x < x0 or lane.x >= x0 + w or lane.y < glide.body_y + top or lane.y >= glide.body_y + glide.body_h) continue; + const row = lane.y - glide.body_y - top; + if (glide.dir > 0 and row < shift) keep_lanes[shift - 1 - row].add(lane); + if (glide.dir < 0 and row >= h - shift) keep_lanes[row - (h - shift)].add(lane); + } 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_lanes = if (glide.dir > 0) glide.below_lanes else glide.above_lanes; 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]); + std.mem.copyForwards(RowLanes, other_lanes[0 .. other_n.* - dropped], other_lanes[dropped..][0 .. other_n.* - dropped]); other_n.* -= dropped; // An input: the core's rows moved by as many (down positive). glide.follow.kick(@as(f32, @floatFromInt(shift)) * @as(f32, @floatFromInt(glide.dir)), glide.now_ns, glide.pace()); } 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; + const rows = @as(usize, glide.body_h) * reach; + inline for (.{ .{ &glide.above, rows * glide.bw() }, .{ &glide.below, rows * glide.bw() }, .{ &glide.above_lanes, rows }, .{ &glide.below_lanes, rows } }) |kept| if (kept[0].len < kept[1]) { + kept[0].* = gpa.realloc(kept[0].*, kept[1]) catch return false; }; return true; } }; +/// A kept row's lanes, as the frame it left drew them: a row has a level +/// each at most. +pub const RowLanes = struct { + n: u8 = 0, + lane: [pardes.Lane.levels]pardes.Lane = undefined, + + pub fn add(row: *RowLanes, lane: pardes.Lane) void { + if (row.n == row.lane.len) return; + row.lane[row.n] = lane; + row.n += 1; + } + + pub fn items(row: *const RowLanes) []const pardes.Lane { + return row.lane[0..row.n]; + } +}; + pub fn sameRow(a: []const pardes.Cell, b: []const pardes.Cell) bool { for (a, b) |x, y| { if (x.default != y.default) return false; -- cgit v1.3