Notices


Reply
Thread Tools
mikec's Avatar
Posts: 1,366 | Thanked: 1,185 times | Joined on Jan 2006
#1
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

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.
__________________
N900_Email_Options Wiki Page

Last edited by mikec; 2010-03-20 at 21:08.
 

The Following 5 Users Say Thank You to mikec For This Useful Post:
clasificado's Avatar
Posts: 466 | Thanked: 180 times | Joined on Feb 2010
#2
Intresting!
 
Khertan's Avatar
Posts: 1,012 | Thanked: 817 times | Joined on Jul 2007 @ France
#3
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.
 
Posts: 3,319 | Thanked: 5,607 times | Joined on Aug 2008 @ Finland
#4
@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.
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 

The Following 2 Users Say Thank You to attila77 For This Useful Post:
mikec's Avatar
Posts: 1,366 | Thanked: 1,185 times | Joined on Jan 2006
#5
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.
__________________
N900_Email_Options Wiki Page
 
Posts: 3,319 | Thanked: 5,607 times | Joined on Aug 2008 @ Finland
#6
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....
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 
Posts: 3,319 | Thanked: 5,607 times | Joined on Aug 2008 @ Finland
#7
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
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 

The Following User Says Thank You to attila77 For This Useful Post:
Posts: 402 | Thanked: 229 times | Joined on Nov 2009 @ Missouri, USA
#8
Originally Posted by attila77 View Post
@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.
__________________
aspidites | blog | aspidites@inbox.com
 
Posts: 3,319 | Thanked: 5,607 times | Joined on Aug 2008 @ Finland
#9
Yay ! Time to make some benchmarks !
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 

The Following User Says Thank You to attila77 For This Useful Post:
blubbi's Avatar
Posts: 288 | Thanked: 113 times | Joined on Dec 2009 @ Germany
#10
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

Last edited by blubbi; 2010-05-17 at 23:38.
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 18:36.