Skip to content

Conversation

@CybotTM
Copy link
Contributor

@CybotTM CybotTM commented Jan 23, 2026

Summary

Introduces CachingEnvironmentBuilder that replaces EnvironmentBuilder to enable Twig's built-in template caching, avoiding template recompilation on every render.

Features

  • Filesystem template caching: Compiled templates stored for reuse
  • Auto-reload: Templates recompiled when source changes (development-friendly)
  • Configurable cache directory: Defaults to system temp directory
  • Debug mode support: Optional debug extension and strict mode

Performance Impact

~25% template rendering improvement by eliminating redundant template compilation.

Technical Details

  • Decorator pattern: CachingEnvironmentBuilder replaces EnvironmentBuilder
  • PHP 8.1 compatible
  • Cache location: {sys_temp_dir}/typo3-guides-twig-cache/
  • Uses Twig's native caching mechanism

Part of Performance Initiative

This is Phase 1.3 of the performance optimization initiative tracked in #1143.

Related PRs:

  • #1152 - Inventory caching (Phase 1.1)
  • #1153 - AST caching (Phase 1.2)

Upstream dependencies (phpdocumentor/guides):

  • #1287 - DocumentEntryNode file path method
  • #1288 - DocumentEntryNode isRoot flag
  • #1289 - ProjectNode find method
  • #1293 - O(1) document lookup optimization

Test plan

  • Run render on documentation project
  • Verify Twig cache directory created in temp
  • Modify template file and verify recompilation
  • Leave templates unchanged and verify cache hit (check no recompile)

Introduces CachingEnvironmentBuilder that replaces EnvironmentBuilder with:
- Twig's built-in filesystem template caching
- Auto-reload for template changes during development
- Configurable cache directory (defaults to system temp)
- ~25% template rendering improvement

Templates are compiled once and reused across renders.
PHP 8.1 compatible.
- Remove unused EnvironmentBuilder import
- Use PHP 8.1 octal notation (0o755)
@CybotTM
Copy link
Contributor Author

CybotTM commented Jan 23, 2026

Closing due to integration issues. The upstream EnvironmentBuilder is marked 'final' so it cannot be extended for decoration. Twig caching requires either an upstream change to EnvironmentBuilder or a different approach (event listener or Symfony twig bundle configuration).

@CybotTM CybotTM closed this Jan 23, 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