Jump to content

Garbage Collector vs Pixi.js


hashi
 Share

Recommended Posts

Hello
 
Have an Important question. Is Pixi garbage-collector safe?
 
I've found, for example, kind of terrible pieces of code. I will not show them here, because they are easy to find. Just search for "splice" method in pixi.dev.js. You will find it used for deleting elements from array. But Splice always return an array with deleted element/s. In pixi it isn't grabbed to some var, so Garbage Collector will eat it and after eating enough of unused vars, GC will make a lag in runtime, because of freeing memory.
 
Wonder if there are more of memory-unsafe fragments, is Pixi GC safe?
 
EDIT:
Some other example:
PIXI.Rope.prototype.updateTransform = function(){    var points = this.points;    if(points.length < 1)return;    var lastPoint = points[0];    var nextPoint;    var perp = {x:0, y:0}; //:O object created every call of function

Instead of perp object it may be two variables, perp_x and perp_y, as you can see in the next lines (that aren't shown) perp is used only for some in-function calculations.

 

EDIT2:

 

Garbage Collector based on snake example:

kx5VQHq.png

 

Even better..:

 

FdkaNXP.png

Link to comment
Share on other sites

"But Splice always return an array with deleted element/s. In pixi it isn't grabbed to some var, so Garbage Collector will eat it "

 

"Instead of perp object it may be two variables, perp_x and perp_y"

 

Aren't browsers smart enough to optimize such simple cases?

If the returned value is not assigned to anything, why not dispose of it immediately...

Link to comment
Share on other sites

Unfortunately they are not. Optimizers like Google Closure Compiler are able to find optimize those things (variable use), but they hit performance a lot if you have already programmed optimized code. So at the end it's up to the programmer. 

 

Regarding splice: For example this 1-item custom splice function has low GC / is nearly always faster than the browsers one, especially on mobile. https://twitter.com/SolarJSGames/status/524553896908566528

If you even track length by yourself is can be speed up even more.

Link to comment
Share on other sites

Unfortunately they are not. Optimizers like Google Closure Compiler are able to find optimize those things (variable use), but they hit performance a lot if you have already programmed optimized code. So at the end it's up to the programmer. 

Yeah I made a simple test and apparently Chrome  does not optimize those cases(GC acted somewhat differently on each refresh, but I saw the correlation).

 

Regarding splice: For example this 1-item custom splice function has low GC / is nearly always faster than the browsers one, especially on mobile. https://twitter.com/SolarJSGames/status/524553896908566528

If you even track length by yourself is can be speed up even more.

 

Nice. Maybe you should talk to Pixi devs on Github...

 

----------------------

This does not look like a huge problem though. In the bunnies demo, frames actually don't slow down when the GC collects(it might be different in other browsers and on mobile).

And I looked at several other game engines, and most of their demo games generate more garbage... 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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