About guide that comparison to null is expensive

If we consider the comparison of native C# objects for null, it takes around 13ms.

When we examine the behavior within the UnityEditor:
Case 1: Comparing a null GameObject takes about 585ms.
Case 2: Comparing a null MonoBehaviour takes approximately 139ms.

On the other hand, in the AOS IL2CPP environment:
Case 1: Comparing a null GameObject takes around 32ms.
Case 2: Comparing a null MonoBehaviour also takes about 32ms.

I agree that the guide about null comparison being expensive holds true in the UnityEditor environment. However, I believe it might not be necessary in the build environment. It seems to be applicable only when you perform a vast number of comparisons with UnityEngine.Object instances, which is likely to be an exceptional situation.

0
1 comment

Hello Jungu Kang,

Thank you for the feedback. We are planning to improve null comparison inspections in Unity in the upcoming releases. Please upvote and follow issue RIDER-79739 Improve null comparison handling with Unity objects. 

0

Please sign in to leave a comment.