gui: the history's warm-up starts with the app's page, not at start
sessionRoutes started warmSessions when the routes were made, so a magpie started at login, by `magpie tray`, or as `magpie web` with no page read every session's stats, the Requests page's whole history and Codex's effort for nobody. What those reads kept went two minutes later (statsIdle, requestIdle), so the reads were pure cost unless a window opened in those minutes. The warm-up now starts when the app's page is first served (GET / or /index.html, not mode=panel); the steady GC setting is still made with the routes. On Linux and Windows the main window is still made at start, so the warm-up runs there as before. Measured on mote with the real account's history (~15.6k sessions), the sandbox HOME at ~/r2278/acct, proxies to 127.0.0.1:9: - `tray` start, CPU in the first 30 s: w34 2.67 s, w35 0.96 / 1.04 s. - `web` with no page, at 150 s: footprint 104 -> 64 MB, live heap 62 -> 9 MB, CPU 2.52 -> 0.65 s. - normal launch (window shown): the warm-up still runs in the first 30 s (warmStart 0.84 s, warmStats 0.47 s, QueryPage 0.31 s), as on w34 (0.73 s). - `panel` start: no warm-up in the profile, 1.62 s CPU, no panic. Tests: TestWarmsSessions (app page, panel page, assets, HEAD), and -run 'TestWarmsSessions|TestPanelOnFirstOpen|TestMainOnFirstOpen|Warm|Cold' ./internal/gui ok on mica; go vet ./internal/gui and GOOS=windows go vet ./internal/gui ok. Not run: the full suite, the GUI suite (no page script changed), Linux GUI vet (no gtk4 dev packages in WSL). Not tried: a first Sessions page asked within seconds of opening the window after a hidden start; it takes turns with the warm-up (coldTurns), as a first start's window did before.
This commit is contained in:
+7
-1
@@ -1135,7 +1135,13 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
webPage.Store(true)
|
||||
}
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/", devPage(revalidated(http.FileServer(http.FS(staticFS())))))
|
||||
page := devPage(revalidated(http.FileServer(http.FS(staticFS()))))
|
||||
mux.Handle("/", http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
if warmsSessions(r) {
|
||||
warmSessions()
|
||||
}
|
||||
page.ServeHTTP(rw, r)
|
||||
}))
|
||||
devRoutes(mux)
|
||||
pluginPageRoutes(mux, isWeb(w))
|
||||
feedbackRoutes(mux)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package gui
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// A closed window's webview goes on the second look in a row that finds it
|
||||
// closed with lightweight mode on (#580), never while it is shown or the
|
||||
@@ -56,3 +59,24 @@ func TestMainOnFirstOpen(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The warm-up's read of the history starts with the app's page, never
|
||||
// with the tray panel's page or a file the page loads.
|
||||
func TestWarmsSessions(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
method, url string
|
||||
want bool
|
||||
}{
|
||||
{"GET", "/?theme=dark", true},
|
||||
{"GET", "/", true},
|
||||
{"GET", "/index.html", true},
|
||||
{"GET", "/?mode=panel&theme=dark", false},
|
||||
{"GET", "/app.js", false},
|
||||
{"HEAD", "/", false},
|
||||
} {
|
||||
r := httptest.NewRequest(c.method, c.url, nil)
|
||||
if got := warmsSessions(r); got != c.want {
|
||||
t.Errorf("%s %s: %v, want %v", c.method, c.url, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ func gatewaySession(g usage.GatewaySession) sessions.Session {
|
||||
}
|
||||
|
||||
func sessionRoutes(mux *http.ServeMux, w Windows) {
|
||||
warmSessions()
|
||||
steadyGC()
|
||||
mux.HandleFunc("GET /api/sessions", coldTurn(func(rw http.ResponseWriter, r *http.Request) {
|
||||
// the list and the Codex threads' effort each list every session file
|
||||
defer sessions.OneListing()()
|
||||
@@ -912,12 +912,18 @@ func withGatewaySessions(st sessions.Stats, days int, nativeKeys map[string]bool
|
||||
return sessions.MergeExternalStats(st, daily, ext)
|
||||
}
|
||||
|
||||
// warmSessions reads every session file once magpie is up, so the Sessions
|
||||
// page opens on the kept index and not on a first read of them all. Usage ›
|
||||
// Requests' whole history is read after it, not beside it on the disk: a
|
||||
// first All parsing 12k sessions kept that page a skeleton for 40 s.
|
||||
// Once a process: the app's page served to a browser (apppage.go) is a
|
||||
// second Handler beside the window's.
|
||||
// warmSessions reads every session file once the app's page is first
|
||||
// served, so the Sessions page opens on the kept index and not on a first
|
||||
// read of them all. Usage › Requests' whole history is read after it, not
|
||||
// beside it on the disk: a first All parsing 12k sessions kept that page a
|
||||
// skeleton for 40 s. Once a process: the app's page served to a browser
|
||||
// (apppage.go) is a second Handler beside the window's.
|
||||
//
|
||||
// Not at start: a magpie started at login, by `magpie tray` or as `magpie
|
||||
// web` with no page open read the history for nobody, ~0.6 s of CPU and a
|
||||
// rebuilt Requests index after an update, and what the reads kept went
|
||||
// two minutes later (statsIdle, requestIdle). The tray panel's page
|
||||
// doesn't start it: it shows neither page.
|
||||
func warmSessions() {
|
||||
if testing.Testing() {
|
||||
return
|
||||
@@ -925,10 +931,24 @@ func warmSessions() {
|
||||
warmOnce.Do(warmStart)
|
||||
}
|
||||
|
||||
var warmOnce sync.Once
|
||||
var warmOnce, steadyOnce sync.Once
|
||||
|
||||
// steadyGC is steadyGCStart, once a process and never in a test.
|
||||
func steadyGC() {
|
||||
if testing.Testing() {
|
||||
return
|
||||
}
|
||||
steadyOnce.Do(steadyGCStart)
|
||||
}
|
||||
|
||||
// warmsSessions tells the app's page from the panel's and from the files
|
||||
// it loads: the page that starts warmSessions.
|
||||
func warmsSessions(r *http.Request) bool {
|
||||
return r.Method == http.MethodGet && (r.URL.Path == "/" || r.URL.Path == "/index.html") && r.URL.Query().Get("mode") != "panel"
|
||||
}
|
||||
|
||||
func warmStart() {
|
||||
steadyGCStart()
|
||||
steadyGC()
|
||||
go func() {
|
||||
// a fresh install reads no agent's sessions until asked; one
|
||||
// that read them before keeps reading them (decided once)
|
||||
|
||||
Reference in New Issue
Block a user