-
Notifications
You must be signed in to change notification settings - Fork 459
Improve Performance #3680
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
Improve Performance #3680
Conversation
- Merge looped Add calls into AddRange - Optimize empty string checks - Merge position & rotation calls into one - Short circuit operators for bools - Optimize string generation - Use native Count instead of LINQ
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.
Hi! Thanks so much for this PR. It looks great!
We just have to ask for our internal tracking, why did you decide to create this PR? Also, did you encounter a specific issue that made this PR necessary?
Happy to hear that.
The reason was mainly me wanting to make the Unity tools as optimized.
Small things can be missed, and if I can spend some time to improve it for
myself and everyone else that's great.
…On Wed, Sep 17, 2025, 16:30 Emma ***@***.***> wrote:
***@***.**** commented on this pull request.
Hi! Thanks so much for this PR. It looks great!
We just have to ask for our internal tracking, why did you decide to
create this PR? Also, was there any specific issue that made this PR
necessary?
—
Reply to this email directly, view it on GitHub
<#3680 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5EZXDBIPGM6J2P2JYYRCL3TFV7PAVCNFSM6AAAAACGXISQ76VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTEMZUG44DAOBUGQ>
.
You are receiving this because you authored the thread.Message ID:
<Unity-Technologies/com.unity.netcode.
***@***.***>
|
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 the information! You are 100% correct that the small things can be missed over time. We really appreciate you taking this time and this level of attention to detail.
I'm approving this here, however we can't land these changes from your fork directly. Next steps is I will create an internal branch and merge your changes into it. I'll then close this issue and we will land the changes from the internal branch.
Thank you for your contribution!
Appreciate it!
Also quick question, do internal teams also use the project auditor tool?
That gives even more insight than my Visual Studio setup (just a bit more
manual work to fix it)
…On Wed, Sep 17, 2025, 20:33 Emma ***@***.***> wrote:
***@***.**** approved this pull request.
Thank you for the information! You are 100% correct that the small things
can be missed over time. We really appreciate you taking this time and this
level of attention to detail.
I'm approving this here, however we can't land these changes from your
fork directly. Next steps is I will create an internal branch and merge
your changes into it. I'll then close this issue and we will land the
changes from the internal branch.
Thank you for your contribution!
—
Reply to this email directly, view it on GitHub
<#3680 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5EZXBCI257DCJQNLVRS2L3TGSP3AVCNFSM6AAAAACGXISQ76VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTEMZVG4ZDQMZQGU>
.
You are receiving this because you authored the thread.Message ID:
<Unity-Technologies/com.unity.netcode.
***@***.***>
|
We don't use that tool but it looks like we should be using it! If you have any info or thoughts on how it can help us we'd be very happy to hear it |
It goes over both code and assets in the project and gives potential
performance (cou, GPU, and memory) issues and provides an idea how to fix
some. It's especially useful since it finds where a lot of garbage
allocation is and finds places where there is too much boxing.
I would highly recommend to check it out:
***@***.***/manual/index.html
…On Wed, Sep 17, 2025, 23:36 Emma ***@***.***> wrote:
*EmandM* left a comment
(Unity-Technologies/com.unity.netcode.gameobjects#3680)
<#3680 (comment)>
We don't use that tool but it looks like we should be using it! If you
have any info or thoughts on how it can help us we'd be very happy to hear
it
—
Reply to this email directly, view it on GitHub
<#3680 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5EZXDPQTXDNIT7NZDKF6D3THH4ZAVCNFSM6AAAAACGXISQ76VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGMBUGYZTMMBYGQ>
.
You are receiving this because you authored the thread.Message ID:
<Unity-Technologies/com.unity.netcode.gameobjects/pull/3680/c3304636084@
github.com>
|
I have project auditor tool on my list to figure out how to use it best in our workflow (or just run periodic checks) but I didn't have capacity yet |
Cool!
Not sure if it's something Unity does, but I've done freelance performance
(and dev experience) optimization in the past for Unity based tools. So if
needed I can always help out more that was
…On Thu, Sep 18, 2025, 09:37 Michał Chrobot ***@***.***> wrote:
*michalChrobot* left a comment
(Unity-Technologies/com.unity.netcode.gameobjects#3680)
<#3680 (comment)>
I have project auditor tool on my list to figure out how to use it best in
our workflow (or just run periodic checks) but I didn't have capacity yet
—
Reply to this email directly, view it on GitHub
<#3680 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5EZXFTFJOJXKA4TDVJAID3TJOJ7AVCNFSM6AAAAACGXISQ76VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGMBVHA2TENRXGY>
.
You are receiving this because you authored the thread.Message ID:
<Unity-Technologies/com.unity.netcode.gameobjects/pull/3680/c3305852676@
github.com>
|
We appreciate the recommendation! I'll close this PR for now and we'll continue it in #3683. If you'd like to make more performance improvements we will always welcome it. Our current team is doing our best to get around to it all, but it's a big project with lots of nuances. Thanks for paying attention to the small changes that somehow always fall to the bottom of the importance pile! |
## Purpose of this PR @smitdylan2001 found and fixed some small performance improvements, which do not change any functionality. Especially the position and rotation calls and LINQ call removals are very helpful for performance 1. Merge looped `Add` calls on `List<T>` variables into `AddRange` - `AddRange` will ensure the list is only extended once. 2. Optimize empty string checks - Comparing strings using `String.Length` is faster than using `Equals` ([C# docs reference](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1820?view=vs-2022#rule-description:~:text=Comparing%20strings%20using%20the%20String.Length%20property%20or%20the%20String.IsNullOrEmpty%20method%20is%20faster%20than%20using%20Equals)) 3. Merge position & rotation calls into one - `SetPositionAndRotation` has a small performance improvement ([docs](https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Transform.SetPositionAndRotation.html#:~:text=When%20setting%20both%20the%20position%20and%20rotation%20of%20a%20transform%2C%20calling%20this%20method%20is%20more%20efficient%20than%20assigning%20to%20Transform.position%20and%20Transform.rotation%20individually.)) 4. Short circuit operators for bools - We had a couple of places that were using bytewise operations on boolean properties. This fixes them. 5. Use native Count instead of LINQ - `.Count()` uses LINQ and has a cost. `.Count` does the same thing without the LINQ cost. 6. Use `StringBuilder.AppendJoin` rather than `StringBuilder.Append(String.Join` continues: #3680 ## Jira ticket n/a: contribution from external user ### Changelog - Changed: made many very small performance improvements. ## Documentation - Updated the scripting in the docs to use `SetPositionAndRotation` rather than setting the two independently ## Testing & QA (How your changes can be verified during release Playtest) - These do not change functionality. Automated testing should catch any compiler errors. _Does the change require QA team to:_ - [ ] `Review automated tests`? - [ ] `Execute manual tests`? - [ ] `Provide feedback about the PR`? If any boxes above are checked the QA team will be automatically added as a PR reviewer. ## Backports These are small performance improvements so they do not need to be backported. --------- Co-authored-by: Dylan Smit <[email protected]> Co-authored-by: Unity Netcode CI <[email protected]>
Purpose of this PR
I found some simple performance improvement, which do not change any functionality. Especially the position and rotation calls and LINQ call removals are very helpful for performance
Changelog
Improved runtime and editor performance
Documentation
Testing & QA (How your changes can be verified during release Playtest)
These do not change functionality
Does the change require QA team to:
Review automated tests
?Execute manual tests
?Provide feedback about the PR
?If any boxes above are checked the QA team will be automatically added as a PR reviewer.