Skip to content
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

jruby improvements + weaker xpath caching #1597

Closed
wants to merge 31 commits into from

Conversation

kares
Copy link
Contributor

@kares kares commented Jan 31, 2017

managed to run into more common problems such as cloning non-cloneable (Java) objects.
a bit ugly pattern in general but for the rest of Ruby object cloning it would need a justification.

further I realized some xpath problems :

this is now avoided (such expressions always create a new xpath context) - they are less common.
xpath(expr) still caches as before, but I realized the cache makes xpath() not thread-safe #1596

UPDATE: also added a fix for #1440 (also resolves #1281 which is a duplicate - had the same cause)

@flavorjones
Copy link
Member

Thank you for submitting this, @kares!

Can you please rebase this off current master? It doesn't have 92768e0 in it, so the CI pipeline is failing when testing against libxml system libraries. See https://ci.nokogiri.org/teams/nokogiri-core/pipelines/nokogiri/jobs/ruby-2.4-system-pr/builds/3 for specifics.

no need for a synchronized Hashtable here; size will be 4 99% of time
... loading reflectively makes no sense since the class is already
loaded as its part of the method's signature (return type)
has been introduced before the xalan .jars where packed with the gem
it was only necessary due changing Java version - no longer the case!
... from JRuby's RubyHash API so that we avoid all is1_9() checks
... much safer to reason about AND REVEALED SOME INTERNAL ISSUES !
... also re-format code spacing to match rest of the file
... (temporarily) removed the existing caching mechanism
we now make sure to only cache xpaths without binds or custom handlers
... it has been disabled in previous commit(s)
... since there's logic everywhere dealing with the case

also do NOT initialize nodes with newEmptyArray and than append to it
... to potentially save one piece of (char[]) array copy-ing
(incl. previous commits) causes notably less garbage generation!
also faster due re-using a thread-cached encoder (resolves sparklemotion#1440)
@kares
Copy link
Contributor Author

kares commented Feb 10, 2017

rebased and all 💚 now ... thanks for the feedback.
hoping this will also get into 1.7.1 but take your time if you need to reviewing this.

numbers show that doc parsing is ~ 10% faster + xpath has gone 2x faster in some of the cases I tested.

@flavorjones
Copy link
Member

Yep, about to merge! Just writing CHANGELOG entries now.

Thanks so much!

@flavorjones
Copy link
Member

Merged manually.

thumbs-up-simon-pegg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xpath function returning an int fails under jruby RuntimeError when calling to_s with jruby
2 participants