Editing Python/Harmattan/Performance Considerations for Python Apps
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
- | Based on [http://talk.maemo.org/showthread.php?t=50737&highlight=fmms Making Python faster (for fmms initially)] and [http://talk.maemo.org/showthread.php?t=47850 Python Qt startup time tips] | + | Based on [http://talk.maemo.org/showthread.php?t=50737&highlight=fmms|Making Python faster (for fmms initially)] and [http://talk.maemo.org/showthread.php?t=47850|Python Qt startup time tips ] |
- | See the [http://wiki.python.org/moin/PythonSpeed/PerformanceTips python.org page | + | See the [http://wiki.python.org/moin/PythonSpeed/PerformanceTips python.org page] for general python optimizations. |
- | + | = Profiling = | |
- | Do not worry about performance unless you notice a problem. Then only optimize what you can justify with profiling. | + | Do not worry about performance unless you notice a problem. Then only optimize what you can justify with profiling. |
To profile Python code, run it with | To profile Python code, run it with | ||
Line 18: | Line 18: | ||
See the [http://docs.python.org/library/profile.html python.org page] for more information on profiling | See the [http://docs.python.org/library/profile.html python.org page] for more information on profiling | ||
- | + | = Improving Performance = | |
- | + | == Interpreter Choice == | |
- | + | === Unladen Swallow === | |
[http://www.python.org/dev/peps/pep-3146/ PEP 3146 - Merging of Unladen Swallow] | [http://www.python.org/dev/peps/pep-3146/ PEP 3146 - Merging of Unladen Swallow] | ||
Line 28: | Line 28: | ||
Currently Unladen Swallow has not seen too much performance benefit but has a longer start up time and takes more memory | Currently Unladen Swallow has not seen too much performance benefit but has a longer start up time and takes more memory | ||
- | + | === Psyco / Cython === | |
- | + | ||
- | + | ||
Do these work with Arm? | Do these work with Arm? | ||
- | ==== | + | === Shedskin === |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | === | + | === C with CTypes === |
- | + | == Startup == | |
- | === Startup === | + | === /usr/bin/python Startup === |
- | + | Preloaders exists like [http://pylauncher.garage.maemo.org/ PyLauncher] that keep a python process around with heavy weight imports like gtk already imported. On application launch it forks the preloader process. | |
- | Preloaders | + | Preloaders were favored back in the Maemo 4.1 days but has fallen out of favor lately. Concerns center around always keeping an unused python process with heavy pieces of code imported always around [http://talk.maemo.org/showpost.php?p=622358&postcount=10]. |
- | + | === Parsing .py files === | |
- | ==== | + | ==== Stripping the Code ==== |
- | + | A major downside is that the code that your users is running is different than the code you develop with. This means any stack traces that users provide will be a bit more complicated to decipher. | |
- | + | ||
- | A major downside is that the code that your users is running is different than the code you develop with. This means any stack traces that users provide will be a bit more complicated to decipher. | + | |
Benchmarks from stripping code[http://talk.maemo.org/showpost.php?p=627311&postcount=28] | Benchmarks from stripping code[http://talk.maemo.org/showpost.php?p=627311&postcount=28] | ||
First test - normal code | First test - normal code | ||
- | + | 2104 lines of code | |
- | + | 580 blank lines | |
- | + | 215 code lines | |
- | + | Load time from icon click to fully loaded - 10.04 seconds | |
Second Test - Cleared up code | Second Test - Cleared up code | ||
- | + | 2104 lines of code | |
- | + | 0 blank lines | |
- | + | 80 code lines | |
- | + | Load time from icon click to fully loaded - 9.25 seconds | |
Third - Cleared up code!! | Third - Cleared up code!! | ||
- | + | 1469 lines of code | |
- | + | 0 blank lines | |
- | + | 80 code lines | |
- | + | Load time from icon click to fully loaded - 8.40 (5 tests , from 8.09 to 8.60) | |
- | + | ==== Generating pyc/pyo files ==== | |
Python serializes its state after importing a file to save on re-parsing. It saves these next to the .py files which means if the user does not have write access, Python will not be able to cache it. | Python serializes its state after importing a file to save on re-parsing. It saves these next to the .py files which means if the user does not have write access, Python will not be able to cache it. | ||
- | + | === Perceived Startup Performance === | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
[http://lists.maemo.org/pipermail/maemo-developers/2009-October/021478.html hildon_gtk_window_take_screenshot] takes advantage of user perception to make the user think the app is launched faster. | [http://lists.maemo.org/pipermail/maemo-developers/2009-October/021478.html hildon_gtk_window_take_screenshot] takes advantage of user perception to make the user think the app is launched faster. | ||
- | + | == Responsiveness == | |
- | === | + | === Worker Threads === |
- | The One Ring has separate threads for its | + | The One Ring has separate threads for its DBus logic and its networking logic. it does this separation through a worker thread that the DBus thread posts tasks to. Results come as callbacks in the DBus thread. |
See [https://garage.maemo.org/plugins/ggit/browse.php/?p=theonering;a=blob;f=src/util/go_utils.py;h=20ccac19201a4eae1b019fe2861e120b92010f55;hb=835f22ccd4b8e357bcbbc364d451e98721401e72 AsyncLinearExecutor] and some [https://garage.maemo.org/plugins/ggit/browse.php/?p=theonering;a=blob;f=src/channel/call.py;h=aefc59861a1cede286d4094bf8fc35101f2ff19d;hb=835f22ccd4b8e357bcbbc364d451e98721401e72 example code] | See [https://garage.maemo.org/plugins/ggit/browse.php/?p=theonering;a=blob;f=src/util/go_utils.py;h=20ccac19201a4eae1b019fe2861e120b92010f55;hb=835f22ccd4b8e357bcbbc364d451e98721401e72 AsyncLinearExecutor] and some [https://garage.maemo.org/plugins/ggit/browse.php/?p=theonering;a=blob;f=src/channel/call.py;h=aefc59861a1cede286d4094bf8fc35101f2ff19d;hb=835f22ccd4b8e357bcbbc364d451e98721401e72 example code] | ||
- | + | == Memory Usage == | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | = FAQ = | |
- | == | + | == Is Python slow? == |
- | + | The standard response of "it depends". For a graphical application not doing too much processing a user will probably not notice it is written in Python. Compare that to an experiment by epage in writing a GST video filter in python that at best ran at 2 seconds per frame. | |
[[Category:Python]] | [[Category:Python]] |
Learn more about Contributing to the wiki.