-
-
Notifications
You must be signed in to change notification settings - Fork 395
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
Generating diffs of large objects consumes enough CPU to freeze the average computer #773
Conversation
FWIW this doesn't happen on my machine, Ruby 2.2.2, Nokogiri 1.6.6.2, OS X 10.10.3. The diff is produced in under a second (and your file is not that large it should diff/parse fine) which suggests that prehaps the issue here is your copy of nokogiri loading the data? Here's the output on my machine: https://gist.github.com/JonRowe/fa1723c71563e5d9cfbf |
@JonRowe I've tested this on two different computers, both running the same Linux distro and using the same version of Nokogiri (1.6.6.2). In both cases the pattern is the same. |
Hmm, so this could be an issue with libxml2 on linux then, as that would still be different... Or an issue with ruby on linux... |
Let's see what Travis does.. |
bca72c9
to
879c8bb
Compare
I'm not sure how that would be related. A colleague of mine ran the script on OS X and it produced the same pattern: it hangs while sucking up 100% CPU. They're also using Nokogiri 1.6.6.2. |
From memory, nokogiri bundles libxml2 in certain situations where it would be unavailable (e.g. OSX) but on linux it uses the platform library. This is the one key difference I can think of between OSX and linux that is causing this to fail for you. |
Hmm, no theres more to it. The autorun example actually doesn't blow up for me, but inserting it into RSpecs own spec suite does. |
Converting the nokogiri objects to string manually actually causes the spec to pass, converting them to their inspect output causes the spec to fail with a diff correctly. |
So the nokogiri document when pretty printed comes out closer to 50000 lines, and it's possible to replicate this standalone, closing in favour of rspec/rspec-support#196 (meaning thats where the issue lies and would need to be fixed) |
When certain expectations fail RSpec will try to generate diff of the expected and received values. Usually this works fine, except when those values are 6000 line long HTML documents parsed using Nokogiri (or any other operation using big objects). In such a case generating a diff will consume enough CPU usage to at least freeze my Macbook Pro, requiring a hard reboot to make it usable again.
Repro: https://gist.github.com/YorickPeterse/ff2919edb411d9b2689e
Save the script somewhere and run it using either
ruby script.rb
orrspec script.rb
. If you're using a laptop you'll want to take it off your lap and plug in the charger first.