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
Core SRP CPU Performance Improvements #7657
base: master
Are you sure you want to change the base?
Core SRP CPU Performance Improvements #7657
Conversation
Some simple performance improvements. Would be good to take these into new commits as well and could be backported Since nothing changed for the end user I did not make changelog edits. Is that necessary? Improved CPU performance with: - Remove indirect gameObject call - Re order vector calculations - Merge .position and .rotation into .SetPositionAndRotation - Use TryGetComponent to reduce garbage allocation - Use native length and count instead of LINQ - Merge if-else return into return - Use AddRange - Simplify string comparison
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for all your tips. This is right. Nothing here should add a drastic improvement but it will contribute to have a more efficient editor. 👍
Adding more people to counter check change in case I miss something.
@@ -890,7 +890,7 @@ static string GetTextureAutoName(int width, int height, string format, TextureDi | |||
temp = string.Format("{0}x{1}{2}_{3}", width, height, mips ? "_Mips" : "", format); | |||
else | |||
temp = string.Format("{0}x{1}x{2}{3}_{4}", width, height, depth, mips ? "_Mips" : "", format); | |||
temp = String.Format("{0}_{1}_{2}", name == "" ? "Texture" : name, (dim == TextureDimension.None) ? "" : dim.ToString(), temp); | |||
temp = String.Format("{0}_{1}_{2}", name?.Length == 0 ? "Texture" : name, (dim == TextureDimension.None) ? "" : dim.ToString(), temp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, to add the null check, it is even better to rely on String.IsNullOrEmpty
temp = String.Format("{0}_{1}_{2}", name?.Length == 0 ? "Texture" : name, (dim == TextureDimension.None) ? "" : dim.ToString(), temp); | |
temp = String.Format("{0}_{1}_{2}", String.IsNullOrEmpty(name) ? "Texture" : name, (dim == TextureDimension.None) ? "" : dim.ToString(), temp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I benchmarked it and isNullOrEmpty actually does a string comparison instead of a null check, so is slower than this!
It is more readable however, so just say what you prefer. I can share the benchmark numbers tomorrow, but it was more than I expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do, I am curious about the difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these look like valid improvements to me. I'm curious if you can share some performance numbers, I wouldn't expect these to make a big difference but I'm open to be wrong :)
Made a public post for others to see. Could not test everything due to time limits. |
Some simple performance improvements. Would be good to take these into new commits as well and could be backported Since nothing changed for the end user.
I did not make changelog edits. Is that necessary?
Improved CPU performance with:
Purpose of this PR
Why is this PR needed, what hard problem is it solving/fixing?
Improve CPU performance with minor fixes
Testing status
Describe what manual/automated tests were performed for this PR
No major changes made to code
Comments to reviewers
Notes for the reviewers you have assigned.
Do I need to add changelog changes?
Can this be backported?