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
Memoize exception_lines in ExceptionPresenter #2743
Conversation
Do you mind checking the build failure? |
Looking here https://travis-ci.org/github/rspec/rspec-core/branches, i believe the problem is on master, and not a result of my changes. |
@MaxLap |
Apologies, I checked again it is failing with the same error. However this cannot be merged until it is green. |
Master is green if you want to rebase this |
The method failure_lines uses exception_lines 3 times, which uses exception.message. In some situation, exception.message can be slow (when inspect is called on a big object for example). Without caching, this delay which can become considerable will be amplified by 3x.
All green :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Don't forget to add a changelog entry. No change is too small.
Memoize exception_lines in ExceptionPresenter
When an exception occurs and is displayed,
ExceptionPresenter
is used. However, there is an obvious slow amplification doing in it. This PR fixes it.The method
failure_lines
usesexception_lines
3 times, which usesexception.message
. In some situation,exception.message
can be slow (when inspect is called on a big object for example, such as during NoMethodError).Without caching, this delay, which can become considerable, will be amplified by 3x.
Here is a simple example of an rspec that would be amplified
Instead of taking 1 second, the print of the failure message takes 3 seconds.
I did memoization (
@exception_lines ||= ...
), but the call result could have been saved and reused in the failure_lines method. Let me know if you prefer that i change it to just startfailure_lines
withexception_lines = self.exception_lines
.As a side note, I think it would be helpful if the
--profile
or a new flag would help debug slow failures messages (top 10 of slowest failures to display).