Skip to content

Commit

Permalink
Merge pull request unoplatform#15415 from unoplatform/dev/jela/perf-u…
Browse files Browse the repository at this point in the history
…pdate4

perf: Avoid interpreter transition in SetTargetValueSafe
  • Loading branch information
jeromelaban authored Feb 9, 2024
2 parents 2ee46d4 + 744f6eb commit c147dc1
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/Uno.UI/DataBinding/BindingExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -668,32 +668,39 @@ private void SetTargetValueSafe(object v, bool useTargetNullValue)

if (FeatureConfiguration.BindingExpression.HandleSetTargetValueExceptions)
{
SetTargetValueSafeWithTry(v, useTargetNullValue);
try
{
InnerSetTargetValueSafe(v, useTargetNullValue);

/// <remarks>
/// This method contains or is called by a try/catch containing method and
/// can be significantly slower than other methods as a result on WebAssembly.
/// See https://github.com/dotnet/runtime/issues/56309
/// </remarks>
void SetTargetValueSafeWithTry(object v, bool useTargetNullValue)
// Avoid using the finally clause, which on wasm
// causes a transition to the interpreter. Exceptions here
// are caught entirely, and not forwarded to the caller, which
// allows for resetting the value in both the normal and exceptional flow.
_IsCurrentlyPushing = false;
}
catch (Exception e)
{
if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Error))
{
this.Log().Error("Failed to apply binding to property [{0}] on [{1}] ({2})".InvariantCultureFormat(TargetPropertyDetails, _targetOwnerType, e.Message), e);
}

try
{
InnerSetTargetValueSafe(v, useTargetNullValue);
ApplyFallbackValue();
}
catch (Exception e)
catch (Exception e2)
{
// We ensure that _IsCurrentlyPushing can properly be reset, even
// if `ApplyFallbackValue` fails to execute.

if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Error))
{
this.Log().Error("Failed to apply binding to property [{0}] on [{1}] ({2})".InvariantCultureFormat(TargetPropertyDetails, _targetOwnerType, e.Message), e);
this.Log().Error("Failed to apply fallback value to property [{0}] on [{1}] ({2})".InvariantCultureFormat(TargetPropertyDetails, _targetOwnerType, e2.Message), e2);
}

ApplyFallbackValue();
}
finally
{
_IsCurrentlyPushing = false;
}

_IsCurrentlyPushing = false;
}
}
else
Expand Down

0 comments on commit c147dc1

Please sign in to comment.