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

Generating diffs of large objects consumes enough CPU to freeze the average computer #773

Closed
wants to merge 1 commit into from

Conversation

JonRowe
Copy link
Member

@JonRowe JonRowe commented Apr 16, 2015

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 or rspec script.rb. If you're using a laptop you'll want to take it off your lap and plug in the charger first.

@yorickpeterse yorickpeterse changed the title Generating diffs of large documents consumes enough CPU to freeze the average computer Generating diffs of large objects consumes enough CPU to freeze the average computer Apr 15, 2015
@JonRowe
Copy link
Member

JonRowe commented Apr 15, 2015

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

@yorickpeterse
Copy link
Author

@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.

@JonRowe
Copy link
Member

JonRowe commented Apr 16, 2015

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...

@JonRowe
Copy link
Member

JonRowe commented Apr 16, 2015

Let's see what Travis does..

@yorickpeterse
Copy link
Author

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.

@JonRowe
Copy link
Member

JonRowe commented Apr 16, 2015

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.

@JonRowe
Copy link
Member

JonRowe commented Apr 16, 2015

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.

@JonRowe
Copy link
Member

JonRowe commented Apr 16, 2015

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.

@JonRowe
Copy link
Member

JonRowe commented Apr 16, 2015

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)

@JonRowe JonRowe closed this Apr 16, 2015
@JonRowe JonRowe deleted the test_file_diffs branch April 16, 2015 23:41
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.

None yet

2 participants