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

Performance hit on import Qt #8

Closed
fredrikaverpil opened this issue May 28, 2016 · 5 comments
Closed

Performance hit on import Qt #8

fredrikaverpil opened this issue May 28, 2016 · 5 comments

Comments

@fredrikaverpil
Copy link
Collaborator

Importing the .Qt submodule of PyQt means "import all" which might give a performance hit, when one might only end up using QtWidgets (?)

Not sure what you meant here @mottosso

@fredrikaverpil fredrikaverpil changed the title Performance hit on import Qt Performance hit on import Qt May 28, 2016
@mottosso
Copy link
Owner

PyQt has this convenience feature that when you import PyQt5.Qt it will import all classes under the same namespace. So even if you aren't using QtQml, it would still get imported, which I am just assuming adds to the amount of time it takes to import.

I'm sure there is reference of it in the documentation, but couldn't find it just now. This was the closest thing I found.

To solve this, I would rather find a way of only importing what the user actually imports.

from Qt import QtWidgets
# Should not import QtCore, QtQuick.. etc.

Alternatively if we test and make sure it actually does take longer, maybe it doesn't, in which case there's nothing to worry about.

@pipoun
Copy link

pipoun commented Jun 3, 2016

With current Qt.py implementation, in function _pyqt4() if you replace

import PyQt4.Qt

with

import PyQt4.QtCore
import PyQt4.QtGui

to avoid importing PyQt4.Qt (and the performance hit), the following code doesn't work any more.

>>> import Qt
>>> import Qt.QtSvg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: dynamic module not initialized properly

@mottosso
Copy link
Owner

mottosso commented Jun 3, 2016

Yes, importing it all at once has been the only way I haven't run into problems. Me thinks there is some magic happening on import of the PyQt modules.

@fredrikaverpil
Copy link
Collaborator Author

This thread is interesting and somewhat related to this issue: https://www.riverbankcomputing.com/pipermail/pyqt/2016-September/038019.html

"from foo import bar" is equivalent to:

   import foo
   bar = foo.bar
   del foo

@mottosso
Copy link
Owner

mottosso commented May 4, 2017

This isn't solvable anymore, since 1.0, as we are explicitly importing every single member in order to map it correctly. Nor may it ever have needed a solution.

@mottosso mottosso closed this as completed May 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants