Skip to content

I wonder how to optimize this fantastic plugin? #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
loverorser opened this issue Feb 27, 2025 · 5 comments
Open

I wonder how to optimize this fantastic plugin? #358

loverorser opened this issue Feb 27, 2025 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@loverorser
Copy link

Throughing profiler,the UIParticleRenderer.UpdateMesh() costs a lot,with Combine Mesh,Bake Mesh and Update Animatable Material Properties and so on.
Though when using little amount UIParticle,it seems good and works well.However,when there is too much UIParticle in one canvas and,with many Particle System in Rendering Order(about 5-10),it runs slow!It costs about 50-70ms per frame.
I'm trying to seek into the code deeply but,it is hard to optimize for every piece of code has its purpose.

@loverorser loverorser added the question Further information is requested label Feb 27, 2025
@loverorser
Copy link
Author

Image

Image

Image

Image

@mob-sakai
Copy link
Owner

Thank you for your reporting!

@mob-sakai
Copy link
Owner

When rendering the same particle system multiple times, use the [Mesh Sharing](https://github.com/mob-sakai/ParticleEffectForUGUI?tab=readme-ov-file#component-uiparticle) feature.

@loverorser
Copy link
Author

Thank you for your replying!However,these particle system in my project are different from each other,and I suppose it is not supported to enable Mesh Sharing.

@mob-sakai
Copy link
Owner

Alright, I’ve been considering some optimizations:

UIParticleUpdater.GetGroupedRenderers

This is a method that retrieves grouped (=shared) UIParticleRenderer instances.
Currently, it reconstructs the list each time it is called, but it should be cacheable.
The cache can be refreshed when UIParticle.OnEnable / OnDisable is triggered.

Color32Extensions.LinearToGamma

This is a method that converts mesh vertex colors from linear color space to gamma color space.
I considered caching it, but mapping it to RGB24 bits would consume over 67 MB of memory
(256*256*256*32 bit ≒ 67 MB), making it impractical.

By implementing LinearToGamma on the shader side and controlling it with a specific macro
(e.g., UI_PARTICLE_FORCE_GAMMA), the calculation cost could be virtually negligible.
However, if the user is using a shader other than UI/Additive, they would need to modify their existing shader.

UIParticle.UpdateTransformScale

This method calculates the inverse of the canvas localScale, but it does so multiple times per frame.
It should be cached.

Additionally, I believe DrivenRectTransformTracker is unnecessary at runtime.

Culling Mask

An option to skip simulation and rendering for UIParticle instances that are outside the canvas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants