We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionEvents,  Publications,  Opportunities › code review (for 30$)
Page Index Toggle Pages: 1
code review (for 30$) (Read 2637 times)
code review (for 30$)
Apr 14th, 2010, 5:07pm
 
Hi,

my question is two fold:

1. I need my code reviewed.  It needs to run a modest UMPC and it's slacking.  everything works, but my programming knowledge doesn not allow me to update it in such a way that it will perform faster.

2. I would like to load pictures from a Mysql database.

the code can be found here:
http://rapidshare.com/files/375973973/prototype.zip.html
it consists of 2 sketches. one for the bluetooth server, one for the client.

I'm sure you guys can figure it out.
I'm willing to pay up to 30 bucks through paypal for this fix.
That's not an awful lot of money, but that's all I can spare as a student for this project.

thx in advance.
If you'd like to work on this, contact me for the database info.

take care,
Tom
Re: code review (for 30$)
Reply #1 - Apr 15th, 2010, 5:05am
 
java and mysql are always slowly, and you better keep your sql commands simple. "ORDER BY id DESC LIMIT 1" is pretty hard to perform on old machines. another increase in performance will be reached if you dont make loops with less than 10 items. your prof will tell you your code looks crappy but even if you write 10 times the same line, it will run faster ..
Re: code review (for 30$)
Reply #2 - Apr 15th, 2010, 5:31am
 
Please send me the database...
I'll have a look as soon as possible.
IMHO, this is not a question of loops or queries, but more a database indexation issue.
I think that the rendering also need some optimization.

Regards
Re: code review (for 30$)
Reply #3 - Apr 15th, 2010, 6:15am
 
coldarchon wrote on Apr 15th, 2010, 5:05am:
your prof will tell you your code looks crappy but even if you write 10 times the same line, it will run faster ..

It was true with 8bit computers running Basic programs or even assembly code at 1MHz...
I doubt you will get a measurable improvement with Java on modern computers with such trick...

@posiXtom: "I would like to load pictures from a Mysql database."
I believe it is basically a bad idea...
It will bloat your database, complicate your code (you have to convert bytes to PImage) and so on. I don't see any advantage to this over storing image names (or paths) and loading by traditional means (but if you have good arguments, I am ready to hear).
Re: code review (for 30$)
Reply #4 - Apr 15th, 2010, 1:16pm
 
@PhiLho:  I actually do not have a solid argument other than i have this php generator thing which allows me to upload picture through a web interface if I indicate a field as "blob".
the images should be loaded from there.

I don't have a lot of php/mysql knowledge and to be perfectly honest i can't really spare the time to figure this one out.
there's a thesis that goes together with this and it needs writing...Bad Wink
Re: code review (for 30$)
Reply #5 - Apr 15th, 2010, 1:18pm
 
oh and to the rest:

I don't think it's the mysql thing slowing it down. although it might give a quirk in the beginning when your connection is bad, than everything is loaded and you don't need the mysql connection anymore.

the problem is situated in updating the screen. i guess it's the graphic processor of the UMPC that can't handle the png or something...
just guessing here though...

It has a perfect response rate on my laptop, but slacks on the umpc
Re: code review (for 30$)
Reply #6 - Apr 20th, 2010, 12:53am
 
B.L.hacky is not responding...anyone else interested?
Re: code review (for 30$)
Reply #7 - Apr 23rd, 2010, 11:12am
 
How come it looks like every one of your Update methods calls background()?

background is fairly slow and the P2D renderer is also somewhat slow, only a bit ahead of the JAVA2D renderer (default)

Any chance the UMPC supports the OpenGL renderer?

Otherwise I've found the P3D renderer to actually be faster than P2D in many cases, even for 2D.

Also I still see some printf's in there. Those calls are very slow as well. Best bet is to create your own log(String) function to call instead of printf, then before exporting just comment out the println line inside your log function and you'll save the cost of calling printf all those times, and still have all your logging functionality.

Otherwise, I really suggest cleaning up your indentation. As you continue to grow as a programmer the patterns you recognize will become more based on whitespace. You'll find it helps you follow the code much more quickly. (If the code isn't missaligned for you, perhaps you have a mixture of tabs and spaces for indenting -- I currently use spaces in place of tabs at 2 spaces per indent)

Anyways, if you really want to figure out where the app is spending it's time, start in your draw loop and store millis() in integers before and after each function call. Get the difference between the two values and you have roughly the number of milliseconds each call takes. Find the one that takes the longest, and continue down that path until you can find what really needs to be optimized.

It may come down to you're just using too much memory for the device, or you're allocating too much each frame, which will cause the garbage collector to start slowing down your app after some time. If this seems to be the case, then you just need to make sure that everything you're loading and allocating you do as much as possible in setup (or functions called from setup), and then never release all of your references to those objects so they persist for the lifetime of your app. And certainly don't load images every frame (But I didn't see any evidence of this)

Hope some of those tips help,

Jack








Page Index Toggle Pages: 1