Jump to content
Search Community

Questions about optimizing Efficiency

UbiAssassin test
Moderator Tag

Recommended Posts

Hello,

 

I wanted to pick some brains and learn a bit more about cleaning up after myself in my code. I am re-building my website from scratch using AS3 and a lot less timeline driven animations. I really have been loving digging into TweenMax and LoaderMax, but I think that I am still quite uneducated about how to optimize performance and make sure that I am coding in the most efficient manner.

 

My current setup includes a main movie with a main class file. The main class file contains the preloader code and animations that load a number of external swfs, various button and animation sounds, and two songs for my music player. There are also quite a few functions that control the timing/loading of the various start graphics. Each external movie has its own class file that calls for the content of the loaders that they need to access as well as all of the tweens and animations that I need.

 

1. My first specific question deals with how I should handle my LoaderMax loaders. I have a number of loaders that load external .swfs into my main movie. I do not autoDispose these loaders because I preload them and do not necessarily call for their content right away. Should I dispose of these loaders in the class files of the external movies after I have run a getcontent for them? I assume this is the preferred method?

When it comes to the loaders for the sounds it gets more complicated for me. Almost every other external movie that could be called throughout a visit to the site will run a getcontent on these loaders since they all need these basic sounds, so I guess I need to leave the loaders in tact for the life of the site?

How much performance degradation, if any, comes from leaving the loaders in tact?

 

2. Next are my eventListeners. I remove these in any case that I can, under the assumption that they will degrade performance if there are a lot of them active. The problem I foresee with this is the main page of my site. Right now, even in its early stage, I have @ 16 buttons that could be pushed at any time, so I have to leave their eventListeners active in order to detect mouseOver events, clicks, etc. Is this a really bad practice? It seems to me that I really cannot get around having a lot of eventListeners active at any given time.

 

3. What are the big performance drains and inefficient code practices that I should try to avoid and clean up? I am sorry for all of the questions, but I am new to both AS3 and Greensock and I want to use them in the most efficient ways that I can. I am getting along quite well, but I probably know enough to really do as much damage as good at this point hehe.

 

Thanks ahead of time for any responses!

Link to comment
Share on other sites

Ah, a fellow performance fanatic. Welcome :) Glad you're asking the questions.

 

I really wouldn't worry too much about disposing your loaders if you're not done with the content. It isn't as though the loaders themselves use up much memory or degrade performance. After they've loaded, they don't keep on checking things on every frame or anything - they just sit there (well, except VideoLoaders or MP3Loaders that are actively playing, but even those are going to be limited because you won't have a bunch playing simultaneously and even if you did, the loaders themselves don't use tons of resources - probably less than 1% of what the actual media consumes). Just dispose things when you're done with the content for sure.

 

As for removing listeners, those only affect performance when the actual events are getting dispatched. So, for example, if you have an onComplete listener on a loader, it makes absolutely no difference performance wise except when that event is dispatched. And even then the impact is miniscule. If you've got hundreds of objects spewing out events on every frame, then it will start impacting performance. But these loaders aren't doing that sort of thing. The most CPU-intensive event dispatching for the loaders would be onProgress events because they can happen so often while loading. However, once the loader loads, no more progress events are dispatched so it makes no difference.

 

Remove your listeners when you don't need them anymore, plain and simple. Don't stress out about leaving them on there if you need them, though. Seriously, they impact is miniscule. And of course things were coded to make performance as solid as possible from the get-go.

 

As far as best practices and that sort of thing, check out the tips & tricks page at http://www.greensock.com/loadermax-tips/ and the learning resources page at http://www.greensock.com/learning/

 

Enjoy!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...