Skip to content

perf(templates): cache parsed templates keyed by mtime#575

Closed
KrisSimon wants to merge 2 commits intomainfrom
migrate-stub-pr
Closed

perf(templates): cache parsed templates keyed by mtime#575
KrisSimon wants to merge 2 commits intomainfrom
migrate-stub-pr

Conversation

@KrisSimon
Copy link
Copy Markdown
Member

Migrated from GitLab MR !179 (merged)
perf/cache-template-parse-160main
Originally created: 2026-03-19
Merged: 2026-03-22
Author: Kris Simon
Labels: next

Summary

  • Every render/renderAndTrack call previously read the template file from disk and re-parsed it on every invocation — wasteful in tight render loops (e.g. TUI refreshing 10×/s)
  • Added ParseCache actor inside AROTemplateService storing ParsedTemplate objects keyed by file path
  • Embedded/registered templates are cached unconditionally (set-once semantics, never change)
  • File-system templates are validated by mtime: re-parsed only when the file changes on disk; otherwise the cached ParsedTemplate is returned immediately
  • Both render() and renderAndTrack() share the new loadAndParse() helper — cache is always warmed regardless of which path is taken

Closes #160

Test plan

  • swift build passes cleanly
  • All 1319 tests pass (swift test)
  • 5 new TemplateParseCacheTests cover: first render caches, mtime invalidation, path-keying across multiple templates, registered template caching, renderAndTrack cache hit

@KrisSimon KrisSimon closed this Apr 10, 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.

1 participant