Skip to content

perf: speed up script reading with shared Jinja env and YAML cache#192

Merged
MaxHalford merged 1 commit into
mainfrom
perf/jinja-caching
May 5, 2026
Merged

perf: speed up script reading with shared Jinja env and YAML cache#192
MaxHalford merged 1 commit into
mainfrom
perf/jinja-caching

Conversation

@MaxHalford
Copy link
Copy Markdown
Member

Summary

  • Share a single jinja2.Environment across all .sql.jinja files instead of creating a new one per file
  • Cache load_yaml results so the same YAML files aren't re-parsed on every template render (102 calls → 17 unique files)
  • Extract _make_jinja_environment() helper that encapsulates both optimizations

Before: ~1.9s for lea run --select foo (warm cache)
After: ~0.75s — a 2.5x speedup

The Jinja rendering alone went from ~1850ms to ~314ms for 42 templates.

Test plan

  • All 71 existing tests pass
  • Benchmarked with real project (264 table scripts, 42 jinja templates)

🤖 Generated with Claude Code

A new jinja2.Environment + FileSystemLoader was created for every .sql.jinja
file, and load_yaml re-parsed the same YAML files on every call (102 calls
for only 17 unique files). This extracts a shared _make_jinja_environment()
with an in-memory YAML cache, cutting Jinja rendering from ~1.9s to ~0.3s
for 42 templates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@MaxHalford MaxHalford merged commit 2a41d71 into main May 5, 2026
2 checks passed
@MaxHalford MaxHalford deleted the perf/jinja-caching branch May 5, 2026 22:21
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