PDA

View Full Version : chat application performance issues



jackbenimble4
07-21-2008, 05:14 PM
I've been working on a javascript ajax chat application and everything is just about complete. Users can create rooms, set their font color, display message timestamps, see who's typing and more... but it all comes crashing down in a session lasting longer than 20 minutes. I've noticed it in both Firefox 3.0, and IE 7. I was under the impression that most memory leak problems were fixed by now, which has me thinking maybe I just write incredibly inefficient code.

When the application has been running awhile, memory usage for Firefox 3.0 on Mac is greater than 300MB and CPU usage is around 50%. Firefox noticely slows down while the application is running. Just typing in a message I notice a lag between when I press a key and it shows up. In a 43 minute conversation with a buddy, we sent 83 messages. Here's a screenshot of the CPU and memory usage (http://xboxamerica.com/jackson/v2Chat_BeforeRestart.png) at the end of that conversation. My chat app has a feature that will let you restart your chat session by logging you out and then back on. This hides all the previous messages from you. After I did that, the CPU usage got cut in half, but not the memory. Here's a screenshot of that (http://xboxamerica.com/jackson/v2Chat_AfterRestart.png).

Would anyone glancing over my source code and telling me if anything stands out to them? I really don't know what to do. I worked my you-know-what off writing and debugging this application, just to have it be unbearable to use.

I'll include the main file. There are references to objects in some other files such as a Core object but their functionality should be self explanatory. The Core object is just a really simple library from the Sitepoint Simply Javascript book.

It's a long file reaching 1383 lines with documentation and a lot of white space. I apologize for the volume of code, but I don't know where the problem is originating. I realize that no one will likely have the time to look over my mess of a script, so any suggestions on what to look for would be great too. Here's a link to the javascript file (http://xboxamerica.com/temp/Chat.js).

blm126
07-21-2008, 09:48 PM
Ok, I glanced through the code. I didn't notice any obvious problems, so my advice is going to be pretty general. What you need to check is what data the application is keeping track of. Check the obvious places first. Use some type of tool(I like Firebug) to check the data being stored by your application, and make sure that extra information that you don't need isn't creeping in. To look for areas where you could have a memory leak, the most problematic spot for me is normally anonymous functions, or really, any function that has a complicated scope. Try to think like the browser garbage collector. When do you no longer need data? When does that data move out of scope? The garbage collector will only remove things when they go out of scope. Hope that helps