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

Slow import due to pkg_resources #12

Closed
Ristovski opened this issue Jul 21, 2022 · 1 comment
Closed

Slow import due to pkg_resources #12

Ristovski opened this issue Jul 21, 2022 · 1 comment

Comments

@Ristovski
Copy link

Importing pkg_resources is slow (see pypa/setuptools#926 et al).

As a demonstration, dropping the following import pkg_resources and hardcoding the version improves the import times significantly, from ~400ms down to ~20ms.

from pkg_resources import get_distribution
import logging
__version__ = get_distribution("ripgrepy").version

Baseline, argparse as example:

$ python3 -c 'import timeit; t = timeit.Timer("import argparse").timeit(number=10); print(f"{t:.3f} seconds")'
0.010 seconds

ripgrepy, pkg_resources version:

$ python3 -c 'import timeit; t = timeit.Timer("import ripgrepy").timeit(number=10); print(f"{t:.3f} seconds")'
0.397 seconds

ripgrepy, hardcoded version:

$ python3 -c 'import timeit; t = timeit.Timer("import ripgrepy").timeit(number=10); print(f"{t:.3f} seconds")'
0.019 seconds
@securisec
Copy link
Owner

Thank you for the great suggestion! It has been addressed for the next major release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants