Skip to content

Lazy-load HTML templates#59

Merged
andrew merged 1 commit into
mainfrom
lazy-load-templates
Apr 6, 2026
Merged

Lazy-load HTML templates#59
andrew merged 1 commit into
mainfrom
lazy-load-templates

Conversation

@andrew

@andrew andrew commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Move template parsing from server startup into a sync.Once guarded load() method called on first Render(). API and proxy endpoints never touch templates, so they no longer pay the ~780µs startup cost.

NewTemplates() is replaced by a zero-value &Templates{}. Parsing happens once on the first HTML page request.

Benchmarks (before → after):

                 │   before    │            after             │
                 │   sec/op    │   sec/op    vs base          │
ServerCreate-8     736.1µ ± ∞    2.073n ± ∞  -100.00%
TemplatesParse-8   734.4µ ± ∞    783.3µ ± ∞       ~
FirstRender-8      947.3µ ± ∞    988.6µ ± ∞       ~

Closes #53

Templates are parsed on first Render call instead of at server startup.
API-only traffic never pays the ~780µs parsing cost.

Closes #53
@andrew andrew merged commit 34009ba into main Apr 6, 2026
5 checks passed
@andrew andrew deleted the lazy-load-templates branch April 6, 2026 12:06
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.

Lazy-load HTML templates

1 participant