Reduced debug overhead of Events (#435)

* fix: memory allocations due to boxing when creating a StackTraceEntry with disabled DebugMode.
fix: slow repeaded lookups of EditorPrefs for determining DebugMode

* Cleaning up code that was affected by work on #434

- removed dead code
- fixed formatting

Commit-Type: Refactor
This commit is contained in:
Soraphis 2023-12-19 05:11:30 +01:00 committed by GitHub
parent 4576277a19
commit 7d9bb753ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View File

@ -24,18 +24,25 @@ namespace UnityAtoms
public class BoolPreference : Preference<bool>
{
private bool? _cached = null;
public override bool Get()
{
if (_cached != null) return _cached.Value;
if (!EditorPrefs.HasKey(Key))
{
EditorPrefs.SetBool(Key, DefaultValue);
_cached = DefaultValue;
return _cached.Value;
}
return EditorPrefs.GetBool(Key);
_cached = EditorPrefs.GetBool(Key);
return _cached.Value;
}
public override void Set(bool value)
{
_cached = value;
EditorPrefs.SetBool(Key, value);
}
}

View File

@ -61,12 +61,12 @@ namespace UnityAtoms
}
#if UNITY_EDITOR
public static StackTraceEntry Create(object obj, int skipFrames = 0) => AtomPreferences.IsDebugModeEnabled ? new StackTraceEntry(new StackTrace(skipFrames), obj) : null;
public static StackTraceEntry Create<T>(T obj, int skipFrames = 0) => AtomPreferences.IsDebugModeEnabled ? new StackTraceEntry(new StackTrace(skipFrames), obj) : null;
public static StackTraceEntry Create(int skipFrames = 0) => AtomPreferences.IsDebugModeEnabled ? new StackTraceEntry(new StackTrace(skipFrames)) : null;
#else
public static StackTraceEntry Create(object obj, int skipFrames = 0) => null;
#else
public static StackTraceEntry Create<T>(T obj, int skipFrames = 0) => null;
public static StackTraceEntry Create(int skipFrames = 0) => null;
#endif

View File

@ -11,6 +11,7 @@ namespace UnityAtoms
public static void AddStackTrace(int id, StackTraceEntry stackTrace)
{
if (stackTrace == null) return;
if (AtomPreferences.IsDebugModeEnabled)
{
GetStackTraces(id).Insert(0, stackTrace);