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/protocol/wire"
11)
12
13func BenchmarkTransportSend(b *testing.B) {
14	conn := discardConn{}
15	tr := NewTransport(conn)
16	payload := []byte("payload payload payload")
17	envelope := wire.Envelope{Payload: payload}
18
19	b.ReportAllocs()
20	for b.Loop() {
21		if err := tr.Send(envelope); err != nil {
22			b.Fatal(err)
23		}
24	}
25}
26
27func BenchmarkTransportRecvReuse(b *testing.B) {
28	payload := []byte("payload payload payload")
29	encoded := encodeBenchmarkFrame(wire.Envelope{Payload: payload})
30	recv := NewTransport(&loopingReaderConn{data: encoded})
31	b.Cleanup(func() { _ = recv.Close() })
32
33	b.ReportAllocs()
34	for b.Loop() {
35		if _, err := recv.Recv(); err != nil {
36			b.Fatal(err)
37		}
38	}
39}
40
41// frameHeaderLen is the 4-byte big-endian length prefix; envelopes carry no
42// legacy type byte.
43const frameHeaderLen = 4
44
45func encodeBenchmarkFrame(e wire.Envelope) []byte {
46	buf := make([]byte, frameHeaderLen+len(e.Payload))
47	binary.BigEndian.PutUint32(buf[:frameHeaderLen], uint32(len(e.Payload)))
48	copy(buf[frameHeaderLen:], e.Payload)
49	return buf
50}
51
52type loopingReaderConn struct {
53	data []byte
54	off  int
55}
56
57func (c *loopingReaderConn) Read(p []byte) (int, error) {
58	if len(c.data) == 0 {
59		return 0, io.EOF
60	}
61	for i := range p {
62		p[i] = c.data[c.off]
63		c.off = (c.off + 1) % len(c.data)
64	}
65	return len(p), nil
66}
67
68func (c *loopingReaderConn) Write([]byte) (int, error) { return 0, io.ErrClosedPipe }
69func (c *loopingReaderConn) Close() error              { return nil }
70func (c *loopingReaderConn) LocalAddr() net.Addr       { return nil }
71func (c *loopingReaderConn) RemoteAddr() net.Addr      { return nil }
72func (c *loopingReaderConn) SetDeadline(time.Time) error {
73	return nil
74}
75func (c *loopingReaderConn) SetReadDeadline(time.Time) error {
76	return nil
77}
78func (c *loopingReaderConn) SetWriteDeadline(time.Time) error {
79	return nil
80}
81
82type discardConn struct{}
83
84func (discardConn) Read([]byte) (int, error)         { return 0, io.ErrClosedPipe }
85func (discardConn) Write(p []byte) (int, error)      { return len(p), nil }
86func (discardConn) Close() error                     { return nil }
87func (discardConn) LocalAddr() net.Addr              { return nil }
88func (discardConn) RemoteAddr() net.Addr             { return nil }
89func (discardConn) SetDeadline(time.Time) error      { return nil }
90func (discardConn) SetReadDeadline(time.Time) error  { return nil }
91func (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