diff --git a/src/Avalonia.Input/InputElement.cs b/src/Avalonia.Input/InputElement.cs index 4b4ab177b8..47e85416cf 100644 --- a/src/Avalonia.Input/InputElement.cs +++ b/src/Avalonia.Input/InputElement.cs @@ -565,9 +565,17 @@ namespace Avalonia.Input { IsEffectivelyEnabled = IsEnabledCore && (parent?.IsEffectivelyEnabled ?? true); - foreach (var child in this.GetVisualChildren().OfType()) + // PERF-SENSITIVE: This is called on entire hierarchy and using foreach or LINQ + // will cause extra allocations and overhead. + + var children = VisualChildren; + + // ReSharper disable once ForCanBeConvertedToForeach + for (int i = 0; i < children.Count; ++i) { - child.UpdateIsEffectivelyEnabled(this); + var child = children[i] as InputElement; + + child?.UpdateIsEffectivelyEnabled(this); } } }