diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-23 15:42:33 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 16:31:13 -0300 |
| commit | 6f9a8b907a504c28aef6c68b923508419b54f0ee (patch) | |
| tree | 4a9411cf4caffb6b7886f52dd67392a623915338 /core/jj.zig | |
| parent | fa3550eedec44e624384b478fc19a40d94fb7a82 (diff) | |
| download | pardes-6f9a8b907a504c28aef6c68b923508419b54f0ee.tar.gz pardes-6f9a8b907a504c28aef6c68b923508419b54f0ee.zip | |
changes layer: a file with no layer pays for it what tree6 paid, found by measure (instructions by symbol and by source line, Intel PT, on the ReleaseFast pardes-perf, tree6 against round 9's base): perfops against tree6 from 12 of 121 over 0.1% to 1 (the base's `body-appends` +0.44%, `open` +0.235%, `client-key-down` +0.13..0.16%, `client-delete-undo`, `client-edit-char`, `deep-sel` +0.10..0.14%, every frame +3.8k); (1) `File.fillBody`'s row walk compiled worse with the gutter number's layer lookups (`readOnlyRow`, `fileRow`) inlined beside it: PT by source line, tree6's lines matched to the base's by their text, the same bytes walked, the inlined `fitEnd` byte loop +98k an op with no line and its checks reshuffled (body-appends +86k an op): `fillBody(comptime layered)`, as tree6's `comptime ghosted` was, chosen by `mapRows` and `bodyText` (a length test); (2) the 9P path asked the file's text and its offsets through calls: `bodyOf`, `fileDot`, `setFileDot`, `showFileOffset` answer with no layer by a length test, inline (core/ninep/pane.zig); (3) `open` (+8.8k since tree6, step 1's): not the change-id rule's regexp (it stands after the file rules and is never reached for a file) but its PARSE: pardes-perf's open boots a core each time and each core reads the rules at its first plumb (`Plumb.Parser.take` +4.0k, `expand` +1.4k, `feed` +1.2k, `endSet`, `word`, `append`, `stringToEnum`: +8.6k): the rule is deleted from core/plumbing and Look's own unresolved path takes a change id (core/look.zig `lookUnresolved`: eight letters or more, k to z, in a pane neither a raw terminal's nor a kind's, the rule's `src is pardes`; `jj.diffChange`; one naming no change searched for as before), no rule and no parse anywhere; (4) a client's key (+2.0..2.4k): the digest of File.State's two new fields, two small hash updates a pane a digest (Wyhash's buffered update and its memcpy): one field, `layer: Layer` (`owner`, `lines`: what were `layer` and `read_only`), digested by hand (`Layer.digest`: nothing hashed with no layer shown, a length test), its line in replica.zig's `hand_walked` (the test joining a client over a pane showing the layer); LEFT FOR THE COORDINATOR'S RULING: `terminal on all` +0.141% (+147k an op over the 18 terminal cells, +7.8k a terminal frame, the same in-run by an in-process counter around each cell): PT by line in the terminal's render cell: core/ansi.zig `recolor`'s per-cell style loop (source unchanged) compiled worse inlined into `body_layer.renderBody` after round 8's deletions there (`w.ghost`'s skips, `Pane.wrapAt`'s `ghost` field): what it buys is those deletions; `@call(.never_inline, ansi.recolor)` made it worse (+0.227%, and `deep-sel` +0.285%), not kept; perfops (the gate's malloc setting, load 2-9): v4 against tree6 120 of 121 within 0.1%, largest under the budget `client-key-down` on medium +0.065%; core-test 952/1118 (166 skipped) Debug tui
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/jj.zig')
| -rw-r--r-- | core/jj.zig | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/core/jj.zig b/core/jj.zig index b99419b0..176ead49 100644 --- a/core/jj.zig +++ b/core/jj.zig @@ -204,7 +204,7 @@ pub fn looked(p: *Pardes, id: usize, dir: []const u8, text: []const u8, at: look /// What jj answered for a pane's `Changes`: replicated state, the /// session's (`Pardes.changes`, by the pane's serial: a client never runs /// jj; one that joins late has it in the dump), its revset with it. Shown, -/// its ghosts are lines of the pane's buffer, read-only (File.read_only, +/// its ghosts are lines of the pane's buffer, read-only (File.layer.lines, /// `showLayer`), so the layer is the pane's: every view of it shows it or /// none does. From two jj runs off the loop (`Ask`): the changes /// with their diffs of the file (`jj log -p --git`, the diffs read with @@ -264,7 +264,7 @@ pub fn churned(p: *Pardes, serial: u32) ?*Heat { /// Pane `serial`'s answers let go (the pane's end); a twin showing its /// layer, its lines out. pub fn forget(p: *Pardes, serial: u32) void { - for (p.panes) |slot| if (slot) |pane| if (pane.file) |*f| if (f.layer == serial and pane.serial != serial) { + for (p.panes) |slot| if (slot) |pane| if (pane.file) |*f| if (f.layer.owner == serial and pane.serial != serial) { hideLayer(p, f); setLanes(p, f, false); }; @@ -470,7 +470,7 @@ fn pinWord(c: pardes.builtins.Ctx, kind: Ask.Kind) void { } /// The layer shown in every view of every pane on `f`'s buffer, or in -/// none: its lines are the buffer's (File.read_only). A view's lanes take +/// none: its lines are the buffer's (File.layer.lines). A view's lanes take /// cells by its frontend (File.Layers.lanes). fn setLanes(p: *Pardes, f: *const File.State, on: bool) void { for (p.panes) |slot| { @@ -958,7 +958,7 @@ pub fn edited(p: *Pardes, f: *const File.State, off: usize, len: usize, bytes: [ // The values are the file's lines': the layer's lines before the edit // are none of them. var shown_before: usize = 0; - for (f.read_only) |r| { + for (f.layer.lines) |r| { if (r.at >= off) break; shown_before += 1; } @@ -970,7 +970,7 @@ pub fn edited(p: *Pardes, f: *const File.State, off: usize, len: usize, bytes: [ const shown = if (p.panes[id].?.file) |*shown| shown else continue; if (shown.content.ptr != f.content.ptr) continue; // The layer shown: its ghosts stand where its lines are (`placed`). - const placed_by_lines = c.serial == f.layer; + const placed_by_lines = c.serial == f.layer.owner; splice(p.gpa, c, f.content, off, len, bytes, shown_before, placed_by_lines) catch { // No room for it: its values would lie, so it goes; the one // shown stays (its lines are the buffer's, its places theirs). @@ -1016,7 +1016,7 @@ fn splice(gpa: std.mem.Allocator, c: *Changes, text: []const u8, off: usize, len /// A value a line, `values`, spliced as `splice` says, a line put in /// `none`; null when no line is taken or put. `text` is the buffer, whose /// `shown_before` lines before the edit are the layer's (none of the -/// file's: File.read_only). +/// file's: File.layer.lines). fn spliceValues(comptime T: type, gpa: std.mem.Allocator, values: *[]T, none: T, text: []const u8, off: usize, len: usize, bytes: []const u8, shown_before: usize) error{OutOfMemory}!?struct { from: usize, take: usize, put: usize } { const taken = std.mem.count(u8, text[off..][0..len], "\n"); const put = std.mem.count(u8, bytes, "\n"); @@ -1222,9 +1222,9 @@ fn heatOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, /// its place in the file (File.relayer). pub fn showLayer(p: *Pardes, f: *File.State, owner: u32) void { const ch = answered(p, owner) orelse return hideLayer(p, f); - if (f.layer != 0) hideLayer(p, f); + if (f.layer.owner != 0) hideLayer(p, f); // Not out (no memory): nothing more. - if (f.layer != 0) return; + if (f.layer.owner != 0) return; // The file's text, the layer out. const text = f.content; var size = text.len; @@ -1271,7 +1271,7 @@ pub fn showLayer(p: *Pardes, f: *File.State, owner: u32) void { /// every view keeps its place in the file: one in a line that leaves goes /// to the start of the file line it stood before (File.relayer). pub fn hideLayer(p: *Pardes, f: *File.State) void { - if (f.layer == 0) return; + if (f.layer.owner == 0) return; const text = File.fileText(f, p.scratch.allocator()) catch return; const new = pardes.memory.dupeUnfilled(p.gpa, text) catch return; if (!File.relayer(p, f, new, &.{}, 0)) pardes.memory.freeRaw(p.gpa, new); @@ -1280,12 +1280,12 @@ pub fn hideLayer(p: *Pardes, f: *File.State) void { /// A session loaded from a dump that kept a layer shown as a view's bit /// and no lines (wire 31 and older: the ghost rows were drawn, not the /// buffer's): each pane whose views showed it, its lines in its buffer -/// and shown in every view (File.read_only), its places kept in the file. +/// and shown in every view (File.layer.lines), its places kept in the file. pub fn loaded(p: *Pardes) void { for (p.panes) |slot| { const pane = slot orelse continue; const f = if (pane.file) |*file| file else continue; - if (f.layer != 0 or answered(p, pane.serial) == null) continue; + if (f.layer.owner != 0 or answered(p, pane.serial) == null) continue; const shown = pane.layers.lanes > 0 or for (0..pardes.views.max) |k| { if (k != p.live and p.views[k] != null and pane.pv[k].layers.lanes > 0) break true; } else false; @@ -1298,9 +1298,9 @@ pub fn loaded(p: *Pardes) void { /// After an edit of `f`'s buffer (File.edit): the shown layer's ghosts /// stand before the file lines their lines stand before. pub fn placed(p: *Pardes, f: *const File.State) void { - const ch = answered(p, f.layer) orelse return; - if (ch.ghosts.len != f.read_only.len) return; - for (ch.ghosts, f.read_only) |*g, r| g.at = r.line; + const ch = answered(p, f.layer.owner) orelse return; + if (ch.ghosts.len != f.layer.lines.len) return; + for (ch.ghosts, f.layer.lines) |*g, r| g.at = r.line; } const Read = union(enum) { refused: []u8, read: Changes }; @@ -2034,7 +2034,7 @@ fn ownerOf(ch: *const Changes, f: *const File.State, row: usize) PinIndex { pub fn nextChange(p: *Pardes, pane: *const Pane, from: usize, forward: bool) ?usize { if (pane.layers.lanes == 0) return null; const f = if (pane.file) |*file| file else return null; - const ch = answered(p, f.layer) orelse return null; + const ch = answered(p, f.layer.owner) orelse return null; const n = File.lineCount(f.content); var row = from; while (true) { @@ -2057,7 +2057,7 @@ pub fn nextChange(p: *Pardes, pane: *const Pane, from: usize, forward: bool) ?us pub fn lookGhost(p: *Pardes, id: usize, vr: i32, col: i32) bool { const pane = p.panes[id].?; const f = if (pane.file) |*file| file else return false; - const ch = answered(p, f.layer) orelse return false; + const ch = answered(p, f.layer.owner) orelse return false; const tab = p.settings.tab; const w = pane.wrapAt(tab, vr); if (w.line < 0 or w.at != 0) return false; @@ -2379,7 +2379,7 @@ pub fn railHeat(p: *Pardes, s: *pardes.Surface, pane: *Pane, id: usize, rail: pa fn paintLanes(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, body_h: u16) void { const f = if (pane.file) |*file| file else return; - const ch = answered(p, f.layer) orelse return; + const ch = answered(p, f.layer.owner) orelse return; if (ch.lines.len == 0) return; const tab = p.settings.tab; var buf: [8][3]u8 = undefined; @@ -2682,7 +2682,7 @@ test "the layer is the pane's: Changes in one view shows its lines in every view try testing.expectEqual(before + levels, File.gutterWidth(pane)); const shown = try gpa.dupe(u8, pane.file.?.content); defer gpa.free(shown); - try testing.expect(pane.file.?.read_only.len > 0); + try testing.expect(pane.file.?.layer.lines.len > 0); // Shown in the other view too, its lines the same. p.toView(other); try testing.expectEqual(levels, pane.layers.lanes); @@ -2701,7 +2701,7 @@ test "the layer is the pane's: Changes in one view shows its lines in every view try testing.expectEqual(0, pane.layers.lanes); try testing.expectEqual(before, File.gutterWidth(pane)); try testing.expectEqualStrings(Repo.two, pane.file.?.content); - try testing.expectEqual(@as(usize, 0), pane.file.?.read_only.len); + try testing.expectEqual(@as(usize, 0), pane.file.?.layer.lines.len); } test "a client replays Changes from what the session's jj answered and ends equal" { @@ -3544,7 +3544,7 @@ test "the node keys and the indent read the file's text: Alt-o and a function's for ([_]bool{ true, false }) |layer| { p.view().active = id; if (!layer) p.update(.{ .command = "Changes" }); - try testing.expectEqual(layer, f.read_only.len > 0); + try testing.expectEqual(layer, f.layer.lines.len > 0); const row: i32 = if (layer) 4 else 2; for (std.enums.values(Gesture), 0..) |g, k| { p.view().active = id; @@ -3566,7 +3566,7 @@ test "the node keys and the indent read the file's text: Alt-o and a function's for ([_]bool{ false, true }, &opened) |layer, *o| { p.view().active = id; if (layer) p.update(.{ .command = "Changes" }); - try testing.expectEqual(layer, f.read_only.len > 0); + try testing.expectEqual(layer, f.layer.lines.len > 0); Lines.at(pane, if (layer) 4 else 2, 4); Lines.send(p, "ox\x1b"); o.* = try arena.allocator().dupe(u8, try File.fileText(f, arena.allocator())); @@ -3651,7 +3651,7 @@ test "THE FILE'S TEXT: with the layer's lines in the buffer, every reader of the const pane = p.panes[id].?; const f = &pane.file.?; if (shown) p.update(.{ .command = "Changes @-" }); - try testing.expectEqual(shown, f.read_only.len > 0); + try testing.expectEqual(shown, f.layer.lines.len > 0); // The same edit of a file line, `c2();` (its line 3). p.update(.{ .command = "Look :3" }); Lines.send(p, ";A // e\x1b"); @@ -3701,11 +3701,11 @@ test "THE FILE'S TEXT: with the layer's lines in the buffer, every reader of the p.update(.{ .command = "Changes @-" }); got.lines = try keep.dupe(Line, answered(p, pane.serial).?.lines); if (!shown) p.update(.{ .command = "Changes" }); - try testing.expectEqual(shown, f.read_only.len > 0); + try testing.expectEqual(shown, f.layer.lines.len > 0); // A Get: the file's text from where it was read, the layer kept. p.update(.{ .command = "Get" }); got.gotten = try keep.dupe(u8, try File.fileText(f, arena.allocator())); - try testing.expectEqual(shown, f.read_only.len > 0); + try testing.expectEqual(shown, f.layer.lines.len > 0); } const off, const on = seen; try testing.expectEqualStrings("fn f() void {\n a();\n c2(); // e\n}\n", off.saved); @@ -3737,7 +3737,7 @@ test "an edit made while the layer is shown is the file's: journaled in its line // Undone while shown, redone. Lines.send(p, "u"); try testing.expectEqualStrings(Lines.cut_text, try File.fileText(f, arena.allocator())); - try testing.expectEqual(@as(usize, 3), f.read_only.len); + try testing.expectEqual(@as(usize, 3), f.layer.lines.len); try testing.expectEqual(@as(i32, 4), pane.body.cur_row); Lines.send(p, "U"); try testing.expectEqualStrings(typed, try File.fileText(f, arena.allocator())); @@ -3816,7 +3816,7 @@ test "a session dumped by a build whose layer was a view's bit and no lines (wir const back = q.panes[q.view().active].?; const bf = &back.file.?; try testing.expectEqualStrings(Lines.cut_text, try File.fileText(bf, q.scratch.allocator())); - try testing.expectEqual(shown, bf.read_only.len == 3); + try testing.expectEqual(shown, bf.layer.lines.len == 3); try testing.expectEqual(shown, back.layers.lanes > 0); // The cursor on `c2();` (the file's line 3) as it was. try testing.expectEqualStrings(" c2();", File.sourceLine(back, back.body.cur_row)); @@ -3902,7 +3902,7 @@ test "a client replays the layer's lines and an edit refused among them, and end const rf = &r.core().panes[id].?.file.?; try testing.expectEqualStrings("fn f() void {\n a();\n c2();;\n}\n", try File.fileText(af, a.core.scratch.allocator())); try testing.expectEqualStrings(af.content, rf.content); - try testing.expectEqualSlices(File.ReadOnly, af.read_only, rf.read_only); + try testing.expectEqualSlices(File.ReadOnly, af.layer.lines, rf.layer.lines); try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core())); try R.loadsAsSession(a, 2); } |
