Skip to content

Memoize XPath function resolution in XPathAstCompiler - #8

Merged
ezkimo merged 2 commits into
mainfrom
issue-2-memoize_xpath_function_resulution
Oct 15, 2026
Merged

ezkimo merged 2 commits into
mainfrom
issue-2-memoize_xpath_function_resulution

Conversation

@ezkimo

@ezkimo ezkimo commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Summary

Every function node previously triggered a linear scan over all registered XPath function classes, calling supports() each time. This change resolves each function name at most once per compiler instance and caches both successful matches and misses.

Changes

  • src/Schematron/Compiler/XPathAstCompiler.php
    • Add instance memo map $resolvedFunctions (array<string, XPathFunctionInterface|null>)
    • Add resolveFunction(string $name) to perform and cache resolution
    • Update compileFunction() to use the resolver
    • Update compilePathStepFunction() to use the resolver
    • Cache null as a sentinal for names without a handler

Compatibility

  • Compiled PHP output remains unchanged for existing tests
  • Function resolution order is unchanged
  • Misses are cached, avoiding repeated full scans

Testing

  • Existing PHUnit suite passes (49 tests)
  • Recommended additional test:
    • Repeated compilation of the same function name resolves once
    • Unknown function names are cached as misses
    • Compiled output remains identical

@ezkimo
ezkimo merged commit 7292c74 into main Oct 15, 2026
1 check passed
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