-
Notifications
You must be signed in to change notification settings - Fork 314
Lazy load packages in compat for faster import. #881
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
Merged
Merged
Conversation
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
491f090 to
1c6fbe4
Compare
f728511 to
d604177
Compare
73548c1 to
9779c89
Compare
1c3dd7f to
695624a
Compare
695624a to
a2d8793
Compare
ddrthall
approved these changes
Jan 10, 2025
jack-edmonds-dd
approved these changes
Jan 10, 2025
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.
Requirements for Contributing to this repository
What does this PR do?
Lazy load all import statements in
datadog.utils.compat, cutting down time toimport datadogfrom ~64ms to ~34ms.Description of the Change
In serverless environments like AWS Lambda, the time it takes to import packages is important. On a "cold start" (first invocation on a new container) the caller must wait around for all code to initialize and for their request to be handled.
Customers care a lot about their cold start times in AWS Lambda in particular.
Alternate Designs
Possible Drawbacks
Patching the sys module in this way can be risky. All these imports need to be thoroughly tested.
Verification Process
Before this change, it took 25.6ms to import the
datadog.utils.compatmodule, which is imported every timedatadogis imported.After this change, it now takes 1.19ms to import the same
datadog.utls.compatmodule.Additional Notes
Release Notes
Review checklist (to be filled by reviewers)
changelog/label attached. If applicable it should have thebackward-incompatiblelabel attached.do-not-merge/label attached.kind/andseverity/labels attached at least.