Skip to content

Commit

Permalink
perf: Remove ObjectId from DependencyObjectStore
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Sep 10, 2024
1 parent d427c31 commit cb16b0d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/DependencyObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal static AttachedDependencyObject GetAttachedDependencyObject(object inst
/// <returns>A unique ID</returns>
internal static long GetDependencyObjectId(this object dependencyObject)
{
return GetStore(dependencyObject).ObjectId;
return GetStore(dependencyObject).GetHashCode();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/DependencyObjectStore.Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private void ApplyDataContext(object? actualDataContext)
}

private object?[] GetTraceProperties()
=> new object?[] { ObjectId, _originalObjectType?.ToString() };
=> new object?[] { GetHashCode(), _originalObjectType?.ToString() };


public void SetBinding(object target, string dependencyProperty, BindingBase binding)
Expand Down
19 changes: 3 additions & 16 deletions src/Uno.UI/UI/Xaml/DependencyObjectStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ public static class TraceProvider

private static readonly IEventProvider _trace = Tracing.Get(TraceProvider.Id);

/// <summary>
/// A global static counter that is used to uniquely identify objects.
/// This is primarily used during trace profiling.
/// </summary>
private static long _objectIdCounter;

private bool _isDisposed;

private readonly DependencyPropertyDetailsCollection _properties;
Expand Down Expand Up @@ -184,8 +178,6 @@ internal void ClonePropertiesToAnotherStoreForHotReload(DependencyObjectStore ot
/// <param name="originalObject"></param>
public DependencyObjectStore(object originalObject, DependencyProperty dataContextProperty, DependencyProperty templatedParentProperty)
{
ObjectId = Interlocked.Increment(ref _objectIdCounter);

_originalObjectRef = WeakReferencePool.RentWeakReference(this, originalObject);
_originalObjectType = originalObject is AttachedDependencyObject a ? a.Owner.GetType() : originalObject.GetType();

Expand All @@ -198,7 +190,7 @@ public DependencyObjectStore(object originalObject, DependencyProperty dataConte
{
_trace.WriteEvent(
DependencyObjectStore.TraceProvider.CreationTask,
new object[] { ObjectId, _originalObjectType.Name }
new object[] { GetHashCode(), _originalObjectType.Name }
);
}
}
Expand Down Expand Up @@ -235,11 +227,6 @@ private void Dispose(bool disposing)

internal bool IsTemplatedParentFrozen { get; set; }

/// <summary>
/// Gets a unique identifier for the current DependencyObject.
/// </summary>
internal long ObjectId { get; }

/// <summary>
/// Returns the current effective value of a dependency property from a DependencyObject.
/// </summary>
Expand Down Expand Up @@ -776,7 +763,7 @@ private void WritePropertyEventTrace(int eventId, DependencyProperty property, D
{
if (_trace.IsEnabled)
{
_trace.WriteEvent(eventId, new object[] { ObjectId, property.OwnerType.Name, property.Name, precedence?.ToString() ?? "Local" });
_trace.WriteEvent(eventId, new object[] { GetHashCode(), property.OwnerType.Name, property.Name, precedence?.ToString() ?? "Local" });
}
}

Expand All @@ -787,7 +774,7 @@ private void WritePropertyEventTrace(int eventId, DependencyProperty property, D
return _trace.WriteEventActivity(
startEventId,
stopEventId,
new object[] { ObjectId, property.OwnerType.Name, property.Name, precedence.ToString() }
new object[] { GetHashCode(), property.OwnerType.Name, property.Name, precedence.ToString() }
);
}
else
Expand Down

0 comments on commit cb16b0d

Please sign in to comment.