engine icon indicating copy to clipboard operation
engine copied to clipboard

Particle system creation is slow

Open willeastcott opened this issue 6 years ago • 5 comments

An investigation should be carried out to search for optimization opportunities.

willeastcott avatar Oct 15 '19 00:10 willeastcott

I have noticed it as well. It is related to rebuilding texture with parameters and reuploading it to GPU. Even when particle emitter is cloned, it still calls rebuild, although they will look and behave identical.

I believe if particle is cloned and looks identical, it should then clone parameters texture too. But if we clone emitter and it should look different based on randomisation curves, then it should call rebuild.

Or leave rebuild/randomisation to developer, and always clone identical without rebuilding. So more flexibility to developer.

Maksims avatar Oct 15 '19 08:10 Maksims

It does indeed allocate a lot of stuff when created. It can be made faster, but the best optimization is still on the user side: create emitter pool in advance and reuse.

guycalledfrank avatar Oct 15 '19 09:10 guycalledfrank

It does indeed allocate a lot of stuff when created. It can be made faster, but the best optimization is still on the user side: create emitter pool in advance and reuse.

I've created pool. but unfortunately it does not allocate on cloning, but on first render. So there seems to be no way to pre-warm it?

Maksims avatar Oct 15 '19 10:10 Maksims

Maybe this one? https://github.com/playcanvas/engine/blob/master/src/scene/particle-system/particle-emitter.js#L1041

guycalledfrank avatar Oct 15 '19 10:10 guycalledfrank

Maybe this one? https://github.com/playcanvas/engine/blob/master/src/scene/particle-system/particle-emitter.js#L1041

Nope. this will only setup particle emitter, so when it starts playing, it already has particles spawned.

To pre-warm engine for particle, it should be enabled as entity with component, so it creates Emitter, check here: https://github.com/playcanvas/engine/blob/master/src/framework/components/particle-system/component.js#L601 And it will call rebuild.

Would be great to either have a function to actually trigger all rebuilding and stuff, so it wouldn't stall JS thread when entity is enabled first time.

Maksims avatar Oct 15 '19 11:10 Maksims