Skip to content

Perf: cache dashboard HTML template at package init#136

Merged
dmabry merged 1 commit into
mainfrom
feature/dashboard-template-cache
May 15, 2026
Merged

Perf: cache dashboard HTML template at package init#136
dmabry merged 1 commit into
mainfrom
feature/dashboard-template-cache

Conversation

@dmabry
Copy link
Copy Markdown
Owner

@dmabry dmabry commented May 15, 2026

Summary

The dashboard HTML template was parsed on every single HTTP request via template.New().Funcs().Parse() — unnecessary CPU and allocation overhead.

Move template parsing to a package-level variable initialized once at startup. DashboardHandler now reuses the pre-parsed template.

Changes

  • Added dashboardTmpl package-level variable with init-time parsing
  • DashboardHandler calls dashboardTmpl.Execute() directly — no per-request parsing
  • Parse failure logs a [WARN] at init and returns an empty template (server still starts)
  • Simplified error handling — removed nested if err block

Verified

  • go build
  • go vet ./...
  • go test -v ./stats/ -count 1 ✅ All passing
  • go test -race ./... ✅ No races detected

The dashboard template was parsed on every HTTP request via
template.New().Funcs().Parse() — unnecessary CPU and allocation overhead.

Move template parsing to a package-level variable initialized once at
startup. DashboardHandler now reuses the pre-parsed template.

Also simplified error handling: parse failure logs a warning at init
time and returns an empty template (server still starts); execute
failures log per-request as before.
@dmabry dmabry merged commit 22ce5c1 into main May 15, 2026
3 checks passed
@dmabry dmabry deleted the feature/dashboard-template-cache branch May 15, 2026 21:35
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.

1 participant