Active Topics

 


Reply
Thread Tools
epage's Avatar
Posts: 1,684 | Thanked: 1,562 times | Joined on Jun 2008 @ Austin, TX
#21
Originally Posted by Khertan View Post
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
__________________
770, n810, n900, Ideapad S10-3t
TheOneRing, DialCentral, Gonvert, Quicknote, Multilist, ejpi, nQa, Waters of Shiloah
Programming Blog
 

The Following User Says Thank You to epage For This Useful Post:
Khertan's Avatar
Posts: 1,012 | Thanked: 817 times | Joined on Jul 2007 @ France
#22
Originally Posted by epage View Post
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's Avatar
Posts: 1,684 | Thanked: 1,562 times | Joined on Jun 2008 @ Austin, TX
#23
Originally Posted by Khertan View Post
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
__________________
770, n810, n900, Ideapad S10-3t
TheOneRing, DialCentral, Gonvert, Quicknote, Multilist, ejpi, nQa, Waters of Shiloah
Programming Blog
 
Khertan's Avatar
Posts: 1,012 | Thanked: 817 times | Joined on Jul 2007 @ France
#24
Originally Posted by epage View Post
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.
 
Posts: 163 | Thanked: 96 times | Joined on Feb 2010 @ Israel
#25
Well, depending on the case, Cython can be a very handy tool...
 
Khertan's Avatar
Posts: 1,012 | Thanked: 817 times | Joined on Jul 2007 @ France
#26
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's Avatar
Posts: 1,635 | Thanked: 1,816 times | Joined on Apr 2008 @ Manchester, England
#27
Originally Posted by noobmonkey View Post
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
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
__________________
liqbase sketching the future.
like what i say? hit the Thanks, thanks!
twitter.com/lcuk
 

The Following User Says Thank You to lcuk For This Useful Post:
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#28
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.



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!)
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -

Last edited by noobmonkey; 2010-04-25 at 19:25.
 

The Following 5 Users Say Thank You to noobmonkey For This Useful Post:
lcuk's Avatar
Posts: 1,635 | Thanked: 1,816 times | Joined on Apr 2008 @ Manchester, England
#29
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)
__________________
liqbase sketching the future.
like what i say? hit the Thanks, thanks!
twitter.com/lcuk
 
Posts: 3,319 | Thanked: 5,610 times | Joined on Aug 2008 @ Finland
#30
@noobmonkey: use the import trick from my presentation, that way you can save the time required for parsing (empty lines or not).
__________________
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:
Reply

Tags
performance, python


 
Forum Jump


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