Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-03-2009, 08:00 PM   #1
rinogo
Registered User
 
Join Date: Mar 2008
Posts: 15
Default Loader optimization necessary?

Hey all!

Long story short - I'm dynamically loading many (40) images with Loader. In most scenarios, many of those images are duplicates (e.g. we're only loading 20 unique images, and the others are duplicates).

My Loader code is pretty standard:

ActionScript Code:
trace('Loading ' + filename); loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.INIT, initListener); loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorListener); loader.load(new URLRequest(filename));

First question:
My assumption is that if I load the same image multiple times, it is only transferred over HTTP once after which each Loader just loads its own copy from the cache. Is this assumption correct?

Second/third questions:
How much overhead is introduced with these 'browser-level' cache hits? (Since the browser manages HTTP transfers/caching/etc). I could theoretically write my own LoaderManager class that would only user Loader once per image, and then subsequent requests for duplicate images would directly return a reference to loader.content. (In other words, instead of hitting the browser cache, I would simply write my own internal cache and hit it instead).

Is it worth the effort to write this application-level cache, or do you think the benefits will be negligible? (Writing this manager class will take two hours or so, and I'd rather avoid wasting that time if it won't be worth it)

What do you think?
rinogo is offline   Reply With Quote
Old 11-03-2009, 08:18 PM   #2
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,758
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

It would help in both load performance and memory if you cached and reused existing items, but its not necessary if you're not feeling any negative impact from loading from the cache as is
__________________
(6)
senocular is offline   Reply With Quote
Old 11-03-2009, 08:28 PM   #3
rinogo
Registered User
 
Join Date: Mar 2008
Posts: 15
Default

Thanks for the response as always, senocular! That's just the thing - I load all of the images at the same time, and I am experiencing a speed hit. Maybe I'll just code up the changes and see if it helps... :/
rinogo is offline   Reply With Quote
Old 11-03-2009, 09:12 PM   #4
rinogo
Registered User
 
Join Date: Mar 2008
Posts: 15
Default

Done with the quick 'n dirty version of the implementation. Didn't seem to help much. Maybe the speed hit is in creating the DisplayObjects used to display the bitmaps... Or could it be something else?
rinogo is offline   Reply With Quote
Old 11-03-2009, 09:21 PM   #5
shawnblais
Senior Member
 
Join Date: Feb 2009
Posts: 153
Default

You'll see a hit just from trying to instanciate that many load operations at once.

The best approach is to probably implement some sort of queue system, where you have say 5 - 10 active downloads at any given time, and as one finished the next one starts.

Or the easier way, just set up a timer and space your loads out by like .1 seconds...
__________________
Portfolio: http://www.shawnblais.com
Blog & Code Examples: http://www.shawnblais.com/lab
shawnblais is offline   Reply With Quote
Old 11-03-2009, 09:28 PM   #6
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,758
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

The standard limitation is 4 open connections at once
__________________
(6)
senocular is offline   Reply With Quote
Old 11-03-2009, 09:46 PM   #7
shawnblais
Senior Member
 
Join Date: Feb 2009
Posts: 153
Default

Quote:
Originally Posted by senocular View Post
The standard limitation is 4 open connections at once
What do you mean "standard"?? Is that the max concurrent connections that are actually made??
__________________
Portfolio: http://www.shawnblais.com
Blog & Code Examples: http://www.shawnblais.com/lab
shawnblais is offline   Reply With Quote
Old 11-03-2009, 09:50 PM   #8
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,758
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

Actually that data might be outdated. Seems now both FF and IE use 6, but limit 2 per domain? It all depends on the client.
__________________
(6)
senocular is offline   Reply With Quote
Old 11-03-2009, 10:11 PM   #9
rinogo
Registered User
 
Join Date: Mar 2008
Posts: 15
Default

For what it's worth:

Seems like I was just stressing the interpreter a bit too much (initializing my app, starting tweens, loading images, etc all at the same time).

The cached Loader class works like a charm but doesn't really boost responsiveness (although surely it reduces the memory footprint and is 'cleaner') - I don't regret implementing it.

What *did* end up helping was adding a trivial delay to some of the initialization. Namely, 'cycler.show(0)' is the command that 'starts' the app, including displaying lots of Sprites, tweening them, etc. Delaying this command by 10ms helped immensely:

setTimeout(cycler.show, 10, 0)

Funny how such a trivial delay (10ms) could have such a significant effect on app responsiveness...

Anyway, there you go. Thanks for the help, guys.
rinogo is offline   Reply With Quote
Old 11-03-2009, 10:25 PM   #10
shawnblais
Senior Member
 
Join Date: Feb 2009
Posts: 153
Default

Quote:
Originally Posted by senocular View Post
Actually that data might be outdated. Seems now both FF and IE use 6, but limit 2 per domain? It all depends on the client.
Ahh cool, thanks for the info
__________________
Portfolio: http://www.shawnblais.com
Blog & Code Examples: http://www.shawnblais.com/lab
shawnblais is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:03 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.