perf: cache rendered index HTML with sync.Once#560
Closed
sam-saffron-jarvis wants to merge 1 commit intoSamSaffron:mainfrom
Closed
perf: cache rendered index HTML with sync.Once#560sam-saffron-jarvis wants to merge 1 commit intoSamSaffron:mainfrom
sam-saffron-jarvis wants to merge 1 commit intoSamSaffron:mainfrom
Conversation
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.
Owner
|
Closing as superseded by merged #547, which includes rendered index HTML caching plus the related static asset caching work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Wrap
renderIndexHTML()insync.Onceso 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:basePath, asset version, sidebar config, and optional VAPID/WebRTC snippets into JSONbytes.ReplaceAllcalls over the 19 KB template to inject versioned asset URLsAll inputs are fixed at server startup:
cfg.basePath,cfg.sidebarSessions— set once from flags/configserveui.AssetVersion()— already uses its ownsync.OncecfgRef.Serve.WebPush.VAPIDPublicKey,webrtcHeadSnippet— set at startupThe output is therefore identical on every call. Caching it eliminates repeated string manipulation and allocations on every page load.
Notes
Follows the same
xOnce/xFieldpattern already used byresponseRunsOnce/responseRunsinserveServer.