Skip to content

Cache TemplateCaps.detect results with a bounded LRU #448

Description

@leehack

Context

PR #446 measured repeated Jinja capability detection and found that parsing dominates the cost: one explicit Lexer/Parser pass plus a second parse inside dinja Template construction, followed by four distinct render probes. The render probes cannot be collapsed because they exercise different payloads.

The redundant second parse cannot currently be removed without an upstream dinja API change; #351 tracks the broader private-source/upstream coupling. A bounded cache at the TemplateCaps.detect boundary would avoid both parses and all four renders when the same template is detected repeatedly.

Proposed work

  • Add a bounded LRU keyed by exact template source, with an explicit conservative capacity.
  • Preserve all current capability results and failure diagnostics from fix: label and log Jinja capability probe render failures #446.
  • Define cache ownership and invalidation behavior; do not introduce unbounded process-wide retention.
  • Add hit, miss, eviction, and failure-path regression tests.
  • Benchmark representative real templates before and after.

Boundary

This is a non-blocking performance improvement discovered during #446. It is not a prerequisite for the diagnostics fix or the next release.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority:P3Watch or strategic work blocked by upstream/runtime/design dependencies

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions