Skip to content
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

chore(serverless): lazy load slow package imports #8994

Merged
merged 10 commits into from
Apr 24, 2024

Conversation

purple4reina
Copy link
Contributor

@purple4reina purple4reina commented Apr 15, 2024

Lazy loads

  • logging.handlers
  • multiprocessing
  • email.mime.application
  • email.mime.multipart

All of which are slow to import and not needed when run in aws lambda. This improves cold start time.

Also, updates tests to ensure the code is not accidentally updated in the future to import these packages.

Checklist

  • Change(s) are motivated and described in the PR description
  • Testing strategy is described if automated tests are not included in the PR
  • Risks are described (performance impact, potential for breakage, maintainability)
  • Change is maintainable (easy to change, telemetry, documentation)
  • Library release note guidelines are followed or label changelog/no-changelog is set
  • Documentation is included (in-code, generated user docs, public corp docs)
  • Backport labels are set (if applicable)
  • If this PR changes the public interface, I've notified @DataDog/apm-tees.

Reviewer Checklist

  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Description motivates each change
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Change is maintainable (easy to change, telemetry, documentation)
  • Release note makes sense to a user of the library
  • Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

@duncanista duncanista added the changelog/no-changelog A changelog entry is not required for this PR. label Apr 17, 2024
@duncanista duncanista changed the title chore(serverless): lazy load slow package imports. chore(serverless): lazy load slow package imports Apr 17, 2024
@pr-commenter
Copy link

pr-commenter bot commented Apr 17, 2024

Benchmarks

Benchmark execution time: 2024-04-24 09:20:48

Comparing candidate commit aa8ecaa in PR branch rey.abolofia/lazy-import with baseline commit 704aac0 in branch main.

Found 49 performance improvements and 5 performance regressions! Performance is the same for 147 metrics, 9 unstable metrics.

scenario:coreapiscenario-context_with_data_listeners

  • 🟩 max_rss_usage [-1.370MB; -1.288MB] or [-6.233%; -5.860%]

scenario:coreapiscenario-context_with_data_listeners_and_all_listeners

  • 🟩 max_rss_usage [-674.006KB; -594.116KB] or [-3.060%; -2.697%]

scenario:coreapiscenario-context_with_data_no_listeners

  • 🟩 max_rss_usage [-646.049KB; -570.463KB] or [-2.944%; -2.600%]

scenario:coreapiscenario-core_dispatch_listeners

  • 🟩 max_rss_usage [-717.767KB; -634.732KB] or [-3.266%; -2.888%]

scenario:coreapiscenario-core_dispatch_listeners_and_all_listeners

  • 🟩 max_rss_usage [-685.712KB; -605.347KB] or [-3.121%; -2.755%]

scenario:coreapiscenario-core_dispatch_no_listeners

  • 🟩 max_rss_usage [-1.363MB; -1.291MB] or [-6.209%; -5.881%]

scenario:coreapiscenario-core_dispatch_only_all_listeners

  • 🟩 max_rss_usage [-661.772KB; -586.280KB] or [-3.013%; -2.669%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • 🟥 max_rss_usage [+478.842KB; +558.265KB] or [+2.298%; +2.679%]

scenario:coreapiscenario-core_dispatch_with_results_listeners_and_all_listeners

  • 🟩 max_rss_usage [-650.901KB; -483.282KB] or [-3.062%; -2.274%]

scenario:coreapiscenario-core_dispatch_with_results_no_listeners

  • 🟩 max_rss_usage [-706.733KB; -632.249KB] or [-3.217%; -2.878%]

scenario:coreapiscenario-core_dispatch_with_results_only_all_listeners

  • 🟩 max_rss_usage [-644.260KB; -564.060KB] or [-2.931%; -2.566%]

scenario:coreapiscenario-get_item_exists

  • 🟩 max_rss_usage [-737.835KB; -658.081KB] or [-3.356%; -2.993%]

scenario:coreapiscenario-get_item_missing

  • 🟩 max_rss_usage [-719.150KB; -646.047KB] or [-3.273%; -2.940%]

scenario:coreapiscenario-set_item

  • 🟩 max_rss_usage [-689.235KB; -610.426KB] or [-3.140%; -2.781%]

scenario:httppropagationextract-all_styles_all_headers

  • 🟩 max_rss_usage [-921.729KB; -678.578KB] or [-4.201%; -3.093%]

scenario:httppropagationextract-empty_headers

  • 🟩 max_rss_usage [-678.370KB; -611.461KB] or [-3.093%; -2.788%]

scenario:httppropagationextract-full_t_id_datadog_headers

  • 🟩 max_rss_usage [-652.736KB; -573.197KB] or [-2.980%; -2.617%]

scenario:httppropagationextract-invalid_priority_header

  • 🟩 max_rss_usage [-641.949KB; -562.275KB] or [-2.927%; -2.564%]

scenario:httppropagationextract-invalid_span_id_header

  • 🟩 max_rss_usage [-777.920KB; -699.507KB] or [-3.647%; -3.279%]

scenario:httppropagationextract-invalid_trace_id_header

  • 🟩 max_rss_usage [-606.859KB; -521.179KB] or [-2.776%; -2.384%]

scenario:httppropagationextract-large_valid_headers_all

  • 🟩 max_rss_usage [-798.062KB; -647.007KB] or [-3.736%; -3.029%]

scenario:httppropagationextract-medium_valid_headers_all

  • 🟩 max_rss_usage [-740.729KB; -657.236KB] or [-3.475%; -3.083%]

scenario:httppropagationextract-tracecontext_headers

  • 🟩 max_rss_usage [-673.146KB; -594.976KB] or [-3.069%; -2.713%]

scenario:httppropagationextract-valid_headers_all

  • 🟩 max_rss_usage [-868.673KB; -632.920KB] or [-3.958%; -2.884%]

scenario:httppropagationextract-valid_headers_basic

  • 🟩 max_rss_usage [-641.250KB; -565.431KB] or [-2.927%; -2.581%]

scenario:httppropagationextract-wsgi_valid_headers_all

  • 🟩 max_rss_usage [-729.264KB; -642.896KB] or [-3.423%; -3.018%]

scenario:httppropagationextract-wsgi_valid_headers_basic

  • 🟩 max_rss_usage [-671.143KB; -592.882KB] or [-3.064%; -2.707%]

scenario:httppropagationinject-ids_only

  • 🟩 max_rss_usage [-1.299MB; -1.247MB] or [-5.954%; -5.717%]

scenario:httppropagationinject-with_all

  • 🟩 max_rss_usage [-610.294KB; -553.380KB] or [-2.792%; -2.532%]

scenario:httppropagationinject-with_dd_origin

  • 🟩 max_rss_usage [-629.382KB; -575.252KB] or [-2.883%; -2.635%]

scenario:httppropagationinject-with_priority_and_origin

  • 🟩 max_rss_usage [-622.287KB; -577.841KB] or [-2.848%; -2.645%]

scenario:httppropagationinject-with_sampling_priority

  • 🟩 max_rss_usage [-634.660KB; -580.213KB] or [-2.903%; -2.654%]

scenario:httppropagationinject-with_tags

  • 🟩 max_rss_usage [-647.557KB; -586.158KB] or [-2.961%; -2.680%]

scenario:httppropagationinject-with_tags_invalid

  • 🟩 max_rss_usage [-628.381KB; -579.529KB] or [-2.877%; -2.653%]

scenario:otelspan-add-metrics

  • 🟥 max_rss_usage [+897.315KB; +973.737KB] or [+2.528%; +2.743%]

scenario:otelspan-add-tags

  • 🟥 max_rss_usage [+885.510KB; +965.472KB] or [+2.489%; +2.713%]

scenario:otelspan-start-finish

  • 🟩 max_rss_usage [-1.603MB; -1.528MB] or [-6.906%; -6.586%]

scenario:otelspan-start-finish-telemetry

  • 🟩 max_rss_usage [-664.390KB; -595.130KB] or [-2.864%; -2.565%]

scenario:samplingrules-average_match

  • 🟩 max_rss_usage [-1121.474KB; -780.708KB] or [-5.122%; -3.566%]

scenario:samplingrules-high_match

  • 🟩 max_rss_usage [-1153.542KB; -813.357KB] or [-5.274%; -3.718%]

scenario:samplingrules-very_low_match

  • 🟩 max_rss_usage [-1070.507KB; -748.527KB] or [-4.263%; -2.981%]

scenario:sethttpmeta-all-disabled

  • 🟩 max_rss_usage [-794.268KB; -557.412KB] or [-3.686%; -2.587%]

scenario:sethttpmeta-all-enabled

  • 🟩 max_rss_usage [-1022.243KB; -702.583KB] or [-4.706%; -3.234%]

scenario:sethttpmeta-collectipvariant_exists

  • 🟩 max_rss_usage [-1037.551KB; -719.633KB] or [-4.766%; -3.306%]

scenario:sethttpmeta-no-useragentvariant

  • 🟩 max_rss_usage [-1151.859KB; -811.764KB] or [-5.264%; -3.710%]

scenario:sethttpmeta-obfuscation-regular-case-explicit-query

  • 🟩 max_rss_usage [-1070.866KB; -787.899KB] or [-4.833%; -3.556%]

scenario:sethttpmeta-obfuscation-worst-case-explicit-query

  • 🟩 max_rss_usage [-789.159KB; -707.929KB] or [-3.509%; -3.147%]

scenario:span-add-metrics

  • 🟥 max_rss_usage [+1.231MB; +1.309MB] or [+2.295%; +2.441%]

scenario:span-add-tags

  • 🟩 max_rss_usage [-1.970MB; -1.894MB] or [-6.133%; -5.897%]

scenario:span-start

  • 🟩 max_rss_usage [-1.834MB; -1.538MB] or [-4.390%; -3.681%]

scenario:span-start-finish-telemetry

  • 🟩 max_rss_usage [-1.227MB; -1.152MB] or [-5.585%; -5.247%]

scenario:span-start-finish-traceid128

  • 🟩 max_rss_usage [-1.259MB; -1.185MB] or [-5.721%; -5.384%]

scenario:span-start-traceid128

  • 🟩 max_rss_usage [-1.569MB; -1.439MB] or [-3.722%; -3.413%]

scenario:tracer-large

  • 🟥 max_rss_usage [+531.321KB; +599.994KB] or [+2.426%; +2.739%]

@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented Apr 22, 2024

Datadog Report

Branch report: rey.abolofia/lazy-import
Commit report: fee10a3
Test service: dd-trace-py

✅ 0 Failed, 122855 Passed, 50391 Skipped, 3h 39m 23.18s Total duration (6h 51m 24.2s time saved)

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 7.23%. Comparing base (02e3932) to head (011863a).
Report is 1 commits behind head on main.

Files Patch % Lines
ddtrace/internal/utils/http.py 0.00% 2 Missing ⚠️
tests/internal/test_serverless.py 0.00% 2 Missing ⚠️
ddtrace/_logger.py 0.00% 1 Missing ⚠️
ddtrace/internal/compat.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #8994       +/-   ##
===========================================
- Coverage   78.61%    7.23%   -71.38%     
===========================================
  Files        1254     1224       -30     
  Lines      117600   115821     -1779     
===========================================
- Hits        92447     8376    -84071     
- Misses      25153   107445    +82292     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@purple4reina purple4reina enabled auto-merge (squash) April 24, 2024 17:22
@purple4reina purple4reina merged commit 5478ea5 into main Apr 24, 2024
158 of 159 checks passed
@purple4reina purple4reina deleted the rey.abolofia/lazy-import branch April 24, 2024 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog A changelog entry is not required for this PR. serverless
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants