Skip to content

Lazy-load HTML templates#59

Open
andrew wants to merge 1 commit intomainfrom
lazy-load-templates
Open

Lazy-load HTML templates#59
andrew wants to merge 1 commit intomainfrom
lazy-load-templates

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented Apr 4, 2026

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
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