← Back to DAGDA | Support | Source: https://github.com/pypa/setuptools/issues/1154
Skip to content

Python 2.7 wheel for C-extension is slower than the egg/local-version on Windows #1154

Closed

Description

@Safihre

I have a Python 2.7 C-extension that was made for performance, however, I noticed something strange on Windows:
When I run locally python setup.py install and it installs it the "egg" way, the performance of running the module 500x in a loop is:

     yEnc C New  took   579 ms
     yEnc C New  took   580 ms
     yEnc C New  took   580 ms

But when I install it as a wheel locally or via pip without a single change to the C-code, this is the result:

     yEnc C New  took   702 ms
     yEnc C New  took   694 ms
     yEnc C New  took   691 ms

That's a 15-20% difference..
I also checked macOS and Ubuntu, here it does not seem to be the case.

To reproduce run and look at the yEnc C New score between the 2 ways:

git clone https://github.com/sabnzbd/sabyenc.git
cd sabyenc
python setup.py install
python .\tests\speed_compare.py; python .\tests\speed_compare.py;python .\tests\speed_compare.py;
pip uninstall sabyenc -y

pip install sabyenc
# Or this:
# python setup.py install bdist_wheel
# pip install .\dist\sabyenc-3.3.1-cp27-cp27m-win_amd64.whl
python .\tests\speed_compare.py; python .\tests\speed_compare.py;python .\tests\speed_compare.py;

Activity

  1. Safihre commented on Sep 19, 2017

    @Safihre
    Author

    Upon further inspection, when using (after removing existing dist and build folders):

    python setup.py install_lib
    

    It also creates the slower version.
    I compared compiler commands as printed during the building, and they were they same.
    Beware that you have to manually remove the sabyenc.pyd file from the site-packages directory after this last command for continued testing!

    I updated the wheel and setuptools to their latest versions before all this testing.

  2. Safihre commented on Sep 19, 2017

    @Safihre
    Author

    Oke so the difference is in the bootstrap-loader that comes included in the egg.
    When I only unpacked the sabyenc.pyd from the .egg into the site-packages directory, it was again slow.
    However, when I then renamed the file to sabyenc_.pyd, then unpacked from the .egg also the bootstrap loader sabyenc.py and changed it to:

    def __bootstrap__():
        global __bootstrap__, __loader__, __file__
        import sys, pkg_resources, imp
        __file__ = pkg_resources.resource_filename(__name__, 'sabyenc_.pyd')
        __loader__ = None; del __bootstrap__, __loader__
        imp.load_dynamic(__name__,__file__)
    __bootstrap__()

    It is fast again...

    What is happening here?!

    EDIT: Continued testing revealed that py2exe loads the files in the "fast" way, so at least our users get the fast experience anyway 🏅

  3. Safihre commented on Sep 21, 2017

    @Safihre
    Author

    Could this be a python bug in the way libraries are loaded? And should I report it to the Python bugtracker?

  4. Safihre commented on Oct 1, 2017

    @Safihre
    Author

    Python developers are sure it's a problem of setuptools and wheel: https://bugs.python.org/issue31555

    But as this is about Python 2.7 interest is understandably very low, so I'll close this now.
    Let's see if the same thing also happens when I port the module to Python 3.

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

      Issue actions