perf: shallow clone instead of creating new empty xpath context + assigning #146
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I identified 2 performance degradations:
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 resolversFunctionResolver
creation was particularly more expensive than he others.assign()
function added performance overhead.The solution I found for both was to:
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.I added also the benchmark code I used for this, which provides this information:
Benchmark completed in 4612.00 milliseconds for 100000 iterations.
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.