ShaderParticleEngine
ShaderParticleEngine copied to clipboard
Group.removeEmitter Performance
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).
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?
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 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?
Sorry, I've spent the past few days moving. I will get an example fiddle up asap.
And finally.
http://jsfiddle.net/titansoftime/gazta474/
[edited to fix some migration issues]
Awesome, thanks @titansoftime. I'll have a look as soon as I can!