Best practices for reducing the amount of Garbage Collector work
I have a fairly complex Javascript app, which has a main loop that is
called 60 times per second. There seems to be a lot of garbage collection
going on (based on the 'sawtooth' output from the Memory timeline in the
Chrome dev tools) - and this often impacts the performance of the
application.
So, I'm trying to research best practices for reducing the amount of work
that the garbage collector has to do. (Most of the information I've been
able to find on the web regards avoiding memory leaks, which is a slightly
different question - my memory is getting freed up, it's just that there's
too much garbage collection going on.) I'm assuming that this mostly comes
down to reusing objects as much as possible, but of course the devil is in
the details.
The app is structured in 'classes' along the lines of John Resig's Simple
JavaScript Inheritance.
I think one issue is that some functions can be called thousands of times
per second (as they are used hundreds of times during each iteration of
the main loop), and perhaps the local working variables in these functions
(strings, arrays, etc.) might be the issue.
I'm aware of object pooling for larger/heavier objects (and we use this to
a degree), but I'm looking for techniques that can be applied across the
board, especially relating to functions that are called multiple times in
tight loops.
What techniques can I use to reduce the amount of work that the garbage
collector must do?
No comments:
Post a Comment