Repository navigation
Skip unchanged renders for rebuilt animation declarations #1710
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
Merged
Alexandre Zollinger Chohfi (azchohfi)
merged 10 commits into
main
from
azchohfi-animation-extras-rerender-skip
Nov 26, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c2291bd
Skip unchanged renders for rebuilt animation declarations (#1702)
azchohfi a461b85
Address review findings for the animation skip fix (#1702)
azchohfi 6eb8a86
Merge remote-tracking branch 'origin/main' into azchohfi-animation-ex…
azchohfi 82b8624
Address review round 1
azchohfi f344112
Merge origin/main; address review round 2
azchohfi e2073bf
Merge remote-tracking branch 'origin/main' into azchohfi-animation-ex…
azchohfi 2ffc65b
Address review round 4
azchohfi 460c392
Address review round 5
azchohfi 1eb24e9
Merge remote-tracking branch 'origin/main' into azchohfi-animation-ex…
azchohfi 85222b7
Merge remote-tracking branch 'origin/main' into azchohfi-animation-ex…
azchohfi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| using System.Runtime.CompilerServices; | ||
| using Microsoft.UI.Xaml; | ||
| using Microsoft.UI.Xaml.Media.Animation; | ||
| using XamlTransition = Microsoft.UI.Xaml.Media.Animation.Transition; | ||
|
|
||
| namespace Microsoft.UI.Reactor.Animation; | ||
|
|
||
| /// <summary> | ||
| /// Value equality for animation declarations that modifiers rebuild on every render (issue #1702). | ||
| /// Element skip checks compare these, so two renders that declare the same animation compare | ||
| /// equal even though each allocated fresh arrays and WinUI objects. Unknown WinUI types fall | ||
| /// back to reference equality. Reading WinUI objects requires the UI thread, like reconcile. | ||
| /// </summary> | ||
| internal static class AnimationEquality | ||
| { | ||
| internal static bool SequenceEqual<T>(T[]? a, T[]? b) | ||
| { | ||
| if (ReferenceEquals(a, b)) return true; | ||
| if (a is null || b is null || a.Length != b.Length) return false; | ||
| var comparer = EqualityComparer<T>.Default; | ||
| for (int i = 0; i < a.Length; i++) | ||
| if (!comparer.Equals(a[i], b[i])) return false; | ||
| return true; | ||
| } | ||
|
|
||
| internal static int SequenceHash<T>(T[]? items) | ||
| { | ||
| if (items is null) return 0; | ||
| var hash = new HashCode(); | ||
| foreach (var item in items) hash.Add(item); | ||
| return hash.ToHashCode(); | ||
| } | ||
|
|
||
| /// <summary>Equality for the implicit transitions behind <c>.OpacityTransition()</c> and friends.</summary> | ||
| internal static bool ImplicitTransitionEqual(object? a, object? b) | ||
| { | ||
| if (ReferenceEquals(a, b)) return true; | ||
| return (a, b) switch | ||
| { | ||
| (ScalarTransition sa, ScalarTransition sb) => sa.Duration == sb.Duration, | ||
| (Vector3Transition va, Vector3Transition vb) => va.Duration == vb.Duration && va.Components == vb.Components, | ||
| (BrushTransition ba, BrushTransition bb) => ba.Duration == bb.Duration, | ||
| _ => false, | ||
| }; | ||
| } | ||
|
|
||
| internal static bool ThemeTransitionsEqual(XamlTransition[]? a, XamlTransition[]? b) | ||
| { | ||
| if (ReferenceEquals(a, b)) return true; | ||
| if (a is null || b is null || a.Length != b.Length) return false; | ||
| for (int i = 0; i < a.Length; i++) | ||
| if (!ThemeTransitionEqual(a[i], b[i])) return false; | ||
| return true; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Equality for WinUI's theme transitions, by type and settable properties. A transition type | ||
| /// missing from this table compares by reference, which only costs a skipped update. | ||
| /// </summary> | ||
| private static bool ThemeTransitionEqual(XamlTransition? a, XamlTransition? b) | ||
| { | ||
| if (ReferenceEquals(a, b)) return true; | ||
| return (a, b) switch | ||
| { | ||
| (EntranceThemeTransition ea, EntranceThemeTransition eb) => | ||
| ea.FromHorizontalOffset == eb.FromHorizontalOffset && ea.FromVerticalOffset == eb.FromVerticalOffset | ||
|
azchohfi marked this conversation as resolved.
Resolved
|
||
| && ea.IsStaggeringEnabled == eb.IsStaggeringEnabled, | ||
| (ContentThemeTransition ca, ContentThemeTransition cb) => | ||
| ca.HorizontalOffset == cb.HorizontalOffset && ca.VerticalOffset == cb.VerticalOffset, | ||
|
azchohfi marked this conversation as resolved.
Resolved
azchohfi marked this conversation as resolved.
Resolved
|
||
| (PopupThemeTransition pa, PopupThemeTransition pb) => | ||
| pa.FromHorizontalOffset == pb.FromHorizontalOffset && pa.FromVerticalOffset == pb.FromVerticalOffset, | ||
|
azchohfi marked this conversation as resolved.
Resolved
azchohfi marked this conversation as resolved.
Resolved
|
||
| (RepositionThemeTransition ra, RepositionThemeTransition rb) => ra.IsStaggeringEnabled == rb.IsStaggeringEnabled, | ||
| (EdgeUIThemeTransition ea, EdgeUIThemeTransition eb) => ea.Edge == eb.Edge, | ||
| (PaneThemeTransition pa, PaneThemeTransition pb) => pa.Edge == pb.Edge, | ||
| (NavigationThemeTransition na, NavigationThemeTransition nb) => | ||
| NavigationInfoEqual(na.DefaultNavigationTransitionInfo, nb.DefaultNavigationTransitionInfo), | ||
| (AddDeleteThemeTransition, AddDeleteThemeTransition) => true, | ||
| (ReorderThemeTransition, ReorderThemeTransition) => true, | ||
| _ => false, | ||
| }; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Navigation transition infos compare by type and setting. A continuum transition names | ||
| /// an exit element, so it compares by reference. | ||
| /// </summary> | ||
| private static bool NavigationInfoEqual(NavigationTransitionInfo? a, NavigationTransitionInfo? b) | ||
| { | ||
| if (ReferenceEquals(a, b)) return true; | ||
| return (a, b) switch | ||
| { | ||
| (SlideNavigationTransitionInfo sa, SlideNavigationTransitionInfo sb) => sa.Effect == sb.Effect, | ||
| (CommonNavigationTransitionInfo ca, CommonNavigationTransitionInfo cb) => ca.IsStaggeringEnabled == cb.IsStaggeringEnabled, | ||
| (DrillInNavigationTransitionInfo, DrillInNavigationTransitionInfo) => true, | ||
| (EntranceNavigationTransitionInfo, EntranceNavigationTransitionInfo) => true, | ||
| (SuppressNavigationTransitionInfo, SuppressNavigationTransitionInfo) => true, | ||
| _ => false, | ||
| }; | ||
| } | ||
|
|
||
| /// <summary>Hash for a value compared by reference.</summary> | ||
| internal static int IdentityHash(object? value) => value is null ? 0 : RuntimeHelpers.GetHashCode(value); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// An array compared by its elements, for array-valued animation declarations held in | ||
| /// <see cref="Core.AnimationExtras"/>. | ||
| /// </summary> | ||
| internal readonly struct ValueArray<T>(T[]? items) : IEquatable<ValueArray<T>> | ||
| { | ||
| internal T[]? Items { get; } = items; | ||
|
|
||
| public bool Equals(ValueArray<T> other) => AnimationEquality.SequenceEqual(Items, other.Items); | ||
|
|
||
| public override bool Equals(object? obj) => obj is ValueArray<T> other && Equals(other); | ||
|
|
||
| public override int GetHashCode() => AnimationEquality.SequenceHash(Items); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.