v0.3.0 99dc266

transport_benchmark_test.go RawHistoryFolder

1package ipc
2
3import (
4	"encoding/binary"
5	"io"
6	"net"
7	"testing"
8	"time"
9
10	"github.com/bnema/vev/internal/ports"
11)
12
13func BenchmarkTransportSend(b *testing.B) {
14	conn := discardConn{}
15	tr := NewTransport(conn)
16	payload := []byte("payload payload payload")
17	frame := ports.Frame{Type: ports.MsgOutput, Payload: payload}
18
19	b.ReportAllocs()
20	for b.Loop() {
21		if err := tr.Send(frame); err != nil {
22			b.Fatal(err)
23		}
24	}
25}
26
27func BenchmarkTransportRecvReuse(b *testing.B) {
28	payload := []byte("payload payload payload")
29	encoded := encodeBenchmarkFrame(ports.Frame{Type: ports.MsgOutput, Payload: payload})
30	recv := &unixTransport{conn: &loopingReaderConn{data: encoded}}
31
32	b.ReportAllocs()
33	for b.Loop() {
34		if _, err := recv.Recv(); err != nil {
35			b.Fatal(err)
36		}
37	}
38}
39
40func encodeBenchmarkFrame(f ports.Frame) []byte {
41	n := 1 + len(f.Payload)
42	buf := make([]byte, frameHeaderLen+n)
43	binary.BigEndian.PutUint32(buf[:frameHeaderLen], uint32(n))
44	buf[frameHeaderLen] = byte(f.Type)
45	copy(buf[frameHeaderLen+1:], f.Payload)
46	return buf
47}
48
49type loopingReaderConn struct {
50	data []byte
51	off  int
52}
53
54func (c *loopingReaderConn) Read(p []byte) (int, error) {
55	if len(c.data) == 0 {
56		return 0, io.EOF
57	}
58	for i := range p {
59		p[i] = c.data[c.off]
60		c.off = (c.off + 1) % len(c.data)
61	}
62	return len(p), nil
63}
64
65func (c *loopingReaderConn) Write([]byte) (int, error) { return 0, io.ErrClosedPipe }
66func (c *loopingReaderConn) Close() error              { return nil }
67func (c *loopingReaderConn) LocalAddr() net.Addr       { return nil }
68func (c *loopingReaderConn) RemoteAddr() net.Addr      { return nil }
69func (c *loopingReaderConn) SetDeadline(time.Time) error {
70	return nil
71}
72func (c *loopingReaderConn) SetReadDeadline(time.Time) error {
73	return nil
74}
75func (c *loopingReaderConn) SetWriteDeadline(time.Time) error {
76	return nil
77}
78
79type discardConn struct{}
80
81func (discardConn) Read([]byte) (int, error)         { return 0, io.ErrClosedPipe }
82func (discardConn) Write(p []byte) (int, error)      { return len(p), nil }
83func (discardConn) Close() error                     { return nil }
84func (discardConn) LocalAddr() net.Addr              { return nil }
85func (discardConn) RemoteAddr() net.Addr             { return nil }
86func (discardConn) SetDeadline(time.Time) error      { return nil }
87func (discardConn) SetReadDeadline(time.Time) error  { return nil }
88func (discardConn) SetWriteDeadline(time.Time) error { return nil }

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