ShaderParticleEngine icon indicating copy to clipboard operation
ShaderParticleEngine copied to clipboard

Group.removeEmitter Performance

Open titansoftime opened this issue 7 years ago • 6 comments

I have a particle group with 80 emitters attached (clouds). After an emitter has existed for about 3 minutes I remove the emitter. Unfortunately each Group.removeEmitter call takes between 200 - 300ms on my 3 year old desktop. This of course freezes the app.

This is the culprit code (line 2260):

for ( var attr in this.attributes ) {
    if ( this.attributes.hasOwnProperty( attr ) ) {
        this.attributes[ attr ].splice( start, end );
    }
}

I can just comment this out and all "seems" fine, though I'm sure there is a resulting memory leak (haven't tested).

titansoftime avatar Oct 25 '17 16:10 titansoftime

Ah, good find! I'm sure you can figure out what that code is doing (and why I thought it necessary). I'll experiment with some perf improvements and do some profiling. What's the longest you'd like it to take (on your current setup?) I'm assuming less than 1 frame, so 16ms at the abs max?

squarefeet avatar Oct 26 '17 22:10 squarefeet

I'm assuming that the code removes the buffer attributes from the particle group. So huge memory and rendering advantage to remove them.

Hmm, tricky as the operation needs to happen quite quickly, sometimes up to 30 emitters with roughly 300-400 particles per emitter get removed.

I suppose I could just stagger the removal of the emitters, set up some sort of garbage collection. Hmm...

titansoftime avatar Oct 27 '17 02:10 titansoftime

@titansoftime Do you have an example of your use of this lib so I can try to reproduce it? Or could I just create 30 emitters with 300-400 particles and add/remove them to reproduce?

squarefeet avatar Oct 27 '17 11:10 squarefeet

Sorry, I've spent the past few days moving. I will get an example fiddle up asap.

titansoftime avatar Nov 02 '17 15:11 titansoftime

And finally.

http://jsfiddle.net/titansoftime/gazta474/

[edited to fix some migration issues]

titansoftime avatar Nov 17 '17 19:11 titansoftime

Awesome, thanks @titansoftime. I'll have a look as soon as I can!

squarefeet avatar Nov 21 '17 17:11 squarefeet