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.
IndexProgramming Questions & HelpPrograms › loadImage in applet extremely slow
Page Index Toggle Pages: 1
loadImage in applet extremely slow (Read 1698 times)
loadImage in applet extremely slow
May 28th, 2009, 11:15pm
 
Hello everyone,

I've written some code that loads a certain amount of images into a sketch from a web server using "loadImage("url")". The images names are dynamic so I can't add them to the "data" folder.

When I run the sketch in Processing, it loads almost instantly but when I export it to an applet and put it on my server, the images take a very very long time... like I'm talking minutes... and the images are about 5Kb - 10Kb each.

I've implemented threading to load the images but that didn't help.

Anyone has an idea on optimizing this?

Thanks
Steven
Re: loadImage in applet extremely slow
Reply #1 - May 29th, 2009, 1:45am
 
use php to fetch the images to your server first perhaps
sortof like .. loadImage("yourdomain.com/applet/image.php?url=base64-encoded-url");
or something like that
Re: loadImage in applet extremely slow
Reply #2 - May 29th, 2009, 3:40am
 
AFAIK, image loading is already threaded.
Are the images on your own server?

I see this comment in the PApplet source code:
Quote:
By trial and error, four image loading threads seem to work best when
loading images from online. This is consistent with the number of open
connections that web browsers will maintain. The variable is made public
(however no accessor has been added since it's esoteric) if you really
want to have control over the value used. For instance, when loading local
files, it might be better to only have a single thread (or two) loading
images so that you're disk isn't simply jumping around.

Do you try to load lot of images simultaneously?
Re: loadImage in applet extremely slow
Reply #3 - May 29th, 2009, 8:20am
 
Are you using loadImage() or requestImage()? (Or is there a difference anymore?)
Re: loadImage in applet extremely slow
Reply #4 - May 29th, 2009, 9:28am
 
Ah, you are right, I browsed the code too fast, the comment applies to requestImage(), not to loadImage() which is always synchronous...
requestImage()'s ref. says:
Quote:
Asynchronous image loading (particularly when downloading from a server) can dramatically improve performance.
Re: loadImage in applet extremely slow
Reply #5 - Jun 2nd, 2009, 10:27pm
 
Thanks for your ideas guys.

@Seltar: What do you mean exactely? Copy them to my server via php? If that's the case, I can't really fetch the images to my domain because the applet could fecth thousands and thousands of images over time.

@NoaBuddy: I'm using loadImages. I'll try requestImages but have to wait for the image to be loaded before displaying it or else I get an error.

@PhiLo: Thanks!

Anyone else has suggestions?

It really seems to be a problem with the applet because in Processing, it loads them instantly.

Cheers!
Re: loadImage in applet extremely slow
Reply #6 - Jun 3rd, 2009, 2:40am
 
steven wrote on Jun 2nd, 2009, 10:27pm:
@PhiLo: Thanks!

You are welcome, but you didn't answered my questions...

Quote:
When I run the sketch in Processing, it loads almost instantly

Loading the images from your disk or still from the server
It might be the server lagging a lot...
Re: loadImage in applet extremely slow
Reply #7 - Jun 3rd, 2009, 9:46pm
 
Still getting them from the server.

But even when I run the app directly in processing, it loads them directly from the server and it's really fast... unless they're cached somewhere...
Re: loadImage in applet extremely slow
Reply #8 - Jun 6th, 2009, 9:19am
 
If the difference is not the network, one other thing that changes between the IDE and applet environment is the amount of memory available.  You say each image is small, but if you're loading thousands, you may be hitting a memory limit in the JVM that your browser uses.

Even if you're not explicitly getting out of memory errors, Java consumes a lot of resources with garbage collection if you happen to be running close to the memory limit.

To see if this is the problem you are having, try reducing the available memory in the Processing IDE (it's in the preferences on the Mac) to see if you can reproduce what you're seeing in the applet.
Re: loadImage in applet extremely slow
Reply #9 - Jun 6th, 2009, 9:33pm
 
Thanks for the reply mhuyck
but I don't think it's a memory problem because I tested from 1 image to 5 images maximum and every time I increment the number of images, it takes longer and longer. (images are 50 px by 50px).
Re: loadImage in applet extremely slow
Reply #10 - Jun 7th, 2009, 10:52pm
 
Hmm... yeah, I guess it's not a memory problem if those are 5 small images.  Can you reproduce the problem with a small example sketch and share the code here?
Page Index Toggle Pages: 1