Open kalyan-koneru opened 1 week ago
@kalyan-koneru thank you for the feedback.
First of all, when measuring the time it takes for the Sentry SDK to initialize, you should use time.process_time_ns()
rather than time.time()
.
The problem with time.time()
is that it measures the entire elapsed time of the SDK's initialization, including time where the process initializing the Sentry SDK is sleeping. On the other hand, time.process_time_ns()
excludes time when the process is sleeping. So, time.process_time_ns()
will give you a more accurate idea of how much time it actually takes the Sentry SDK to initialize.
I don't find it that surprising though that there is some delay to initializing the Sentry SDK. We need to do quite a bit of work to instrument your application properly with the SDK, so it is no surprise that this does add a delay.
Did you notice a sudden performance regression from a previous version of the Sentry SDK, or has it always been like this for you?
@szokeasaurusrex
Thank you for the clarification on using time.process_time_ns() to measure initialization time more accurately. We were indeed using time.time() and will switch to time.process_time_ns() to get a clearer view of the SDK's active processing time.
Regarding performance, we haven't specifically checked for regressions in the current version of the Sentry SDK. This issue came to our attention while investigating cold startup times in our Python application, where we observed the Sentry SDK initialization taking around 500ms. Do you consider this a reasonable performance expectation, or are there optimizations we could look into?
@kalyan-koneru Could you first try timing the import and initialization with time.process_time_ns()
?
It's hard to tell whether a 500ms duration measured with time.time()
is reasonable because the duration with time.time()
depends on many external factors that are specific to your system, and which could even vary between individual runs of the program.
How do you use Sentry?
Sentry Saas (sentry.io)
Version
2.18.0
Steps to Reproduce
While implementing a simple AWS Lambda function, I observed significant delays related to Sentry SDK initialization. Specifically:
These delays contribute to an increased cold start time for AWS Lambda functions, which could impact performance in latency-sensitive applications.
I have attached the lambda function I used to test the performance
Expected Result
Expect the sentry initialization time to be under 50ms
Actual Result
Sentry initialization time is over 500ms
Elapsed time import sentry_sdk: 304 ms Elapsed time sentry_sdk.init: 257 ms