maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Maemo 5 / Fremantle (https://talk.maemo.org/forumdisplay.php?f=40)
-   -   Making Python faster (for fmms initially) (https://talk.maemo.org/showthread.php?t=50737)

epage 2010-04-22 19:23

Re: Making Python faster (for fmms initially)
 
Quote:

Originally Posted by Khertan (Post 623199)
An other things to doesn't freeze the ui and to not slow down the device by using intensive thread is to divide tasks in very small tasks and to use a sigleton with gidle :

import gobject

class _DeferClass(object):
_calls=[]
_ref=None
def __new__(cls,*args,**kw):
if cls._ref is None:
cls._ref = super(_DeferClass,cls).__new__(cls,*args,
**kw)
return cls._ref

def __len__(self):
return len(self._calls)

def __call__(self,func,*args):
def NextCall():
(func,args)=self._calls[0]
func(*args)
self._calls=self._calls[1:]
return self._calls!=[]
if not self._calls: gobject.idle_add(NextCall)
self._calls.append((func,args))

I ve many example to give and there is so man things to say that i ll be able to write a book about py opimization.

So if you need so help optimizing code i can maybe help you.

An alternative is to use a worker thread per set of logic data to avoid locks and then wrap it in classes to handle the jumping between the main loop and my thread.

AsyncLinearExecutor code:
https://garage.maemo.org/plugins/ggi...51e98721401e72

Code that uses AsyncLinearExecutor:
https://garage.maemo.org/plugins/ggi...51e98721401e72

Khertan 2010-04-22 21:14

Re: Making Python faster (for fmms initially)
 
Quote:

Originally Posted by epage (Post 623233)
An alternative is to use a worker thread per set of logic data to avoid locks and then wrap it in classes to handle the jumping between the main loop and my thread.

AsyncLinearExecutor code:
https://garage.maemo.org/plugins/ggi...51e98721401e72

Code that uses AsyncLinearExecutor:
https://garage.maemo.org/plugins/ggi...51e98721401e72

Maybe but mine work also if the app is in background and we didn t want eat too much cpu of the app in front

epage 2010-04-22 21:25

Re: Making Python faster (for fmms initially)
 
Quote:

Originally Posted by Khertan (Post 623392)
Maybe but mine work also if the app is in background and we didn t want eat too much cpu of the app in front

I guess I'm not seeing the case but oh well, both work with each probably best for different needs

Khertan 2010-04-23 05:42

Re: Making Python faster (for fmms initially)
 
Quote:

Originally Posted by epage (Post 623413)
I guess I'm not seeing the case but oh well, both work with each probably best for different needs

Yep both both are different solutions for different use case.

dbrodie 2010-04-23 11:40

Re: Making Python faster (for fmms initially)
 
Well, depending on the case, Cython can be a very handy tool...

Khertan 2010-04-23 12:31

Re: Making Python faster (for fmms initially)
 
Also :

- Avoid while loop when you can use a "for foo in foo_list"
- use xrange instead of range (removed in python 3 so it s not really a good idea for compatibility)

ah and of course, Read this : http://wiki.python.org/moin/PythonSpeed/PerformanceTips

lcuk 2010-04-24 01:49

Re: Making Python faster (for fmms initially)
 
Quote:

Originally Posted by noobmonkey (Post 622330)
Interesting post....... I feel i may be able to provide a few tests to back up issues....

Healthcheck currently has about 300 redundant lines of code (Comments + Blank lines) probably 25% of the total.

I'll run a version of it without all of those and compare load times :D

hey Greg, did you manage to try this by chance?
it propbably won't make too much difference but if we can get a line count before and one after if there is any kind of difference it can go into the melting pot :)

noobmonkey 2010-04-25 19:22

Re: Making Python faster (for fmms initially)
 
Ahaaaaaaaaaaa i'm back! and had time to do it! yay!

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
2104 lines of code
0 blank lines
80 code lines
Load time from icon click to fully loaded - 9.25 seconds

Ok, it was a basic test, but i ran them side by side for a while with nothing else loaded... the load times where almost exactly the same each time. So... yes blank lines do affect load up!

My next test, later this week will be to remove redundant lines into sensible functions - should cut my lines of code down a lot...... so will compare that against these results.

:D

quick edit :-
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)

(Sorry code lines probably don't mean much - i meant comment lines!)

lcuk 2010-04-25 19:35

Re: Making Python faster (for fmms initially)
 
noobmonk3y - so you just saved 20% of the load time by scrubbing your code?

thats remarkable (tho extreme, we like comments)

i did not expect the difference to be so great.
if we could strip them from debs as part of packaging for most python apps that would be wicked
(keep them in source of course)

attila77 2010-04-25 21:39

Re: Making Python faster (for fmms initially)
 
@noobmonkey: use the import trick from my presentation, that way you can save the time required for parsing (empty lines or not).


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

vBulletin® Version 3.8.8