Results 1 to 2 of 2

Thread: chat application performance issues

  1. #1
    Join Date
    Aug 2007
    Thanked 15 Times in 15 Posts

    Default chat application performance issues

    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 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.

    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.

  2. #2
    Join Date
    Sep 2005
    Thanked 3 Times in 3 Posts


    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts