perf: Optimize performance for status view

This commit is contained in:
2025-03-24 00:06:51 +08:00
parent a2ef175a81
commit 074a58dabd

View File

@@ -1,4 +1,5 @@
using System.Globalization;
using System.Text;
using TMPro;
using UnityEngine;
@@ -11,17 +12,30 @@ namespace Cryville.EEW.Unity.UI {
_textView = GetComponent<TMP_Text>();
}
StringBuilder _sb = new();
char[] _buffer = new char[256];
void Update() {
_textView.text = string.Format(
_sb.Clear();
_sb.AppendFormat(
CultureInfo.InvariantCulture,
"FPS: i{0:0} / s{1:0}\nSMem: {2:N0} / {3:N0}\nIMem: {4:N0} / {5:N0}",
"FPS: i{0:0} / s{1:0}\n",
1 / Time.deltaTime,
1 / Time.smoothDeltaTime,
1 / Time.smoothDeltaTime
);
_sb.AppendFormat(
CultureInfo.InvariantCulture,
"SMem: {0:N0} / {1:N0}\n",
UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong(),
UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong(),
UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong()
);
_sb.AppendFormat(
CultureInfo.InvariantCulture,
"IMem: {0:N0} / {1:N0}",
UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong(),
UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong()
);
_sb.CopyTo(0, _buffer, _sb.Length);
_textView.SetText(_buffer, 0, _sb.Length);
}
}
}