Skip to content

perf: shallow clone instead of creating new empty xpath context + assigning #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ziluvatar
Copy link

I identified 2 performance degradations:

  • When a copy of a XPathContext is needed, new XPathContext() is created, which creates new resolvers for it, afterwards those are discarded and in favor of the context to be copied from. Out of these resolvers FunctionResolver creation was particularly more expensive than he others.
  • Individual checks for assigning fields in assign() function added performance overhead.

The solution I found for both was to:

  • Create a shallow cloning function (removing extend, I could leave it in code, unused, to keep public compatibility if needed), passing the available resolvers to the new context, which avoids the waste of their creation.
  • Manually assign the available fields in a context.

I added also the benchmark code I used for this, which provides this information:

  • For current 0.0.34: Benchmark completed in 4612.00 milliseconds for 100000 iterations.
  • For code in the PR: Benchmark completed in 1444.20 milliseconds for 100000 iterations. (3x times faster)

I can remove the benchmark file if needed, I thought it would be useful for future.

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