Skip to main content

Profile the import time of a module.

Project description

importfiler

Profile your imports, find what is dragging your module load time.

importfiler builds on top of the output generated by the interpreter -X importtime traces. It is just a different output targeted more at a specific use-case. Finding what modules impact the longest on a specific one you are trying to optimize.

If you need a more detailed result, check out py-spy or any other runtime profiler.

Getting dependencies import time

Given an import, shows the the time spent importing direct dependencies. The import time does include the time spent on importing other modules.

This helps you finding the most time consuming imports in your library/app.

Examples:

$ python -m importfiler requests
modules:            time(%)
------------------- --------
requests            100 %
urllib3             61 %
charset_normalizer  11 %
http.cookiejar      10 %
idna                2 %
certifi             2 %
http.cookies        1 %
zipfile             1 %

Getting the time in milliseconds:

$ python -m importfiler --unit=ms requests
modules:            time(ms)
------------------- ---------
requests            48 ms
urllib3             29 ms
charset_normalizer  5 ms
http.cookiejar      4 ms
idna                1 ms
certifi             1 ms

Getting all_modules import time

Given an import, shows the the time spent loading all its dependencies (including transitive). The import time does not include the time spent on importing other modules.

This helps you finding the most time consuming modules across your chain of dependencies.

Examples:

$ python -m importfiler --mode="all_modules" requests
modules:             time (%)             submodules
-------------------- -------------------- --------------------
urllib3              17 %                 urllib3.util.url, urllib3.packages.six, urllib3.exceptions, urllib3.poolmanager, ...
email                7 %                  email._policybase, email.message, email.header, email.feedparser, ...
charset_normalizer   6 %                  charset_normalizer.constant, charset_normalizer.models, charset_normalizer.cd, ...
requests             6 %                  requests.utils, requests.models, requests.exceptions, requests.packages, ...
http                 6 %                  http.cookiejar, http.client, http.cookies
urllib               4 %                  urllib.request, urllib.parse, urllib.error, urllib.response
typing               3 %
ssl                  2 %
importlib            2 %                  importlib.resources._adapters, importlib.resources.abc, importlib.resources._common, ...
re                   2 %                  re._parser, re._compiler, re._constants, re._casefix

Getting the time in milliseconds:

$ python -m importfiler --mode="all_modules" --unit=ms requests
modules:             time (ms)            submodules
-------------------- -------------------- --------------------
urllib3              18 ms                urllib3.util.url, urllib3.packages.six, urllib3.exceptions, urllib3.connectionpool, ...
charset_normalizer   8 ms                 charset_normalizer.md__mypyc, charset_normalizer.constant, charset_normalizer.models, ...
requests             7 ms                 requests.utils, requests.exceptions, requests.models, requests.packages, ...
email                3 ms                 email._policybase, email.header, email.feedparser, email.utils, ...
http                 3 ms                 http.cookiejar, http.cookies, http.client
idna                 2 ms                 idna.core, idna.idnadata, idna.package_data, idna.intranges
urllib               1 ms                 urllib.request, urllib.parse, urllib.error, urllib.response
importlib            1 ms                 importlib.resources._adapters, importlib.resources.abc, importlib.resources._common, ...
typing               1 ms
ssl                  1 ms
re                   1 ms                 re._parser, re._compiler, re._constants, re._casefix

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

importfiler-0.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

importfiler-0.0.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file importfiler-0.0.1.tar.gz.

File metadata

  • Download URL: importfiler-0.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for importfiler-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3fe3a616d94e8cbcb12373301fdf56246d9344e6d22ba561e6977a659e02cc4a
MD5 cfd6364136141d5b7975152c56e1e099
BLAKE2b-256 1bb5bfd716f95f7077b8aea6f98479483ea36520cc8c904bdf6d51a126a3d670

See more details on using hashes here.

File details

Details for the file importfiler-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: importfiler-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for importfiler-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 803b4f44ab240a0db2c6691e566d2329ba6c1ea72ae68a58cfb51017d9d5580c
MD5 c37ec7d89d48ac086f0d2103c0978ebb
BLAKE2b-256 a8ab6d43b5170861c850f3204d9257d76fc60eeb118db6caeaf4844a33db870e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page