Reduced slowdown with Stracktrace middleware#697
Closed
allanwhiteford wants to merge 1 commit intoplack:masterfrom
Closed
Reduced slowdown with Stracktrace middleware#697allanwhiteford wants to merge 1 commit intoplack:masterfrom
allanwhiteford wants to merge 1 commit intoplack:masterfrom
Conversation
During normal operation errors will be thrown and caught by various modules. e.g. Mason throws: Can't locate Mason/Plugin/DollarDot/Result.pm The Middleware doesn't display these but it still slows it down. Specifically, if the strack trace itself is large (either from being reasonably deep or because a lot of data are being moved around in it) then the logic that checks to display it first checks if there is a stracktrace and then if it should display it. However, checking for a stacktrace (when using Devel::Stracktrace) is expensive because, in effect, what looks like a boolean operation in the middleware is actually calling Devel::Stracktrace->as_string. This commit swaps the order of checking so that if we aren't going to use the stacktrace then we don't see if it's truthy (hence don't recurse down the structure making a string). The specific test case that caused this was pushing 32MB through a Mason/Plack request on the first request of the server. The Mason interpreter throws an error as it loads the template but since 32MB is being passed around the ->as_string call to the stacktrace is expensive (even though it is then ignored). This resulted in a 4.2s slowdown on an i7-1065G7 with laptop-spec RAM/disk etc.
Member
Huh, is that because Devel::StackTrace has overload for I guess this patch is simple enough but I wonder if it would be more readable to change it to |
Member
|
|
Author
|
Looks better to me as well, thank you! |
netbsd-srcmastr
pushed a commit
to NetBSD/pkgsrc
that referenced
this pull request
Jan 14, 2024
2.05 2024-01-08 - Added explicit boolean overloading for trace objects. Without this, Perl will use the object's string overloading and then check the truthiness of the returned string, which is a lot of extra work. This can produce significant slowdowns in some cases, as seen in plack/Plack#697. Requested by Tatsuhiko Miyagawa. GH #23.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
During normal operation errors will be thrown and caught by various modules. e.g. Mason throws:
Can't locate Mason/Plugin/DollarDot/Result.pm
The Middleware doesn't display these but it still slows it down.
Specifically, if the strack trace itself is large (either from being reasonably deep or because a lot of data are being moved around in it) then the logic that checks to display it first checks if there is a stracktrace and then if it should display it.
However, checking for a stacktrace (when using Devel::Stracktrace) is expensive because, in effect, what looks like a boolean operation in the middleware is actually calling Devel::Stracktrace->as_string.
This commit swaps the order of checking so that if we aren't going to use the stacktrace then we don't see if it's truthy (hence don't recurse down the structure making a string).
The specific test case that caused this was pushing 32MB through a Mason/Plack request on the first request of the server. The Mason interpreter throws an error as it loads the template but since 32MB is being passed around the ->as_string call to the stacktrace is expensive (even though it is then ignored). This resulted in a 4.2s slowdown on an i7-1065G7 with laptop-spec RAM/disk etc.