Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Add a fast path for GetValue #13848

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/Uno.UI/UI/Xaml/DependencyObjectStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,38 @@ private void Dispose(bool disposing)

ValidatePropertyOwner(property);

// As a performance optimization, avoid creating the property details and try get the value in this fast path.
// We skip attached properties in this fast path as it causes Given_DependencyProperty_AttachedPropagation tests to fail.
if (!property.IsAttached && (propertyDetails ??= _properties.FindPropertyDetails(property)) is null)
{
// Since property details wasn't created, the only possibilities are returning UnsetValue or the default value.
// UnsetValue is returned when we are asked for a non-DefaultValue precedence specific value.
// Otherwise, we calculate the default value, first by calling `GetDefaultValue2`, then from property metadata.
if (isPrecedenceSpecific)
{
Debug.Assert(precedence is not null);
if (precedence != DependencyPropertyValuePrecedences.DefaultValue)
{
return UnsetValue.Instance;
}
}

if (ActualInstance is UIElement uiElement && uiElement.GetDefaultValue2(property, out var defaultValue))
{
return defaultValue;
}

defaultValue = property.GetMetadata(_originalObjectType).DefaultValue;

// Ensures that the default value of non-nullable properties is not null
if (defaultValue == null && !property.IsTypeNullable)
{
defaultValue = property.GetFallbackDefaultValue();
}

return defaultValue;
}

propertyDetails ??= _properties.GetPropertyDetails(property);

return GetValue(propertyDetails, precedence, isPrecedenceSpecific);
Expand Down
Loading