Skip to content

Conversation

@CybotTM
Copy link
Contributor

@CybotTM CybotTM commented Jan 21, 2026

Summary

Adds caching layers for frequently accessed rendering operations to improve performance.

Changes

  • SluggerAnchorNormalizer: Cache slugger instance and normalization results
  • TwigTemplateRenderer: Cache Twig globals across render calls
  • PreNodeRendererFactory: Cache renderer lookups by class name
  • TwigEnvironment: Cache template by path
  • RenderContext: O(1) document lookup via hash map
  • DocumentNameResolver: Cache URL resolution results
  • UrlGenerator: Cache URL generation results
  • ExternalReferenceResolver: O(1) hash set lookup for URI schemes (~6x faster than regex)

Performance Impact

See Performance Analysis Report for detailed benchmarks.


Related PRs

PR Description Status
#1287 This PR - Rendering caching layer
#1288 RST parsing optimizations Independent
#1289 CLI container caching Independent
#1290 DocumentEntryNode identity refactoring Independent
#1292 ProjectNode O(1) document lookup Independent

All PRs can be merged independently in any order.

@CybotTM CybotTM force-pushed the perf/caching-improvements branch 4 times, most recently from d2f2cfa to 0fd7a3e Compare January 22, 2026 00:51
@CybotTM CybotTM changed the title perf: Add caching layer for frequently accessed operations perf: Add caching layer for rendering operations Jan 22, 2026
@CybotTM CybotTM force-pushed the perf/caching-improvements branch 2 times, most recently from ee3b8de to 55158bb Compare January 22, 2026 01:22
Add instance and result caching for hot paths in the rendering pipeline:

- ProjectNode: cache root document entry with O(1) lookup, add fast-path
  to getDocumentEntry(), lazy cache invalidation in setDocumentEntries()
- DocumentNode: add hasDocumentEntry() helper for safe checks
- RenderContext: use hash map for O(1) document lookup by file path,
  optimize withDocument() to clone directly instead of rebuilding
- DocumentNameResolver: cache URI analysis and resolved paths
- ExternalReferenceResolver: pre-compile schema regex pattern
- SluggerAnchorNormalizer: cache slugger instance and normalization results
- AbstractUrlGenerator: cache isRelativePath() checks
- RelativeUrlGenerator: cache computed relative paths
- PreNodeRendererFactory: cache renderer lookups by node class
- TwigEnvironmentBuilder: enable filesystem template caching
- TwigTemplateRenderer: cache global context to avoid redundant addGlobal()

See https://cybottm.github.io/render-guides/ for benchmark data.
@CybotTM CybotTM force-pushed the perf/caching-improvements branch from 55158bb to 44a9023 Compare January 22, 2026 01:31
CybotTM added a commit to CybotTM/guides that referenced this pull request Jan 22, 2026
Add SUPPORTED_SCHEMAS_LIST and isSupportedScheme() to ExternalReferenceResolver
for O(1) hash set lookup instead of regex matching against 371 IANA schemes.
This is ~6x faster than the 5600+ character regex pattern.

InlineLexer now uses ExternalReferenceResolver::isSupportedScheme() to
validate URI schemes during tokenization.

Note: This change is also in PR phpDocumentor#1287 - when both PRs merge, the conflict
is trivially resolved by keeping one version.
@CybotTM CybotTM force-pushed the perf/caching-improvements branch 2 times, most recently from e2bd863 to 44a9023 Compare January 22, 2026 19:09
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