Skip to content

perf: cache rendered index HTML with sync.Once#560

Closed
sam-saffron-jarvis wants to merge 1 commit intoSamSaffron:mainfrom
sam-saffron-jarvis:feat/webui-cache-index-html
Closed

perf: cache rendered index HTML with sync.Once#560
sam-saffron-jarvis wants to merge 1 commit intoSamSaffron:mainfrom
sam-saffron-jarvis:feat/webui-cache-index-html

Conversation

@sam-saffron-jarvis
Copy link
Copy Markdown
Contributor

What

Wrap renderIndexHTML() in sync.Once so the rendered HTML is computed once and reused for every subsequent request.

Why

renderIndexHTML() rebuilds the same ~19 KB byte slice on every page navigation:

  • Marshals basePath, asset version, sidebar config, and optional VAPID/WebRTC snippets into JSON
  • Runs a table of ~12 bytes.ReplaceAll calls over the 19 KB template to inject versioned asset URLs

All inputs are fixed at server startup:

  • cfg.basePath, cfg.sidebarSessions — set once from flags/config
  • serveui.AssetVersion() — already uses its own sync.Once
  • cfgRef.Serve.WebPush.VAPIDPublicKey, webrtcHeadSnippet — set at startup

The output is therefore identical on every call. Caching it eliminates repeated string manipulation and allocations on every page load.

Notes

Follows the same xOnce/xField pattern already used by responseRunsOnce/responseRuns in serveServer.

renderIndexHTML() rebuilds the same ~19 KB byte slice on every page
navigation: it marshals the base path, asset version, sidebar config,
and optional VAPID/WebRTC snippets, then runs a table of string
replacements over the 19 KB template.  All inputs are fixed at server
startup (config is immutable, embedded asset hashes are computed once
via their own sync.Once), so the output is identical on every call.

Add indexHTMLOnce/indexHTMLBytes fields to serveServer and wrap the
rendering body in sync.Once so it runs exactly once.  Subsequent calls
return the cached slice with no allocation or string manipulation.
@SamSaffron
Copy link
Copy Markdown
Owner

Closing as superseded by merged #547, which includes rendered index HTML caching plus the related static asset caching work.

@SamSaffron SamSaffron closed this May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants