detached 0254710

Merge pull request 'perf: stop decoding rows in copy navigation and reuse transient compose pages' (#15) from perf/render-copy-allocations into main

commit
0254710a72a251d8a805f3d81d9378e40b09b1dd
author
bnema · · 2026-10-08 08:22 UTC
merge of
1c3372f + df3f959 · diff against the first parent
signature
unsigned
7 files · +317 -9
M internal/usecase/copy/document.go +2 -1
@@ -241,7 +241,8 @@ func (d *Document) NextWordEnd(pos Pos) (Pos, bool) {
241241 // LineText returns row text without duplicated continuation cells and retains
242242 // the established copy-mode behavior of trimming trailing blank spaces.
243243 func (d *Document) LineText(row int) string {
244- return strings.TrimRight(d.cellsText(d.Row(row), 0, len(d.Row(row))-1), " ")
244+ cells := d.Row(row)
245+ return strings.TrimRight(d.cellsText(cells, 0, len(cells)-1), " ")
245246 }
246247
247248 // Extract renders inclusive ranges as copyable text. Every emitted line drops
@@ -241,7 +241,8 @@ func (d *Document) NextWordEnd(pos Pos) (Pos, bool) {
241 // LineText returns row text without duplicated continuation cells and retains241 // LineText returns row text without duplicated continuation cells and retains
242 // the established copy-mode behavior of trimming trailing blank spaces.242 // the established copy-mode behavior of trimming trailing blank spaces.
243 func (d *Document) LineText(row int) string {243 func (d *Document) LineText(row int) string {
244- return strings.TrimRight(d.cellsText(d.Row(row), 0, len(d.Row(row))-1), " ")244+ cells := d.Row(row)
245+ return strings.TrimRight(d.cellsText(cells, 0, len(cells)-1), " ")
245 }246 }
246 247
247 // Extract renders inclusive ranges as copyable text. Every emitted line drops248 // Extract renders inclusive ranges as copyable text. Every emitted line drops
M internal/usecase/copy/navigator.go +3 -3
@@ -140,11 +140,11 @@ func (n *Navigator) moveVertical(doc *Document, row int) bool {
140140 }
141141
142142 func navigatorPosOnRow(doc *Document, row, col int) (Pos, bool) {
143- cells := doc.Row(row)
144- if len(cells) == 0 {
143+ width := doc.RowWidth(row)
144+ if width == 0 {
145145 return doc.Normalize(Pos{Row: row, Col: 0})
146146 }
147- col = min(max(col, 0), len(cells)-1)
147+ col = min(max(col, 0), width-1)
148148 return doc.Normalize(Pos{Row: row, Col: col})
149149 }
150150
@@ -140,11 +140,11 @@ func (n *Navigator) moveVertical(doc *Document, row int) bool {
140 }140 }
141 141
142 func navigatorPosOnRow(doc *Document, row, col int) (Pos, bool) {142 func navigatorPosOnRow(doc *Document, row, col int) (Pos, bool) {
143- cells := doc.Row(row)143+ width := doc.RowWidth(row)
144- if len(cells) == 0 {144+ if width == 0 {
145 return doc.Normalize(Pos{Row: row, Col: 0})145 return doc.Normalize(Pos{Row: row, Col: 0})
146 }146 }
147- col = min(max(col, 0), len(cells)-1)147+ col = min(max(col, 0), width-1)
148 return doc.Normalize(Pos{Row: row, Col: col})148 return doc.Normalize(Pos{Row: row, Col: col})
149 }149 }
150 150
M internal/usecase/copy/navigator_test.go +46 -1
@@ -3,7 +3,8 @@ package copy
33 import (
44 "testing"
55
6- renderer "github.com/bnema/vev-vt"
6+ vt "github.com/bnema/vev-vt"
7+ renderer "github.com/bnema/vev-vt/ansi"
78 "github.com/stretchr/testify/require"
89 )
910
@@ -136,3 +137,47 @@ func TestNavigatorEmptyTopBottomPageAndSet(t *testing.T) {
136137 require.Equal(t, Pos{Row: 2, Col: 0}, navigator.Pos)
137138 })
138139 }
140+
141+func TestNavigatorVerticalMovesDoNotAllocate(t *testing.T) {
142+ history := vt.NewHistory(vt.HistoryConfig{MaxRows: 8, ChunkRows: 4})
143+ for _, text := range []string{"abcdef", "xy", "界z", "", "omega"} {
144+ cells := documentCells(text)
145+ if text == "界z" {
146+ cells = []renderer.Cell{{Rune: '界'}, {Continuation: true}, {Rune: 'z'}}
147+ }
148+ require.NoError(t, history.Append(cells, vt.LineBound{End: len(cells)}))
149+ }
150+ // Rows 0-4 come from history and rows 5-6 from the live screen.
151+ doc := NewDocument(NewSnapshot(history, renderer.NewFrame(6, 2), nil, nil), " -_@")
152+ require.Equal(t, 7, doc.Len())
153+
154+ tests := []struct {
155+ name string
156+ move func(*Navigator, *Document) bool
157+ from Pos
158+ pref int
159+ want Pos
160+ }{
161+ {"down clamps to short row", (*Navigator).Down, Pos{Row: 0, Col: 5}, 5, Pos{Row: 1, Col: 1}},
162+ {"down lands on wide head", (*Navigator).Down, Pos{Row: 1, Col: 1}, 1, Pos{Row: 2, Col: 0}},
163+ {"down onto empty row", (*Navigator).Down, Pos{Row: 2, Col: 2}, 2, Pos{Row: 3, Col: 0}},
164+ {"up from empty row", (*Navigator).Up, Pos{Row: 3, Col: 0}, 4, Pos{Row: 2, Col: 2}},
165+ {"down into history tail", (*Navigator).Down, Pos{Row: 3, Col: 0}, 9, Pos{Row: 4, Col: 4}},
166+ {"down into live screen", (*Navigator).Down, Pos{Row: 4, Col: 4}, 4, Pos{Row: 5, Col: 4}},
167+ {"up out of live screen", (*Navigator).Up, Pos{Row: 5, Col: 4}, 4, Pos{Row: 4, Col: 4}},
168+ {"page down clamps to last row", func(n *Navigator, d *Document) bool { return n.Page(d, 100) }, Pos{Row: 0, Col: 2}, 2, Pos{Row: 6, Col: 2}},
169+ {"page up clamps to first row", func(n *Navigator, d *Document) bool { return n.Page(d, -100) }, Pos{Row: 6, Col: 2}, 2, Pos{Row: 0, Col: 2}},
170+ }
171+ for _, tt := range tests {
172+ t.Run(tt.name, func(t *testing.T) {
173+ navigator := &Navigator{}
174+ allocs := testing.AllocsPerRun(100, func() {
175+ *navigator = Navigator{Pos: tt.from, PreferredCol: tt.pref}
176+ if !tt.move(navigator, doc) || navigator.Pos != tt.want {
177+ t.Fatalf("move() = %v, want %v", navigator.Pos, tt.want)
178+ }
179+ })
180+ require.Zero(t, allocs, "vertical navigation must not decode rows")
181+ })
182+ }
183+}
@@ -3,7 +3,8 @@ package copy
3 import (3 import (
4 "testing"4 "testing"
5 5
6- renderer "github.com/bnema/vev-vt"6+ vt "github.com/bnema/vev-vt"
7+ renderer "github.com/bnema/vev-vt/ansi"
7 "github.com/stretchr/testify/require"8 "github.com/stretchr/testify/require"
8 )9 )
9 10
@@ -136,3 +137,47 @@ func TestNavigatorEmptyTopBottomPageAndSet(t *testing.T) {
136 require.Equal(t, Pos{Row: 2, Col: 0}, navigator.Pos)137 require.Equal(t, Pos{Row: 2, Col: 0}, navigator.Pos)
137 })138 })
138 }139 }
140+
141+func TestNavigatorVerticalMovesDoNotAllocate(t *testing.T) {
142+ history := vt.NewHistory(vt.HistoryConfig{MaxRows: 8, ChunkRows: 4})
143+ for _, text := range []string{"abcdef", "xy", "界z", "", "omega"} {
144+ cells := documentCells(text)
145+ if text == "界z" {
146+ cells = []renderer.Cell{{Rune: '界'}, {Continuation: true}, {Rune: 'z'}}
147+ }
148+ require.NoError(t, history.Append(cells, vt.LineBound{End: len(cells)}))
149+ }
150+ // Rows 0-4 come from history and rows 5-6 from the live screen.
151+ doc := NewDocument(NewSnapshot(history, renderer.NewFrame(6, 2), nil, nil), " -_@")
152+ require.Equal(t, 7, doc.Len())
153+
154+ tests := []struct {
155+ name string
156+ move func(*Navigator, *Document) bool
157+ from Pos
158+ pref int
159+ want Pos
160+ }{
161+ {"down clamps to short row", (*Navigator).Down, Pos{Row: 0, Col: 5}, 5, Pos{Row: 1, Col: 1}},
162+ {"down lands on wide head", (*Navigator).Down, Pos{Row: 1, Col: 1}, 1, Pos{Row: 2, Col: 0}},
163+ {"down onto empty row", (*Navigator).Down, Pos{Row: 2, Col: 2}, 2, Pos{Row: 3, Col: 0}},
164+ {"up from empty row", (*Navigator).Up, Pos{Row: 3, Col: 0}, 4, Pos{Row: 2, Col: 2}},
165+ {"down into history tail", (*Navigator).Down, Pos{Row: 3, Col: 0}, 9, Pos{Row: 4, Col: 4}},
166+ {"down into live screen", (*Navigator).Down, Pos{Row: 4, Col: 4}, 4, Pos{Row: 5, Col: 4}},
167+ {"up out of live screen", (*Navigator).Up, Pos{Row: 5, Col: 4}, 4, Pos{Row: 4, Col: 4}},
168+ {"page down clamps to last row", func(n *Navigator, d *Document) bool { return n.Page(d, 100) }, Pos{Row: 0, Col: 2}, 2, Pos{Row: 6, Col: 2}},
169+ {"page up clamps to first row", func(n *Navigator, d *Document) bool { return n.Page(d, -100) }, Pos{Row: 6, Col: 2}, 2, Pos{Row: 0, Col: 2}},
170+ }
171+ for _, tt := range tests {
172+ t.Run(tt.name, func(t *testing.T) {
173+ navigator := &Navigator{}
174+ allocs := testing.AllocsPerRun(100, func() {
175+ *navigator = Navigator{Pos: tt.from, PreferredCol: tt.pref}
176+ if !tt.move(navigator, doc) || navigator.Pos != tt.want {
177+ t.Fatalf("move() = %v, want %v", navigator.Pos, tt.want)
178+ }
179+ })
180+ require.Zero(t, allocs, "vertical navigation must not decode rows")
181+ })
182+ }
183+}
M internal/usecase/daemon/floating_render.go +4 -1
@@ -133,6 +133,9 @@ type floatingComposeInput struct {
133133 borderActive renderer.Style
134134 cache composeCacheInput
135135 full bool
136+ // scratch, when non-nil, is the page the popup frame is composed into. It
137+ // must not alias baseFrame's page; nil allocates a clone.
138+ scratch *renderer.Frame
136139 }
137140
138141 func composeCapturedFloatingFrame(input floatingComposeInput) (renderer.Frame, []renderer.Damage) {
@@ -146,7 +149,7 @@ func composeCapturedFloatingFrame(input floatingComposeInput) (renderer.Frame, [
146149 cache := input.cache
147150 full := input.full
148151
149- frame := base.Clone()
152+ frame := copyFrameInto(input.scratch, base)
150153 applyOverlayBackdrop(frame, theme)
151154 geometry := floating.geometry.translate(content.X, content.Y)
152155 blitClippedFloatingPane(frame, geometry.Inner, floating.pane.frame)
@@ -133,6 +133,9 @@ type floatingComposeInput struct {
133 borderActive renderer.Style133 borderActive renderer.Style
134 cache composeCacheInput134 cache composeCacheInput
135 full bool135 full bool
136+ // scratch, when non-nil, is the page the popup frame is composed into. It
137+ // must not alias baseFrame's page; nil allocates a clone.
138+ scratch *renderer.Frame
136 }139 }
137 140
138 func composeCapturedFloatingFrame(input floatingComposeInput) (renderer.Frame, []renderer.Damage) {141 func composeCapturedFloatingFrame(input floatingComposeInput) (renderer.Frame, []renderer.Damage) {
@@ -146,7 +149,7 @@ func composeCapturedFloatingFrame(input floatingComposeInput) (renderer.Frame, [
146 cache := input.cache149 cache := input.cache
147 full := input.full150 full := input.full
148 151
149- frame := base.Clone()152+ frame := copyFrameInto(input.scratch, base)
150 applyOverlayBackdrop(frame, theme)153 applyOverlayBackdrop(frame, theme)
151 geometry := floating.geometry.translate(content.X, content.Y)154 geometry := floating.geometry.translate(content.X, content.Y)
152 blitClippedFloatingPane(frame, geometry.Inner, floating.pane.frame)155 blitClippedFloatingPane(frame, geometry.Inner, floating.pane.frame)
M internal/usecase/daemon/floating_render_test.go +50 -0
@@ -709,6 +709,52 @@ func TestComposeCapturedFloatingFrameCachedAllocationsAreOnlyFrameClone(t *testi
709709 }
710710 }
711711
712+// TestComposeCapturedFloatingFrameScratchReusesPopupPage pins that a primed
713+// scratch page removes the per-frame base clone, leaves the base untouched,
714+// and yields exactly the frame an unscratched composition builds.
715+func TestComposeCapturedFloatingFrameScratchReusesPopupPage(t *testing.T) {
716+ base := renderer.NewFrame(80, 24)
717+ for y := range base.Height {
718+ for x := range base.Width {
719+ base.Set(x, y, renderer.Cell{Rune: rune('a' + (x+y)%26), Style: renderer.DefaultStyle()})
720+ }
721+ }
722+ content := domain.Rect{Y: 1, Width: 80, Height: 22}
723+ geometry := calculateContentFloatingGeometry(domain.Size{Cols: content.Width, Rows: content.Height}, domain.FloatingConfig{Width: 80, Height: 80})
724+ input := floatingComposeInput{
725+ baseFrame: base,
726+ floating: capturedFloatingRenderState{
727+ visible: true,
728+ pane: capturedPaneRenderState{frame: renderer.NewFrame(62, 18), title: "float", titleGeneration: 1},
729+ geometry: geometry,
730+ title: "float",
731+ generation: 1,
732+ titleGeneration: 1,
733+ },
734+ content: content,
735+ cache: composeCacheInput{
736+ valid: true, floatingGeneration: 1, floatingGeometry: geometry.translate(content.X, content.Y), floatingTitleGeneration: 1,
737+ },
738+ }
739+ baseBefore := frameRows(base)
740+ want, wantDamage := composeCapturedFloatingFrame(input)
741+
742+ var popup renderer.Frame
743+ input.scratch = &popup
744+ got, gotDamage := composeCapturedFloatingFrame(input) // sizes the scratch page
745+ require.Equal(t, frameRows(want), frameRows(got))
746+ require.Equal(t, wantDamage, gotDamage)
747+ require.False(t, framesShareStorage(got, base), "popup frame must not alias the base page")
748+ require.Equal(t, baseBefore, frameRows(base), "base must stay free of popup cells")
749+
750+ allocs := testing.AllocsPerRun(100, func() { composeCapturedFloatingFrame(input) })
751+ cloneAllocs := testing.AllocsPerRun(100, func() { benchmarkComposeSink.frame = base.Clone() })
752+ require.Less(t, allocs, cloneAllocs, "scratch composition must allocate less than a clone")
753+ if copyEnterAllocationBudgetEnabled {
754+ assertRenderByteBudget(t, func() { benchmarkComposeSink.frame, _ = composeCapturedFloatingFrame(input) }, 1<<10)
755+ }
756+}
757+
712758 var (
713759 benchmarkComposeSink composedRenderFrame
714760 benchmarkOutputSink []byte
@@ -817,6 +863,10 @@ func BenchmarkComposeCapturedFloatingFrameCached(b *testing.B) {
817863 },
818864 }
819865
866+ // Production passes the attachment's reusable popup page.
867+ var popup renderer.Frame
868+ input.scratch = &popup
869+
820870 b.ReportAllocs()
821871 b.ResetTimer()
822872 for b.Loop() {
@@ -709,6 +709,52 @@ func TestComposeCapturedFloatingFrameCachedAllocationsAreOnlyFrameClone(t *testi
709 }709 }
710 }710 }
711 711
712+// TestComposeCapturedFloatingFrameScratchReusesPopupPage pins that a primed
713+// scratch page removes the per-frame base clone, leaves the base untouched,
714+// and yields exactly the frame an unscratched composition builds.
715+func TestComposeCapturedFloatingFrameScratchReusesPopupPage(t *testing.T) {
716+ base := renderer.NewFrame(80, 24)
717+ for y := range base.Height {
718+ for x := range base.Width {
719+ base.Set(x, y, renderer.Cell{Rune: rune('a' + (x+y)%26), Style: renderer.DefaultStyle()})
720+ }
721+ }
722+ content := domain.Rect{Y: 1, Width: 80, Height: 22}
723+ geometry := calculateContentFloatingGeometry(domain.Size{Cols: content.Width, Rows: content.Height}, domain.FloatingConfig{Width: 80, Height: 80})
724+ input := floatingComposeInput{
725+ baseFrame: base,
726+ floating: capturedFloatingRenderState{
727+ visible: true,
728+ pane: capturedPaneRenderState{frame: renderer.NewFrame(62, 18), title: "float", titleGeneration: 1},
729+ geometry: geometry,
730+ title: "float",
731+ generation: 1,
732+ titleGeneration: 1,
733+ },
734+ content: content,
735+ cache: composeCacheInput{
736+ valid: true, floatingGeneration: 1, floatingGeometry: geometry.translate(content.X, content.Y), floatingTitleGeneration: 1,
737+ },
738+ }
739+ baseBefore := frameRows(base)
740+ want, wantDamage := composeCapturedFloatingFrame(input)
741+
742+ var popup renderer.Frame
743+ input.scratch = &popup
744+ got, gotDamage := composeCapturedFloatingFrame(input) // sizes the scratch page
745+ require.Equal(t, frameRows(want), frameRows(got))
746+ require.Equal(t, wantDamage, gotDamage)
747+ require.False(t, framesShareStorage(got, base), "popup frame must not alias the base page")
748+ require.Equal(t, baseBefore, frameRows(base), "base must stay free of popup cells")
749+
750+ allocs := testing.AllocsPerRun(100, func() { composeCapturedFloatingFrame(input) })
751+ cloneAllocs := testing.AllocsPerRun(100, func() { benchmarkComposeSink.frame = base.Clone() })
752+ require.Less(t, allocs, cloneAllocs, "scratch composition must allocate less than a clone")
753+ if copyEnterAllocationBudgetEnabled {
754+ assertRenderByteBudget(t, func() { benchmarkComposeSink.frame, _ = composeCapturedFloatingFrame(input) }, 1<<10)
755+ }
756+}
757+
712 var (758 var (
713 benchmarkComposeSink composedRenderFrame759 benchmarkComposeSink composedRenderFrame
714 benchmarkOutputSink []byte760 benchmarkOutputSink []byte
@@ -817,6 +863,10 @@ func BenchmarkComposeCapturedFloatingFrameCached(b *testing.B) {
817 },863 },
818 }864 }
819 865
866+ // Production passes the attachment's reusable popup page.
867+ var popup renderer.Frame
868+ input.scratch = &popup
869+
820 b.ReportAllocs()870 b.ReportAllocs()
821 b.ResetTimer()871 b.ResetTimer()
822 for b.Loop() {872 for b.Loop() {
M internal/usecase/daemon/render_pipeline.go +54 -3
@@ -48,6 +48,39 @@ type composeCacheInput struct {
4848 theme themeui.Theme
4949 styleGeneration uint64
5050 copyViewport copyViewportState
51+ // transient holds reusable pages for frames that are painted for one
52+ // publication only (toasts, floating popups, modals). See transientFrames.
53+ transient transientFrames
54+}
55+
56+// transientFrames are scratch pages for composed frames that never become a
57+// cache: renderer.Prepare copies the frame it is given, so once a publication
58+// finishes nothing references them. They travel with composeCacheInput through
59+// the same commit/spare rotation as the cached frame, so a page is only ever
60+// written by a composition whose input scratch owns it. Neither slot may hold
61+// a page shared with a cached frame (frame, copyViewport.frame) or with another
62+// slot; they are filled only by copyFrameInto, which allocates a fresh page.
63+type transientFrames struct {
64+ // overlay receives the toast-decorated or modal-decorated copy of the base
65+ // frame. Toasts and modals never both clone, so they share the slot.
66+ overlay renderer.Frame
67+ // popup receives the floating-terminal composition. It may start from the
68+ // overlay page (toasts under a popup), so it must be a distinct page.
69+ popup renderer.Frame
70+}
71+
72+// copyFrameInto makes *dst an independent copy of src, reusing dst's storage,
73+// and returns it. A nil dst (direct callers without scratch) allocates a clone.
74+func copyFrameInto(dst *renderer.Frame, src renderer.Frame) renderer.Frame {
75+ if dst == nil {
76+ return src.Clone()
77+ }
78+ dst.CopyFrom(src)
79+ if dst.Width != src.Width || dst.Height != src.Height {
80+ // CopyFrom leaves dst untouched for an unusable source.
81+ *dst = src.Clone()
82+ }
83+ return *dst
5184 }
5285
5386 type composedRenderFrame struct {
@@ -174,8 +207,14 @@ func composeFrame(state capturedRenderState, in composeCacheInput, scratchIn ...
174207 overlaysActive := state.overlays.active()
175208 toastsVisible := len(state.overlays.notices) > 0 || state.overlays.noticeOverflow > 0
176209 var toastFootprints []domain.Rect
210+ // Toast, popup, and modal frames are transient: they live only until the
211+ // publication that consumes them, so they are composed into scratch pages
212+ // carried by the cache rotation instead of a fresh clone per frame.
213+ transient := scratch.transient
214+ usedOverlay := false
177215 if toastsVisible {
178- frame = baseFrame.Clone()
216+ usedOverlay = true
217+ frame = copyFrameInto(&transient.overlay, baseFrame)
179218 toastFootprints = composeCapturedNotices(state.overlays, frame, state.styles)
180219 }
181220 if state.floating.visible {
@@ -190,6 +229,7 @@ func composeFrame(state capturedRenderState, in composeCacheInput, scratchIn ...
190229 borderActive: styles.BorderActive,
191230 cache: in,
192231 full: full || overlaysActive,
232+ scratch: &transient.popup,
193233 })
194234 damage = floatingDamage
195235 }
@@ -216,12 +256,23 @@ func composeFrame(state capturedRenderState, in composeCacheInput, scratchIn ...
216256 frame = scratch.copyViewport.frame
217257 frame.CopyFrom(baseFrame)
218258 case !toastsVisible && !state.floating.visible:
219- frame = baseFrame.Clone()
259+ // Not a copy viewport (that is the case above), so this frame is
260+ // never retained as viewport cache.
261+ usedOverlay = true
262+ frame = copyFrameInto(&transient.overlay, baseFrame)
220263 }
221264 frame, damage = composeCapturedCopyMode(state, frame, damage, content)
222265 }
223266 frame, damage = composeCapturedOverlays(state, frame, damage)
224267 }
268+ // Release pages this composition did not need, so an attachment that stops
269+ // showing toasts, popups, or modals does not pin two spare frames forever.
270+ if !usedOverlay {
271+ transient.overlay = renderer.Frame{}
272+ }
273+ if !state.floating.visible {
274+ transient.popup = renderer.Frame{}
275+ }
225276 for x := range width {
226277 topBar[x] = baseFrame.Cell(x, 0)
227278 bottomBar[x] = baseFrame.Cell(x, rows+1)
@@ -252,7 +303,7 @@ func composeFrame(state capturedRenderState, in composeCacheInput, scratchIn ...
252303 // never into baseFrame. Keep
253304 // that unadorned base reusable between wheel events. Modal/floating paths
254305 // retain their conservative invalidation, and copy exit requests a reset.
255- outCache := composeCacheInput{valid: !overlaysActive || copyOnly, frame: baseFrame, layoutFingerprint: state.layout.fingerprint, theme: state.theme, styleGeneration: state.styleGeneration, titleGenerations: titles, damage: damage, toastFootprints: append(scratch.toastFootprints[:0], toastFootprints...), floatingVisible: state.floating.visible, floatingFocused: state.floating.focused, floatingGeneration: state.floating.generation, floatingGeometry: state.floating.geometry.translate(content.X, content.Y), floatingTitleGeneration: state.floating.titleGeneration, bars: scratch.bars}
306+ outCache := composeCacheInput{valid: !overlaysActive || copyOnly, frame: baseFrame, layoutFingerprint: state.layout.fingerprint, theme: state.theme, styleGeneration: state.styleGeneration, titleGenerations: titles, damage: damage, toastFootprints: append(scratch.toastFootprints[:0], toastFootprints...), floatingVisible: state.floating.visible, floatingFocused: state.floating.focused, floatingGeneration: state.floating.generation, floatingGeometry: state.floating.geometry.translate(content.X, content.Y), floatingTitleGeneration: state.floating.titleGeneration, bars: scratch.bars, transient: transient}
256307 outCache.bars = barCache{top: topBar, bottom: bottomBar}
257308 if copyViewport.document != nil {
258309 copyViewport.frame = frame
@@ -48,6 +48,39 @@ type composeCacheInput struct {
48 theme themeui.Theme48 theme themeui.Theme
49 styleGeneration uint6449 styleGeneration uint64
50 copyViewport copyViewportState50 copyViewport copyViewportState
51+ // transient holds reusable pages for frames that are painted for one
52+ // publication only (toasts, floating popups, modals). See transientFrames.
53+ transient transientFrames
54+}
55+
56+// transientFrames are scratch pages for composed frames that never become a
57+// cache: renderer.Prepare copies the frame it is given, so once a publication
58+// finishes nothing references them. They travel with composeCacheInput through
59+// the same commit/spare rotation as the cached frame, so a page is only ever
60+// written by a composition whose input scratch owns it. Neither slot may hold
61+// a page shared with a cached frame (frame, copyViewport.frame) or with another
62+// slot; they are filled only by copyFrameInto, which allocates a fresh page.
63+type transientFrames struct {
64+ // overlay receives the toast-decorated or modal-decorated copy of the base
65+ // frame. Toasts and modals never both clone, so they share the slot.
66+ overlay renderer.Frame
67+ // popup receives the floating-terminal composition. It may start from the
68+ // overlay page (toasts under a popup), so it must be a distinct page.
69+ popup renderer.Frame
70+}
71+
72+// copyFrameInto makes *dst an independent copy of src, reusing dst's storage,
73+// and returns it. A nil dst (direct callers without scratch) allocates a clone.
74+func copyFrameInto(dst *renderer.Frame, src renderer.Frame) renderer.Frame {
75+ if dst == nil {
76+ return src.Clone()
77+ }
78+ dst.CopyFrom(src)
79+ if dst.Width != src.Width || dst.Height != src.Height {
80+ // CopyFrom leaves dst untouched for an unusable source.
81+ *dst = src.Clone()
82+ }
83+ return *dst
51 }84 }
52 85
53 type composedRenderFrame struct {86 type composedRenderFrame struct {
@@ -174,8 +207,14 @@ func composeFrame(state capturedRenderState, in composeCacheInput, scratchIn ...
174 overlaysActive := state.overlays.active()207 overlaysActive := state.overlays.active()
175 toastsVisible := len(state.overlays.notices) > 0 || state.overlays.noticeOverflow > 0208 toastsVisible := len(state.overlays.notices) > 0 || state.overlays.noticeOverflow > 0
176 var toastFootprints []domain.Rect209 var toastFootprints []domain.Rect
210+ // Toast, popup, and modal frames are transient: they live only until the
211+ // publication that consumes them, so they are composed into scratch pages
212+ // carried by the cache rotation instead of a fresh clone per frame.
213+ transient := scratch.transient
214+ usedOverlay := false
177 if toastsVisible {215 if toastsVisible {
178- frame = baseFrame.Clone()216+ usedOverlay = true
217+ frame = copyFrameInto(&transient.overlay, baseFrame)
179 toastFootprints = composeCapturedNotices(state.overlays, frame, state.styles)218 toastFootprints = composeCapturedNotices(state.overlays, frame, state.styles)
180 }219 }
181 if state.floating.visible {220 if state.floating.visible {
@@ -190,6 +229,7 @@ func composeFrame(state capturedRenderState, in composeCacheInput, scratchIn ...
190 borderActive: styles.BorderActive,229 borderActive: styles.BorderActive,
191 cache: in,230 cache: in,
192 full: full || overlaysActive,231 full: full || overlaysActive,
232+ scratch: &transient.popup,
193 })233 })
194 damage = floatingDamage234 damage = floatingDamage
195 }235 }
@@ -216,12 +256,23 @@ func composeFrame(state capturedRenderState, in composeCacheInput, scratchIn ...
216 frame = scratch.copyViewport.frame256 frame = scratch.copyViewport.frame
217 frame.CopyFrom(baseFrame)257 frame.CopyFrom(baseFrame)
218 case !toastsVisible && !state.floating.visible:258 case !toastsVisible && !state.floating.visible:
219- frame = baseFrame.Clone()259+ // Not a copy viewport (that is the case above), so this frame is
260+ // never retained as viewport cache.
261+ usedOverlay = true
262+ frame = copyFrameInto(&transient.overlay, baseFrame)
220 }263 }
221 frame, damage = composeCapturedCopyMode(state, frame, damage, content)264 frame, damage = composeCapturedCopyMode(state, frame, damage, content)
222 }265 }
223 frame, damage = composeCapturedOverlays(state, frame, damage)266 frame, damage = composeCapturedOverlays(state, frame, damage)
224 }267 }
268+ // Release pages this composition did not need, so an attachment that stops
269+ // showing toasts, popups, or modals does not pin two spare frames forever.
270+ if !usedOverlay {
271+ transient.overlay = renderer.Frame{}
272+ }
273+ if !state.floating.visible {
274+ transient.popup = renderer.Frame{}
275+ }
225 for x := range width {276 for x := range width {
226 topBar[x] = baseFrame.Cell(x, 0)277 topBar[x] = baseFrame.Cell(x, 0)
227 bottomBar[x] = baseFrame.Cell(x, rows+1)278 bottomBar[x] = baseFrame.Cell(x, rows+1)
@@ -252,7 +303,7 @@ func composeFrame(state capturedRenderState, in composeCacheInput, scratchIn ...
252 // never into baseFrame. Keep303 // never into baseFrame. Keep
253 // that unadorned base reusable between wheel events. Modal/floating paths304 // that unadorned base reusable between wheel events. Modal/floating paths
254 // retain their conservative invalidation, and copy exit requests a reset.305 // retain their conservative invalidation, and copy exit requests a reset.
255- outCache := composeCacheInput{valid: !overlaysActive || copyOnly, frame: baseFrame, layoutFingerprint: state.layout.fingerprint, theme: state.theme, styleGeneration: state.styleGeneration, titleGenerations: titles, damage: damage, toastFootprints: append(scratch.toastFootprints[:0], toastFootprints...), floatingVisible: state.floating.visible, floatingFocused: state.floating.focused, floatingGeneration: state.floating.generation, floatingGeometry: state.floating.geometry.translate(content.X, content.Y), floatingTitleGeneration: state.floating.titleGeneration, bars: scratch.bars}306+ outCache := composeCacheInput{valid: !overlaysActive || copyOnly, frame: baseFrame, layoutFingerprint: state.layout.fingerprint, theme: state.theme, styleGeneration: state.styleGeneration, titleGenerations: titles, damage: damage, toastFootprints: append(scratch.toastFootprints[:0], toastFootprints...), floatingVisible: state.floating.visible, floatingFocused: state.floating.focused, floatingGeneration: state.floating.generation, floatingGeometry: state.floating.geometry.translate(content.X, content.Y), floatingTitleGeneration: state.floating.titleGeneration, bars: scratch.bars, transient: transient}
256 outCache.bars = barCache{top: topBar, bottom: bottomBar}307 outCache.bars = barCache{top: topBar, bottom: bottomBar}
257 if copyViewport.document != nil {308 if copyViewport.document != nil {
258 copyViewport.frame = frame309 copyViewport.frame = frame
A internal/usecase/daemon/render_transient_frames_test.go +158 -0
@@ -0,0 +1,158 @@
1+package daemon
2+
3+import (
4+ "testing"
5+
6+ renderer "github.com/bnema/vev-vt"
7+ "github.com/bnema/vev/internal/domain"
8+ "github.com/bnema/vev/internal/usecase/ui"
9+ "github.com/stretchr/testify/require"
10+)
11+
12+// framesShareStorage reports whether writing through a is visible through b.
13+func framesShareStorage(a, b renderer.Frame) bool {
14+ if a.Width <= 0 || a.Height <= 0 || b.Width != a.Width || b.Height != a.Height {
15+ return false
16+ }
17+ orig := a.Cell(0, 0)
18+ sentinel := renderer.Cell{Rune: '§', Style: renderer.DefaultStyle()}
19+ if orig.Equal(sentinel) {
20+ sentinel.Rune = '¶'
21+ }
22+ a.Set(0, 0, sentinel)
23+ shared := b.Cell(0, 0).Equal(sentinel)
24+ a.Set(0, 0, orig)
25+ return shared
26+}
27+
28+func transientToastFloatingState(withToast, withFloating, withModal bool, seed rune) capturedRenderState {
29+ var notices []domain.Notification
30+ if withToast {
31+ notices = []domain.Notification{{Code: domain.NoticeClipboard, Severity: domain.NoticeInfo, Message: "copied", Count: 1}}
32+ }
33+ state := toastDamageState(notices, []renderer.Damage{{Kind: renderer.DamageText, X: 0, Y: 0, Width: 1, Height: 1}}, false)
34+ state.panes[0].frame.Set(0, 0, renderer.Cell{Rune: seed, Style: renderer.DefaultStyle()})
35+ if withFloating {
36+ content := domain.Rect{Y: 1, Width: 80, Height: 20}
37+ geometry := calculateContentFloatingGeometry(domain.Size{Cols: content.Width, Rows: content.Height}, domain.FloatingConfig{Width: 60, Height: 60})
38+ state.floating = capturedFloatingRenderState{
39+ visible: true,
40+ pane: capturedPaneRenderState{frame: renderer.NewFrame(geometry.Inner.Width, geometry.Inner.Height), title: "float"},
41+ geometry: geometry,
42+ title: "float",
43+ generation: 1,
44+ }
45+ }
46+ if withModal {
47+ // A modal without toast or floating is the second writer of the
48+ // overlay transient page.
49+ state.overlays.promptActive = true
50+ state.overlays.prompt = capturedModal{
51+ active: true,
52+ title: "Prompt",
53+ presentation: ui.Presentation{
54+ Bounds: domain.Rect{X: 10, Y: 5, Width: 20, Height: 3},
55+ Inner: domain.Rect{X: 11, Y: 6, Width: 18, Height: 1},
56+ Borders: ui.BorderAll,
57+ },
58+ }
59+ }
60+ return state
61+}
62+
63+// TestComposeFrameTransientScratchNeverAliasesCaches replays the attachment
64+// commit/spare rotation across toast, floating, modal, and plain frames, and
65+// across failed publications that compose again without committing. Each result
66+// must match an independent composition without scratch, the retained cache
67+// must stay toast-free, and no handed-out frame may share a page with either
68+// cache slot (which would let a later paint corrupt committed state).
69+func TestComposeFrameTransientScratchNeverAliasesCaches(t *testing.T) {
70+ type step struct {
71+ toast, floating, modal bool
72+ // failed skips commitComposition, as a failed prepare or send does, so
73+ // the next step composes again from the same spare.
74+ failed bool
75+ }
76+ steps := []step{
77+ {}, {toast: true}, {toast: true}, {toast: true, floating: true}, {floating: true},
78+ {modal: true}, {modal: true, failed: true}, {modal: true}, {toast: true, modal: true},
79+ {toast: true, floating: true, failed: true}, {toast: true, floating: true}, {toast: true},
80+ {}, {toast: true, failed: true}, {toast: true}, {floating: true}, {toast: true, floating: true},
81+ }
82+ var render attachmentRenderState
83+ for i, st := range steps {
84+ seed := rune('A' + i)
85+ state := transientToastFloatingState(st.toast, st.floating, st.modal, seed)
86+ state.reset = i == 0
87+ // A frame without scratch is the reference: it only ever clones.
88+ want := composeFrame(state, render.cache)
89+ got := composeFrame(state, render.cache, render.spare)
90+
91+ require.Equal(t, frameRows(want.frame), frameRows(got.frame), "step %d frame", i)
92+ require.Equal(t, frameRows(want.cache.frame), frameRows(got.cache.frame), "step %d cache", i)
93+ require.Equal(t, want.damage, got.damage, "step %d damage", i)
94+
95+ // The result is built in the spare page, so it may share that one, but it
96+ // must never touch the committed cache a failed publication falls back to.
97+ require.False(t, framesShareStorage(got.frame, render.cache.frame), "step %d: composed frame aliases the committed cache", i)
98+ require.False(t, framesShareStorage(got.cache.frame, render.cache.frame), "step %d: new cache base aliases the committed cache", i)
99+ if st.toast || st.floating || st.modal {
100+ // A decorated frame lives on a transient page: never the cache base
101+ // (toast-free by contract) nor the committed or spare cache pages.
102+ require.False(t, framesShareStorage(got.frame, got.cache.frame), "step %d: decorated frame aliases the cache base", i)
103+ require.False(t, framesShareStorage(got.frame, render.spare.frame), "step %d: decorated frame aliases the spare cache", i)
104+ }
105+ require.NotContains(t, frameText(got.cache.frame), "copied", "step %d: cache must stay toast-free", i)
106+
107+ if st.failed {
108+ continue
109+ }
110+ beforeCommitted := frameRows(render.cache.frame)
111+ render.commitComposition(got.cache)
112+ if i > 0 {
113+ require.Equal(t, beforeCommitted, frameRows(render.spare.frame))
114+ }
115+ // The two slots' transient pages must be distinct from each other, from
116+ // both cache frames, and from every frame the next composition reads.
117+ pages := []renderer.Frame{render.cache.transient.overlay, render.cache.transient.popup, render.spare.transient.overlay, render.spare.transient.popup}
118+ for a := range pages {
119+ for b := a + 1; b < len(pages); b++ {
120+ require.False(t, framesShareStorage(pages[a], pages[b]), "step %d: transient pages %d and %d alias", i, a, b)
121+ }
122+ require.False(t, framesShareStorage(pages[a], render.cache.frame), "step %d: transient page %d aliases cache", i, a)
123+ require.False(t, framesShareStorage(pages[a], render.spare.frame), "step %d: transient page %d aliases spare", i, a)
124+ }
125+ }
126+}
127+
128+// TestComposeFrameStableToastReusesScratchPages pins the saving: with a primed
129+// scratch, a stable toast frame no longer clones the base page.
130+func TestComposeFrameStableToastReusesScratchPages(t *testing.T) {
131+ base := composeFrame(toastDamageState(nil, nil, true), composeCacheInput{})
132+ notice := []domain.Notification{{Code: domain.NoticeClipboard, Severity: domain.NoticeInfo, Message: "copied", Count: 1}}
133+ shown := composeFrame(toastDamageState(notice, nil, false), base.cache, composeCacheInput{})
134+ state := toastDamageState(notice, []renderer.Damage{{Kind: renderer.DamageText, X: 0, Y: 0, Width: 1, Height: 1}}, false)
135+
136+ cache, scratch := shown.cache, base.cache
137+ // Prime both rotation slots so every page has reached its steady size.
138+ for range 3 {
139+ out := composeFrame(state, cache, scratch)
140+ scratch, cache = cache, out.cache
141+ }
142+ reused := testing.AllocsPerRun(50, func() {
143+ out := composeFrame(state, cache, scratch)
144+ scratch, cache = cache, out.cache
145+ })
146+ // The baseline composes the same frame without scratch, so it clones the
147+ // base page every time. Reuse must save at least one full Clone.
148+ baseline := testing.AllocsPerRun(50, func() {
149+ benchmarkComposeSink.frame = composeFrame(state, cache, composeCacheInput{}).frame
150+ })
151+ cloned := testing.AllocsPerRun(50, func() { benchmarkComposeSink.frame = cache.frame.Clone() })
152+ require.Positive(t, cloned)
153+ require.LessOrEqual(t, reused, baseline-cloned, "scratch reuse must save at least one Clone (baseline=%v clone=%v)", baseline, cloned)
154+ out := composeFrame(state, cache, scratch)
155+ require.False(t, framesShareStorage(out.frame, out.cache.frame))
156+ require.Contains(t, frameText(out.frame), "copied")
157+ require.NotContains(t, frameText(out.cache.frame), "copied")
158+}
@@ -0,0 +1,158 @@
1+package daemon
2+
3+import (
4+ "testing"
5+
6+ renderer "github.com/bnema/vev-vt"
7+ "github.com/bnema/vev/internal/domain"
8+ "github.com/bnema/vev/internal/usecase/ui"
9+ "github.com/stretchr/testify/require"
10+)
11+
12+// framesShareStorage reports whether writing through a is visible through b.
13+func framesShareStorage(a, b renderer.Frame) bool {
14+ if a.Width <= 0 || a.Height <= 0 || b.Width != a.Width || b.Height != a.Height {
15+ return false
16+ }
17+ orig := a.Cell(0, 0)
18+ sentinel := renderer.Cell{Rune: '§', Style: renderer.DefaultStyle()}
19+ if orig.Equal(sentinel) {
20+ sentinel.Rune = '¶'
21+ }
22+ a.Set(0, 0, sentinel)
23+ shared := b.Cell(0, 0).Equal(sentinel)
24+ a.Set(0, 0, orig)
25+ return shared
26+}
27+
28+func transientToastFloatingState(withToast, withFloating, withModal bool, seed rune) capturedRenderState {
29+ var notices []domain.Notification
30+ if withToast {
31+ notices = []domain.Notification{{Code: domain.NoticeClipboard, Severity: domain.NoticeInfo, Message: "copied", Count: 1}}
32+ }
33+ state := toastDamageState(notices, []renderer.Damage{{Kind: renderer.DamageText, X: 0, Y: 0, Width: 1, Height: 1}}, false)
34+ state.panes[0].frame.Set(0, 0, renderer.Cell{Rune: seed, Style: renderer.DefaultStyle()})
35+ if withFloating {
36+ content := domain.Rect{Y: 1, Width: 80, Height: 20}
37+ geometry := calculateContentFloatingGeometry(domain.Size{Cols: content.Width, Rows: content.Height}, domain.FloatingConfig{Width: 60, Height: 60})
38+ state.floating = capturedFloatingRenderState{
39+ visible: true,
40+ pane: capturedPaneRenderState{frame: renderer.NewFrame(geometry.Inner.Width, geometry.Inner.Height), title: "float"},
41+ geometry: geometry,
42+ title: "float",
43+ generation: 1,
44+ }
45+ }
46+ if withModal {
47+ // A modal without toast or floating is the second writer of the
48+ // overlay transient page.
49+ state.overlays.promptActive = true
50+ state.overlays.prompt = capturedModal{
51+ active: true,
52+ title: "Prompt",
53+ presentation: ui.Presentation{
54+ Bounds: domain.Rect{X: 10, Y: 5, Width: 20, Height: 3},
55+ Inner: domain.Rect{X: 11, Y: 6, Width: 18, Height: 1},
56+ Borders: ui.BorderAll,
57+ },
58+ }
59+ }
60+ return state
61+}
62+
63+// TestComposeFrameTransientScratchNeverAliasesCaches replays the attachment
64+// commit/spare rotation across toast, floating, modal, and plain frames, and
65+// across failed publications that compose again without committing. Each result
66+// must match an independent composition without scratch, the retained cache
67+// must stay toast-free, and no handed-out frame may share a page with either
68+// cache slot (which would let a later paint corrupt committed state).
69+func TestComposeFrameTransientScratchNeverAliasesCaches(t *testing.T) {
70+ type step struct {
71+ toast, floating, modal bool
72+ // failed skips commitComposition, as a failed prepare or send does, so
73+ // the next step composes again from the same spare.
74+ failed bool
75+ }
76+ steps := []step{
77+ {}, {toast: true}, {toast: true}, {toast: true, floating: true}, {floating: true},
78+ {modal: true}, {modal: true, failed: true}, {modal: true}, {toast: true, modal: true},
79+ {toast: true, floating: true, failed: true}, {toast: true, floating: true}, {toast: true},
80+ {}, {toast: true, failed: true}, {toast: true}, {floating: true}, {toast: true, floating: true},
81+ }
82+ var render attachmentRenderState
83+ for i, st := range steps {
84+ seed := rune('A' + i)
85+ state := transientToastFloatingState(st.toast, st.floating, st.modal, seed)
86+ state.reset = i == 0
87+ // A frame without scratch is the reference: it only ever clones.
88+ want := composeFrame(state, render.cache)
89+ got := composeFrame(state, render.cache, render.spare)
90+
91+ require.Equal(t, frameRows(want.frame), frameRows(got.frame), "step %d frame", i)
92+ require.Equal(t, frameRows(want.cache.frame), frameRows(got.cache.frame), "step %d cache", i)
93+ require.Equal(t, want.damage, got.damage, "step %d damage", i)
94+
95+ // The result is built in the spare page, so it may share that one, but it
96+ // must never touch the committed cache a failed publication falls back to.
97+ require.False(t, framesShareStorage(got.frame, render.cache.frame), "step %d: composed frame aliases the committed cache", i)
98+ require.False(t, framesShareStorage(got.cache.frame, render.cache.frame), "step %d: new cache base aliases the committed cache", i)
99+ if st.toast || st.floating || st.modal {
100+ // A decorated frame lives on a transient page: never the cache base
101+ // (toast-free by contract) nor the committed or spare cache pages.
102+ require.False(t, framesShareStorage(got.frame, got.cache.frame), "step %d: decorated frame aliases the cache base", i)
103+ require.False(t, framesShareStorage(got.frame, render.spare.frame), "step %d: decorated frame aliases the spare cache", i)
104+ }
105+ require.NotContains(t, frameText(got.cache.frame), "copied", "step %d: cache must stay toast-free", i)
106+
107+ if st.failed {
108+ continue
109+ }
110+ beforeCommitted := frameRows(render.cache.frame)
111+ render.commitComposition(got.cache)
112+ if i > 0 {
113+ require.Equal(t, beforeCommitted, frameRows(render.spare.frame))
114+ }
115+ // The two slots' transient pages must be distinct from each other, from
116+ // both cache frames, and from every frame the next composition reads.
117+ pages := []renderer.Frame{render.cache.transient.overlay, render.cache.transient.popup, render.spare.transient.overlay, render.spare.transient.popup}
118+ for a := range pages {
119+ for b := a + 1; b < len(pages); b++ {
120+ require.False(t, framesShareStorage(pages[a], pages[b]), "step %d: transient pages %d and %d alias", i, a, b)
121+ }
122+ require.False(t, framesShareStorage(pages[a], render.cache.frame), "step %d: transient page %d aliases cache", i, a)
123+ require.False(t, framesShareStorage(pages[a], render.spare.frame), "step %d: transient page %d aliases spare", i, a)
124+ }
125+ }
126+}
127+
128+// TestComposeFrameStableToastReusesScratchPages pins the saving: with a primed
129+// scratch, a stable toast frame no longer clones the base page.
130+func TestComposeFrameStableToastReusesScratchPages(t *testing.T) {
131+ base := composeFrame(toastDamageState(nil, nil, true), composeCacheInput{})
132+ notice := []domain.Notification{{Code: domain.NoticeClipboard, Severity: domain.NoticeInfo, Message: "copied", Count: 1}}
133+ shown := composeFrame(toastDamageState(notice, nil, false), base.cache, composeCacheInput{})
134+ state := toastDamageState(notice, []renderer.Damage{{Kind: renderer.DamageText, X: 0, Y: 0, Width: 1, Height: 1}}, false)
135+
136+ cache, scratch := shown.cache, base.cache
137+ // Prime both rotation slots so every page has reached its steady size.
138+ for range 3 {
139+ out := composeFrame(state, cache, scratch)
140+ scratch, cache = cache, out.cache
141+ }
142+ reused := testing.AllocsPerRun(50, func() {
143+ out := composeFrame(state, cache, scratch)
144+ scratch, cache = cache, out.cache
145+ })
146+ // The baseline composes the same frame without scratch, so it clones the
147+ // base page every time. Reuse must save at least one full Clone.
148+ baseline := testing.AllocsPerRun(50, func() {
149+ benchmarkComposeSink.frame = composeFrame(state, cache, composeCacheInput{}).frame
150+ })
151+ cloned := testing.AllocsPerRun(50, func() { benchmarkComposeSink.frame = cache.frame.Clone() })
152+ require.Positive(t, cloned)
153+ require.LessOrEqual(t, reused, baseline-cloned, "scratch reuse must save at least one Clone (baseline=%v clone=%v)", baseline, cloned)
154+ out := composeFrame(state, cache, scratch)
155+ require.False(t, framesShareStorage(out.frame, out.cache.frame))
156+ require.Contains(t, frameText(out.frame), "copied")
157+ require.NotContains(t, frameText(out.cache.frame), "copied")
158+}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 12

Tags 11

↑↓ moveenter openesc close