Javascript garbage collection pauses

I'm trying to create a simple JavaScript game engine using WebGl, but I have some unwanted problems with JavaScript in general, which I hope can be avoided. Besides the general lack of performance with JavaScript, I get some weird pauses when rendering using WebGl that happen periodically, once per second or so. I assume this should happen with the GC in JavaScript. Is there a way to minimize these stuttering? Are there any general practices that I should know that a way to get at least part of the garbage collection to occur while I can control it?

I know these are simple questions, but I'm pretty new to JavaScript, and searching the web has not given me a lot of useful information.

+5
source share
1 answer

Reuse objects as often as possible. If you create dozens of objects (for example, vectors and matrices) for each rendered frame, you will definitely get a GC-related stutter. Therefore, when you use a scene-based approach to render your game, you might want to cache objects in the nodes of the scene graph, for example. Or you can use the object pool template . In other languages, such as Java, this method is deprecated because object creation and GC are so fast today that the object pool no longer helps. But in JavaScript this can still help.

GC-stutter JavaScript, , , 2D- , . , . .

2D-:

http://www.ailis.de/~k/hg/javascript/twodee/file/tip/src/main/javascript/twodee

, , / / .

+2

All Articles