render: parse the layout and partials once, clone per page
CI's race step failed twice on 17f91cf: internal/home passed go test's 10-minute limit. v0.38.0's partials are bigger (signin.html doubled), and newRenderer parsed the layout, rastrillo's partials and estilo's once per page (34 pages) in every App a test builds; template parsing was a third of the CPU in a profile of the slowest tests. newRenderer now parses the layout and every shared partial once and clones that tree for each page before parsing the page itself. door and hop are set per clone (Clone copies the function map, so each page's are its own; checked per page by a throwaway probe). Pages still parse at boot, so a broken template is still a boot failure. Locally, internal/home under -race fell from 362 s to 148 s, and without -race from 55 s to 31 s. No gate or timeout changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+46
−25
AGENTS.md+7 −0internal/home/render.go+39 −25
CI passed — run details
CI log
amadan: .amadan/timeout: this job's budget is 20m0s (this runner allows up to 30m0s) === vet === CGO_ENABLED=0 go vet ./... CGO_ENABLED=0 go vet -tags browser ./internal/home/ cd handoff && CGO_ENABLED=0 go vet ./... cd roster && CGO_ENABLED=0 go vet ./... cd dashboard && CGO_ENABLED=0 go vet ./... cd connect && CGO_ENABLED=0 go vet ./... cd teammode && CGO_ENABLED=0 go vet ./... === fmt === === build === CGO_ENABLED=0 go build ./... CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ./cmd/home ./cmd/oficina ./internal/operatorlaunch cd handoff && CGO_ENABLED=0 go build ./... cd roster && CGO_ENABLED=0 go build ./... cd dashboard && CGO_ENABLED=0 go build ./... cd connect && CGO_ENABLED=0 go build ./... cd teammode && CGO_ENABLED=0 go build ./... === go-test === CGO_ENABLED=0 go test -count=1 ./... ? amadan.net/oficina/home/cmd/home [no test files] ok amadan.net/oficina/home/cmd/home-placeholder 0.680s ? amadan.net/oficina/home/cmd/oficina [no test files] ok amadan.net/oficina/home/internal/guardstest 0.060s ok amadan.net/oficina/home/internal/home 50.911s ok amadan.net/oficina/home/internal/home/directorydata 1.363s ok amadan.net/oficina/home/internal/home/logtest 0.003s ok amadan.net/oficina/home/internal/home/seal 0.002s ok amadan.net/oficina/home/internal/home/sealtest 0.003s ok amadan.net/oficina/home/internal/home/wisp 0.041s ok amadan.net/oficina/home/internal/operator 6.379s ok amadan.net/oficina/home/internal/operatorlaunch 4.106s ok amadan.net/oficina/home/internal/provisioner 48.869s cd handoff && CGO_ENABLED=0 go test -count=1 ./... ok amadan.net/oficina/home/handoff 0.656s ok amadan.net/oficina/home/handoff/seal 0.002s cd roster && CGO_ENABLED=0 go test -count=1 ./... ok amadan.net/oficina/home/roster 5.117s cd dashboard && CGO_ENABLED=0 go test ./... ok amadan.net/oficina/home/dashboard (cached) cd connect && CGO_ENABLED=0 go test -count=1 ./... ok amadan.net/oficina/home/connect 1.335s ok amadan.net/oficina/home/connect/linkstore 0.459s cd teammode && CGO_ENABLED=0 go test -count=1 ./... ok amadan.net/oficina/home/teammode 0.096s ? amadan.net/oficina/home/teammode/teammodetest [no test files] === race === go test -race -count=1 ./internal/home/ ./internal/operator/ ./internal/operatorlaunch/ ./internal/home/directorydata/ ok amadan.net/oficina/home/internal/home 310.815s ok amadan.net/oficina/home/internal/operator 82.154s ok amadan.net/oficina/home/internal/operatorlaunch 22.379s ok amadan.net/oficina/home/internal/home/directorydata 23.285s ok amadan.net/oficina/home/internal/provisioner 394.527s cd handoff && CGO_ENABLED=1 go test -race -count=1 ./... ok amadan.net/oficina/home/handoff 12.696s ok amadan.net/oficina/home/handoff/seal 1.013s cd roster && CGO_ENABLED=1 go test -race -count=1 ./... ok amadan.net/oficina/home/roster 6.944s cd dashboard && CGO_ENABLED=1 go test -race -count=1 ./... ok amadan.net/oficina/home/dashboard 1.062s cd connect && CGO_ENABLED=1 go test -race -count=1 ./... ok amadan.net/oficina/home/connect 5.844s ok amadan.net/oficina/home/connect/linkstore 6.277s cd teammode && CGO_ENABLED=1 go test -race -count=1 ./... ok amadan.net/oficina/home/teammode 1.906s ? amadan.net/oficina/home/teammode/teammodetest [no test files]
diff --git a/AGENTS.md b/AGENTS.md| index 600af3a..a60dc95 100644 |
| --- a/AGENTS.md |
| +++ b/AGENTS.md |
| @@ -381,6 +381,13 @@ quietly ignored). |
| are all `TestVendoredAssetsMatchTheLibrary` checks, so a moved |
| fallback passes here: re-check fallbacks in estilo on every bump |
| (estilo AGENTS.md, Theme). Credits regenerated (`make credits`). |
| + v0.38.0's partials are bigger (`signin.html` doubled), and the |
| + renderer parsed every partial once per page, in every App the tests |
| + build: CI's race run of `internal/home` passed `go test`'s 10-minute |
| + limit twice. `newRenderer` now parses the layout and the partials once |
| + and clones that tree per page (each clone carries its own `door` and |
| + `hop`); the race run fell from about 360 s to 150 s here. Keep it |
| + that way rather than raising the timeout. |
| - **No script by default; script only to enhance, and always prefer |
| none** (Paul, 2026-09-29, replacing rulings 21/24's closed list of |
| screens). Every screen works with scripts off — magic-link sign-in, |
diff --git a/internal/home/render.go b/internal/home/render.go| index 072d526..e5e645d 100644 |
| --- a/internal/home/render.go |
| +++ b/internal/home/render.go |
| @@ -40,6 +40,39 @@ func newRenderer() (*renderer, error) { |
| if err != nil { |
| return nil, err |
| } |
| + // The layout and the shared partials (rastrillo's, then estilo's) |
| + // are parsed once and cloned for each page: they are most of the |
| + // bytes, and parsing them once per page made every App construction |
| + // cost a re-parse of rastrillo's partials per page (34 of them). |
| + // ui.Funcs supplies the helpers rastrillo's partials call — "T" |
| + // among them — so the tree must carry them before those partials |
| + // are parsed, not after. "door" and "hop" are placeholders here, so |
| + // the layout parses; each page's clone sets its own below, and a |
| + // clone's functions are its own (template.Clone copies the map). |
| + base, err := template.New("layout.html").Funcs(ui.Funcs()).Funcs(homeFuncs).Funcs(template.FuncMap{ |
| + "door": func() bool { return false }, |
| + "hop": func() bool { return false }, |
| + }).ParseFS(templatesFS, layoutFile) |
| + if err != nil { |
| + return nil, fmt.Errorf("parse %s: %w", layoutFile, err) |
| + } |
| + if base, err = base.ParseFS(ui.Templates(), "*.html"); err != nil { |
| + return nil, fmt.Errorf("parse rastrillo partials: %w", err) |
| + } |
| + if base, err = base.ParseFS(credits.Templates(), "templates/*.html"); err != nil { |
| + return nil, fmt.Errorf("parse credits partials: %w", err) |
| + } |
| + if base, err = base.ParseFS(sky.Templates(), "templates/*.html"); err != nil { |
| + return nil, fmt.Errorf("parse sky partials: %w", err) |
| + } |
| + // The shared chrome: the bar, the account menu, the door and the |
| + // error page (chrome.go). |
| + if base, err = base.ParseFS(menu.Templates(), "templates/*.html"); err != nil { |
| + return nil, fmt.Errorf("parse menu partials: %w", err) |
| + } |
| + if base, err = base.ParseFS(chrome.Templates(), "templates/*.html"); err != nil { |
| + return nil, fmt.Errorf("parse chrome partials: %w", err) |
| + } |
| r := &renderer{pages: make(map[string]*template.Template, len(files))} |
| for _, f := range files { |
| name := path.Base(f) |
| @@ -49,34 +82,15 @@ func newRenderer() (*renderer, error) { |
| // The layout first, then rastrillo's partials, then the page — |
| // so a page may use a partial, and a page redefining a block |
| // wins over the layout's default. |
| - // ui.Funcs supplies the helpers rastrillo's partials call — |
| - // "T" among them — so the tree must carry them before those |
| - // partials are parsed, not after. |
| isDoor, isHop := doorPages[name], hopPages[name] |
| - t, err := template.New(name).Funcs(ui.Funcs()).Funcs(homeFuncs).Funcs(template.FuncMap{ |
| - "door": func() bool { return isDoor }, |
| - "hop": func() bool { return isHop }, |
| - }).ParseFS(templatesFS, layoutFile) |
| + t, err := base.Clone() |
| if err != nil { |
| - return nil, fmt.Errorf("parse %s: %w", layoutFile, err) |
| - } |
| - if t, err = t.ParseFS(ui.Templates(), "*.html"); err != nil { |
| - return nil, fmt.Errorf("parse rastrillo partials: %w", err) |
| - } |
| - if t, err = t.ParseFS(credits.Templates(), "templates/*.html"); err != nil { |
| - return nil, fmt.Errorf("parse credits partials: %w", err) |
| - } |
| - if t, err = t.ParseFS(sky.Templates(), "templates/*.html"); err != nil { |
| - return nil, fmt.Errorf("parse sky partials: %w", err) |
| - } |
| - // The shared chrome: the bar, the account menu, the door and the |
| - // error page (chrome.go). |
| - if t, err = t.ParseFS(menu.Templates(), "templates/*.html"); err != nil { |
| - return nil, fmt.Errorf("parse menu partials: %w", err) |
| - } |
| - if t, err = t.ParseFS(chrome.Templates(), "templates/*.html"); err != nil { |
| - return nil, fmt.Errorf("parse chrome partials: %w", err) |
| + return nil, fmt.Errorf("clone for %s: %w", f, err) |
| } |
| + t.Funcs(template.FuncMap{ |
| + "door": func() bool { return isDoor }, |
| + "hop": func() bool { return isHop }, |
| + }) |
| if t, err = t.ParseFS(templatesFS, f); err != nil { |
| return nil, fmt.Errorf("parse %s: %w", f, err) |
| } |