Each poll of the Sessions list and of every stats range titled each of ~5000 gateway sessions with GatewayTitle, which made the recordings folder's name and Stat-ed it each time. With nothing recorded, as for most users, that was the whole cost: os.Stat 62 MB and gatewayDir 18 MB of 90 s of polls while an agent worked. GatewayTitler makes the folder's name and asks once, and gives "" with no work when nothing is recorded; gatewayListed takes it. GatewayTitle is GatewayTitler()(agent, id), for one session. Bench (mote, ~/r2278/full, hmw.sh second runs), e14 =bed604efb, e15 = this: GatewayTitle 81 MB -> gone, gatewayListed 100 -> 19 MB, polls 170 x 200 in both; total 2308 -> 2350 MB is the run-to-run band. TestGatewayTitlerAsksOnce: with nothing recorded a title makes 0 allocations; after a turn is recorded a titler made then finds what GatewayTitle finds. Broken by hand (Stat and the folder's name again per session): red. At 825db07aa onbed604efb(mote): gofmt clean; go vet -tags nogui ./internal/gui/ ./internal/sessions/ for linux, windows, darwin ok; go test ./internal/sessions/ ok; go test ./internal/gui/ -run 'Gateway|Sessions|Stats' ok.
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package sessions
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// A listing's titler asks once whether magpie recorded anything: with
|
|
// nothing recorded, each of its many sessions costs nothing, not a Stat and
|
|
// a folder name (#2278). Once something is recorded, a titler made after
|
|
// finds the title as GatewayTitle does.
|
|
func TestGatewayTitlerAsksOnce(t *testing.T) {
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
if _, err := os.Stat(gatewayDir()); err == nil {
|
|
t.Fatal("a fresh config folder has recordings")
|
|
}
|
|
title := GatewayTitler()
|
|
if n := testing.AllocsPerRun(100, func() { _ = title("pi", "ses_1") }); n != 0 {
|
|
t.Fatalf("a session's title with nothing recorded made %v allocations", n)
|
|
}
|
|
if err := SetGatewayRecording(true, false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
turn := GatewayTurn{Agent: "pi", Session: "ses_1", Time: time.Now().UTC(),
|
|
Input: []Part{{Role: "user", Kind: "text", Text: "Deploy the staging server"}}}
|
|
if err := SaveGatewayTurn(turn); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
title = GatewayTitler()
|
|
if got := title("pi", "ses_1"); got != "Deploy the staging server" || got != GatewayTitle("pi", "ses_1") {
|
|
t.Fatalf("titler's title %q, GatewayTitle's %q", got, GatewayTitle("pi", "ses_1"))
|
|
}
|
|
if got := title("pi", "ses_2"); got != "" {
|
|
t.Fatalf("another session's title %q", got)
|
|
}
|
|
}
|