-
-
Notifications
You must be signed in to change notification settings - Fork 904
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
Apparent memory leak when duping DocumentFragment #1063
Comments
Also seen on ruby 1.9.3p448 and nokogiri 1.6.0. Second program (calls parse()) prints Valgrind results: Successful program (calls parse()): |
Some notes:
|
OK, this is because Suggestion: we could implement |
I've addressed this in MRI by copying nodes directly to the new Document. However, I'm having trouble with the java implementation. WIP is on branch Moved this into the 1.8.3 milestone, sorry for the delay. |
OK - I've got a second branch up in which I punt on trying to implement this optimization in the JRuby implementaiton. branch is |
…ment-fragment-attempt-2 fix #1063: poor memory performance when `dup`ing DocumentFragment
Back in b92660e (#1834 fixing #1063) I omitted support in JRuby for the "new_parent_document" argument to `Node#dup` because there was no performance reason to implement it. So the test was skipped. However, in 1e7d38a and other commits in #3117 (fixing #316), I introduced a call to `initialize_copy_with_args` that passes the new parent document as an argument on both CRuby and JRuby implementations. Because the test was skipped, I didn't catch that this broke on JRuby. In particular this was a problem for Loofah which relies on decorators, and even more particularly this broke the `Loofah::TextBehavior` formatting concern for `Loofah::*::DocumentFragment` objects. Maybe we should be running downstream tests with JRuby, too? But that feels like a big investment right now so I'll avoid scarring on the first cut, and wait to see if it happens again.
Back in b92660e (#1834 fixing #1063) I omitted support in JRuby for the "new_parent_document" argument to `Node#dup` because there was no performance reason to implement it. So the test was skipped. However, in 1e7d38a and other commits in #3117 (fixing #316), I introduced a call to `initialize_copy_with_args` that passes the new parent document as an argument on both CRuby and JRuby implementations. Because the test was skipped, I didn't catch that this broke on JRuby. In particular this was a problem for Loofah which relies on decorators, and even more particularly this broke the `Loofah::TextBehavior` formatting concern for `Loofah::*::DocumentFragment` objects. Maybe we should be running downstream tests with JRuby, too? But that feels like a big investment right now so I'll avoid scarring on the first cut, and wait to see if it happens again. (cherry picked from commit dda0be2)
**What problem is this PR intended to solve?** Back in b92660e (#1834 fixing #1063) I omitted support in JRuby for the "new_parent_document" argument to `Node#dup` because there was no performance reason to implement it. So the test was skipped. However, in 1e7d38a and other commits in #3117 (fixing #316), I introduced a call to `initialize_copy_with_args` that passes the new parent document as an argument on both CRuby and JRuby implementations. Because the test was skipped, I didn't catch that this broke on JRuby. In particular this was a problem for Loofah which relies on decorators, and even more particularly this broke the `Loofah::TextBehavior` formatting concern for `Loofah::*::DocumentFragment` objects. **Have you included adequate test coverage?** The skipped test is no longer skipped! Maybe we should be running downstream tests with JRuby, too? But that feels like a big investment right now so I'll avoid scarring on the first cut, and wait to see if it happens again. **Does this change affect the behavior of either the C or the Java implementations?** Brings the Java impl into agreement with the C impl.
Ruby 2.1, Nokogiri 1.6.1
Title explains the issue I'm seeing. Here's a simple case to reproduce:
Memory usage goes from 11.9KB to 18.7KB. The contents of the fragment do not seem to matter but the bigger the fragment the bigger the leak (ran it with a large fragment and it peaked at > 1GB).
Having trouble with valgrind on OSX so unable to provide that analysis. It should be clear there's a problem if you run it. Compare to this example, which does not continue to eat up memory (from 11.12KB to 11.16KB):
Happy to provide more info if necessary.
The text was updated successfully, but these errors were encountered: