perf: Application.isPlaying in hot path is slow (#3210)

This showed up during a recent il2cpp profile and is accounting for 1% of total cpu usage while being completely unnecessary outside of the editor
https://share.dl.je/2022/08/2022-08-28_14-44-14_CfEcmlR1L6.png
This commit is contained in:
Robin Rolf 2022-09-01 13:58:32 +02:00 committed by GitHub
parent aac75491ac
commit 17446f3aa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -968,7 +968,11 @@ internal NetworkIdentitySerialization GetSerializationAtTick(int tick)
// (otherwise [SyncVar] changes would never be serialized in tests) // (otherwise [SyncVar] changes would never be serialized in tests)
// //
// NOTE: != instead of < because int.max+1 overflows at some point. // NOTE: != instead of < because int.max+1 overflows at some point.
if (lastSerialization.tick != tick || !Application.isPlaying) if (lastSerialization.tick != tick
#if UNITY_EDITOR
|| !Application.isPlaying
#endif
)
{ {
// reset // reset
lastSerialization.ownerWriter.Position = 0; lastSerialization.ownerWriter.Position = 0;