maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Python Qt startup time tips (https://talk.maemo.org/showthread.php?t=47850)

mikec 2010-03-20 11:29

Python Qt startup time tips
 
Hi Guys

Just did some experiments on Python Qt startup times.
ncalc currently takes 3 seconds to startup from terminal.

I just managed to improve this to 2 seconds by making a small change to the import statement in my main.py :D

from

Code:

from PyQt4 import QtCore,QtGui
from ui.calcstub import MainWindow

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    ui = MainWindow()
    ui.show()
    sys.exit(app.exec_())



To

Code:

from PyQt4 import QtCore
from PyQt4.QtGui import QApplication
from ui.calcstub import MainWindow

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    ui = MainWindow()
    ui.show()
    sys.exit(app.exec_())

Will post additional tips as I find them. Would be interested in other startup optimizations also.

clasificado 2010-03-20 19:32

Re: Python Qt startup time tips
 
Intresting!

Khertan 2010-03-20 19:48

Re: Python Qt startup time tips
 
Did you try with pyside, as the last try i made i think it was a bit too slow just to start up to make real applications.

attila77 2010-03-20 20:32

Re: Python Qt startup time tips
 
@mikec: another trick if your main() is big to put it in a separate file (as only import-ed things can be saved parsed). Then there is pylauncher, but it's been a while since it was updated, not sure if it works on the N900/PyQt/PySide out of the box.

@Khertan: until a Shiboken based version is released, it's going to be slow, the binaries are huge.

mikec 2010-03-20 21:12

Re: Python Qt startup time tips
 
I thought PyLauncher was Gtk Only?

@Khertan, no have not used Pyside just yet, though itchy to get to PR1.2, Qt4.6 and then Pyside we assume will be along soon.

attila77 2010-03-20 21:37

Re: Python Qt startup time tips
 
Yeah, originally, but there is nothing preventing the same concept to be applied to Qt bindings (or any other module for that matter). It will take a few more days after PR1.2 till we get a fully functional Shiboken based PySide, though. So there is still purpose to good ole PyQt....

attila77 2010-03-21 17:50

Re: Python Qt startup time tips
 
And, before I forget, there is a trick to load an image before your app starts so it looks faster than it is (the application manager does this). Not sure how we can make that thingy cooperate with Qt...

See this thread: http://lists.maemo.org/pipermail/mae...er/021332.html

aspidites 2010-03-24 06:12

Re: Python Qt startup time tips
 
Quote:

Originally Posted by attila77 (Post 575100)
@Khertan: until a Shiboken based version is released, it's going to be slow, the binaries are huge.

Shiboken had its first "tech-preview" release:
http://lists.openbossa.org/pipermail...ch/000492.html

Suddenly I'm wishing I didn't clobber my scratchbox setup. I'm itching to try this out.

attila77 2010-03-24 08:07

Re: Python Qt startup time tips
 
Yay ! Time to make some benchmarks !

blubbi 2010-05-17 23:31

Re: Python Qt startup time tips
 
Mhh, interesting...

When I stripped down all the QT modules to the required ones in each of my modules I got a very, very tiny speedup for the startup time (which might be in the range of error)

For the second run, when the .py files are already byte-compiled, there is no difference at all. So I guess, best practice would be to distribute the programs pre-compiled as .pyo (.pyc)

For version 1.0.1 I just had this in each of my modules (besides some other stuff):
Code:

from PyQt4 import QtCore, QtGui
sys.exit()

For version 1.0.2 I stripped the QT modules down to the required ones only:
Code:

from PyQt4 import QtCore
from PyQt4.QtGui import QApplication, QMainWindow, QDialog, QPushButton, QMessageBox
sys.exit()

(Some modules requred more, some less Qt modules)

First launch:
www2sms-1.0.1 $ time python www2sms.py
real 0m 2.62s
user 0m 1.94s
sys 0m 0.21s
USER + SYS = 2.15s

www2sms-1.0.2 $ time python www2sms.py
real 0m 2.17s
user 0m 2.00s
sys 0m 0.14s
USER + SYS = 2.14s

Second launch:
www2sms-1.0.1 $ time python www2sms.py
real 0m 2.00s
user 0m 1.84s
sys 0m 0.16s
USER + SYS = 2.0s

www2sms-1.0.2 $ time python www2sms.py
real 0m 2.02s
user 0m 1.84s
sys 0m 0.16s
USER + SYS = 2.0s

By the way, where is the pstats module for python?
python -m cProfile www2sms.py
[...]
ImportError: No module named pstats

Cheers
Bjoern


All times are GMT. The time now is 10:32.

vBulletin® Version 3.8.8