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

Optimize Python import to make CLI entrypoint faster #1182

Merged

Conversation

vinnamkim
Copy link
Contributor

@vinnamkim vinnamkim commented Oct 23, 2023

Summary

  • Ticket no. 123365
  • Revise the lazy plugin extra deps checking logic not to import them actually, but just checking their specs (existence).
  • Force Environment._get_plugin_exports() not to load classes under datumaro.components.*.
  • Introduce datumaro.util.import_util.lazy_import() to import some heavy external modules (e.g., tensorflow, matplotlib, ...) lazily.
  • Please see the following results:
  1. Before (develop)
(datumaro) (base) vinnamki@vinnamki-mobl:~/datumaro$ time datum -h
...

real    0m11.991s
user    0m11.268s
sys     0m1.906s
  1. After (This PR)
(datumaro) (base) vinnamki@vinnamki-mobl:~/datumaro$ time datum -h
...

real    0m1.086s
user    0m1.154s
sys     0m0.751s

How to test

Our existing tests can cover this.

Checklist

  • I have added unit tests to cover my changes.​
  • I have added integration tests to cover my changes.​
  • I have added the description of my changes into CHANGELOG.​
  • I have updated the documentation accordingly

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below).
# Copyright (C) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT

Signed-off-by: Kim, Vinnam <[email protected]>
@vinnamkim vinnamkim added the ENHANCE Enhancement of existing features label Oct 23, 2023
@vinnamkim vinnamkim added this to the 1.6.0 milestone Oct 23, 2023
@vinnamkim vinnamkim marked this pull request as ready for review October 23, 2023 06:50
@vinnamkim vinnamkim requested review from a team as code owners October 23, 2023 06:50
@vinnamkim vinnamkim requested review from sooahleex and removed request for a team October 23, 2023 06:50
@vinnamkim vinnamkim changed the title Optimize Python import to make CLI entrypoint faster [WIP] Optimize Python import to make CLI entrypoint faster Oct 23, 2023
@wonjuleee wonjuleee self-requested a review October 23, 2023 07:26
@vinnamkim vinnamkim closed this Oct 23, 2023
@vinnamkim vinnamkim reopened this Oct 23, 2023
@vinnamkim vinnamkim changed the title [WIP] Optimize Python import to make CLI entrypoint faster Optimize Python import to make CLI entrypoint faster Oct 23, 2023
@vinnamkim vinnamkim closed this Oct 23, 2023
@vinnamkim vinnamkim reopened this Oct 23, 2023
@codecov
Copy link

codecov bot commented Oct 23, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (c20dc3e) 80.09% compared to head (8a87f7c) 80.06%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1182      +/-   ##
===========================================
- Coverage    80.09%   80.06%   -0.04%     
===========================================
  Files          267      268       +1     
  Lines        29828    29849      +21     
  Branches      5846     5847       +1     
===========================================
+ Hits         23892    23898       +6     
- Misses        4602     4618      +16     
+ Partials      1334     1333       -1     
Flag Coverage Δ
macos-11_Python-3.8 79.18% <93.67%> (-0.04%) ⬇️
ubuntu-20.04_Python-3.8 80.06% <97.46%> (-0.03%) ⬇️
windows-2022_Python-3.8 80.03% <97.46%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/datumaro/cli/util/compare.py 20.08% <100.00%> (+0.08%) ⬆️
...o/components/algorithms/hash_key_inference/base.py 84.00% <100.00%> (+0.66%) ⬆️
...ms/noisy_label_detection/loss_dynamics_analyzer.py 84.94% <100.00%> (ø)
src/datumaro/components/environment.py 85.77% <100.00%> (ø)
src/datumaro/components/extractor_tfds.py 95.08% <100.00%> (+1.15%) ⬆️
src/datumaro/components/lazy_plugin.py 91.83% <100.00%> (+0.34%) ⬆️
src/datumaro/components/media.py 79.70% <100.00%> (+0.02%) ⬆️
src/datumaro/components/project.py 79.26% <100.00%> (+0.01%) ⬆️
src/datumaro/components/shift_analyzer.py 91.12% <100.00%> (+0.07%) ⬆️
src/datumaro/components/visualizer.py 88.84% <100.00%> (+0.12%) ⬆️
... and 6 more

... and 2 files with indirect coverage changes

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

Copy link
Contributor

@wonjuleee wonjuleee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good. Thank you for your efforts.

@vinnamkim vinnamkim merged commit b163010 into openvinotoolkit:develop Oct 24, 2023
6 checks passed
@vinnamkim vinnamkim deleted the enhance/lazy-plugin-import-v2 branch October 24, 2023 02:03
@yunchu yunchu modified the milestones: 1.6.0, 2.0.0 Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ENHANCE Enhancement of existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants