Skip to content

import pkg_resources can be very slow #677

@charleseidsness

Description

@charleseidsness

Running on a little imx6ul processor "import pkg_resources" can take 6 seconds or more. It looks like all it is doing is loading the version. I've patched it on my system to remove it, something you may want to consider.

Activity

svinota

svinota commented on Feb 19, 2020

@svinota
Owner

Got it, thanks for the issue. I'll try to look what may be wrong there.

svinota

svinota commented on Feb 19, 2020

@svinota
Owner

@ffourcot @celebdor

Looks like pkg_resources seriously affects startup time on platforms like ARM, and I can confirm that after tests.

I'm going to drop pkg_resources and provide __version__ by something like generating __version__.py file on make dist. Any objections?

crosser

crosser commented on Feb 19, 2020

@crosser
Contributor

Not an objection, just some considerations to keep in mind: semantics will be slightly different.

At runtime, version from pkg_resources will show the version of installed package, while version from a generated file will show the version of the package that is currently running. It may be different if you e.g. use an instance from the current directory. And in this case, generated file will show "more correct" information, but on the other hand, if you try to use an instance with not yet generated file, it may crash if import of this file is unconditional.

ffourcot

ffourcot commented on Feb 20, 2020

@ffourcot
Collaborator

Not an objection at all, we don't use it and we internally avoid usage of pkg_resources for the same reasons.

@celebdor was author of the commit adding pkg_resources, it's probably a good idea to check with him if this semantic change is ok for him.

celebdor

celebdor commented on Feb 20, 2020

@celebdor
Collaborator

Sounds good

svinota

svinota commented on Feb 20, 2020

@svinota
Owner

So be it — pkg_resources import is dropped. The version file import is enveloped in try/except, should not fail on import errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @celebdor@svinota@crosser@charleseidsness@ffourcot

        Issue actions

          import pkg_resources can be very slow · Issue #677 · svinota/pyroute2