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

Fix performance regression in utils._generate_installed_modules #2703

Merged
merged 2 commits into from
Feb 5, 2024
Merged

Fix performance regression in utils._generate_installed_modules #2703

merged 2 commits into from
Feb 5, 2024

Commits on Feb 4, 2024

  1. Fix performance regression in sentry_sdk.utils._generate_installed_mo…

    …dules
    
    Commit 8c24d33 causes a performance regression when PYTHONPATH is long, because it traverses PYTHONPATH for every distribution found (importlib.metadata.version traverses PYTHONPATH searching for a matching distribution for every call)
    
    In our case we have an environment containing ~500 paths, and containing ~100 distributions, and where the first call to sentry_sdk.utils.package_version causes ~150k filesystems operations taking 10-20 seconds.
    
    This commit uses the version from the distribution found when iterating all distributions, instead of calling importlib.metadata.version for each, which fixes the performance issue for us.
    
    Note that if multiple copies of a distribution with different versions exist in PYTHONPATH the existing _generate_installed_modules will return the name and version of the first matching distribution found multiple times, which will then be discarded by creation of a dict in _get_installed_modules. I have preserved the same behaviour by returning the name and version of a distribution only the first time a distribution name is seen.
    GlenWalker committed Feb 4, 2024
    Configuration menu
    Copy the full SHA
    a61fb67 View commit details
    Browse the repository at this point in the history

Commits on Feb 5, 2024

  1. Configuration menu
    Copy the full SHA
    0860cb2 View commit details
    Browse the repository at this point in the history