sentry-php icon indicating copy to clipboard operation
sentry-php copied to clipboard

\Sentry\ErrorHandler::handleError slow performance when notices thrown

Open joelbarnard opened this issue 1 year ago • 3 comments

How do you use Sentry?

Sentry SaaS (sentry.io)

SDK version

3.6.0

Steps to reproduce

We have PHP notices disabled via error_reporting, and Sentry init error_types.

We have code that generates notices in a large loop (over 650k iterations). This code is taking a large performance hit from \Sentry\ErrorHandler::handleError as it appears to be trying to process the notices, before ultimately ignoring them.

Expected result

If PHP error_reporting says to ignore notices, then don't incur performance hit from notices.

Actual result

Increased time of our function by about 25%

joelbarnard avatar May 01 '24 21:05 joelbarnard

@stayallive can you take a look please?

cleptric avatar May 02 '24 14:05 cleptric

It does look like we can improve here, our ErrorHandler is doing more work then needed because it has no access to the SDK options to know what it can skip. We could basically skip all this work:

https://github.com/getsentry/sentry-php/blob/51cec5c6ee768a71cfdd4d4316528c381172c62d/src/ErrorHandler.php#L329-L339

I'm working on a way to make the ErrorHandler somehow aware of the configured error_types but it is a bit tricky because of the singleton and not wanting to make any backwards incompatible changes.

stayallive avatar May 03 '24 19:05 stayallive

Please note that you are on version 3.6.0 and if we make any changes this will only be released in the latest release so you'd need to upgrade to 4.x (4.7.0 is the latest of today). Possibly an update to 4.x will already help a bit in your situation and it would be good to know the issue still persists if you upgrade to 4.x!

stayallive avatar May 03 '24 19:05 stayallive