-
Notifications
You must be signed in to change notification settings - Fork 459
chore: Small performance improvements #3683
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
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
… into fix/performance-optimizations
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.
Two minor areas to review over.
The rest looks good to me. 👍
m_ServerAddressProperty = connectionDataProperty.FindPropertyRelative(nameof(UnityTransport.ConnectionAddressData.Address)); | ||
m_ServerPortProperty = connectionDataProperty.FindPropertyRelative(nameof(UnityTransport.ConnectionAddressData.Port)); | ||
m_OverrideBindIpProperty = connectionDataProperty.FindPropertyRelative(nameof(UnityTransport.ConnectionAddressData.ServerListenAddress)); | ||
connectionDataProperty.FindPropertyRelative(nameof(UnityTransport.ConnectionAddressData.ServerListenAddress)); |
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.
It seems that this last adjusted line is not used... and the property found is not being assigned to anything.
Is there a reason to keep this line?
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.
Thanks for catching that. The m_OverrideBindIpProperty
was never being used anywhere so I pulled it out, but obviously not very thoroughly
|
||
ClientPositionVisual.transform.position = m_ClientPosition; | ||
ClientPositionVisual.transform.rotation = InLocalSpace ? transform.localRotation : transform.rotation; | ||
var rotation = InLocalSpace ? transform.localRotation : transform.rotation; |
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.
This still needs to use the m_ClientPosition.
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.
It's using m_ClientPosition
on the next line down 😄
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.
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
Add
calls onList<T>
variables intoAddRange
AddRange
will ensure the list is only extended once.String.Length
is faster than usingEquals
(C# docs reference)SetPositionAndRotation
has a small performance improvement (docs).Count()
uses LINQ and has a cost..Count
does the same thing without the LINQ cost.StringBuilder.AppendJoin
rather thanStringBuilder.Append(String.Join
continues: #3680
Jira ticket
n/a: contribution from external user
Changelog
Documentation
SetPositionAndRotation
rather than setting the two independentlyTesting & QA (How your changes can be verified during release Playtest)
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.