Skip to content

Conversation

@purple4reina
Copy link
Contributor

Requirements for Contributing to this repository

  • Fill out the template below. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • The pull request must only fix one issue, or add one feature, at the time.
  • The pull request must update the test suite to demonstrate the changed functionality.
  • After you create the pull request, all status checks must be pass before a maintainer reviews your contribution. For more details, please see CONTRIBUTING.

What does this PR do?

Lazy load all import statements in datadog.utils.compat, cutting down time to import datadog from ~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.compat module, which is imported every time datadog is imported.

Screenshot 2025-01-08 at 9 04 03 AM

After this change, it now takes 1.19ms to import the same datadog.utls.compat module.

Screenshot 2025-01-08 at 9 04 34 AM

Additional Notes

Release Notes

Review checklist (to be filled by reviewers)

  • Feature or bug fix MUST have appropriate tests (unit, integration, etc...)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have one changelog/ label attached. If applicable it should have the backward-incompatible label attached.
  • PR should not have do-not-merge/ label attached.
  • If Applicable, issue must have kind/ and severity/ labels attached at least.

@purple4reina purple4reina requested a review from a team as a code owner January 8, 2025 17:28
@purple4reina purple4reina requested a review from a team January 8, 2025 17:28
@purple4reina purple4reina added the changelog/Added Added features results into a minor version bump label Jan 8, 2025
@purple4reina purple4reina force-pushed the rey.abolofia/lazy-import branch 2 times, most recently from 491f090 to 1c6fbe4 Compare January 8, 2025 21:21
@purple4reina purple4reina force-pushed the rey.abolofia/lazy-import branch from f728511 to d604177 Compare January 8, 2025 22:02
@purple4reina purple4reina force-pushed the rey.abolofia/lazy-import branch from 73548c1 to 9779c89 Compare January 9, 2025 20:06
@purple4reina purple4reina changed the title Lazy import all packages in compat. Lazy load packages in compat for faster import. Jan 9, 2025
@purple4reina purple4reina force-pushed the rey.abolofia/lazy-import branch 2 times, most recently from 1c3dd7f to 695624a Compare January 9, 2025 22:29
@purple4reina purple4reina force-pushed the rey.abolofia/lazy-import branch from 695624a to a2d8793 Compare January 9, 2025 22:32
@purple4reina purple4reina merged commit a7a7594 into master Jan 13, 2025
10 checks passed
@purple4reina purple4reina deleted the rey.abolofia/lazy-import branch January 13, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Added Added features results into a minor version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants