Skip to content

Fix shallow comparison of animation extras - #1552

Merged
Alexandre Zollinger Chohfi (azchohfi) merged 3 commits into
microsoft:mainfrom
PaperHammer:fix/issue1536-animation-extras-equality
Nov 18, 2026
Merged

Alexandre Zollinger Chohfi (azchohfi) merged 3 commits into
microsoft:mainfrom
PaperHammer:fix/issue1536-animation-extras-equality

Conversation

@PaperHammer

Copy link
Copy Markdown
Contributor

Summary

Changing only an animation or transition configuration can currently be skipped when an element's ordinary properties remain unchanged. For example, a Border with the same child can keep its 200 ms layout animation after a later render specifies 800 ms.

This change groups all animation declarations into one internal record and compares that group in Element.ShallowEquals. Configuration changes now reach both direct updates and parent child-skip paths, while equivalent declarations remain eligible for skipping.

Linked issue / spec

Fixes #1536.

Follow-up to #1499. Related design: spec 014.

Approach

  • Move the 10 animation-related fields into an internal readonly record struct AnimationExtras.
  • Keep the existing public Element and ElementExtras properties as forwarding get/init properties.
  • Compare the group using its compiler-generated, typed Equals.
  • Use the same generated equality against default when checking whether the animation group is empty.

Adding a configuration field to this group automatically includes it in equality, hashing, and empty-group detection. This avoids maintaining a separate field-by-field comparison list.

Existing semantics are preserved:

  • Arrays retain reference equality.
  • Configuration records retain their existing value equality.
  • with copies preserve other configuration references and leave the original record unchanged.
  • Attached properties, theme bindings, resource overrides, and context values retain their existing comparison helpers.
  • CallSite remains excluded from behavioral equality.

Runtime changes are confined to Element.cs. Tests, the animation guide template and generated guide, and the changelog are updated.

Why record struct

Both record-class and record-struct prototypes were measured.

The struct embeds the same 10 reference fields directly inside ElementExtras, without allocating a separate group object. The existing 152-byte ElementExtras allocation remains unchanged, and all measured construction scenarios retain main's allocation and managed retained-memory costs.

The class prototype reduces the size of buckets without animation declarations, but animated elements retain an additional group object. In the measured animation scenarios, this adds approximately 24 bytes of retained memory per element and additional construction allocations.

The struct was selected to preserve allocation behavior. It still has copying and comparison costs; it is not assumed to be faster in every scenario. The exported public API, including init accessors and nullability metadata, was verified unchanged.

Performance

Local microbenchmarks compared main at 3a17f925, the record-class prototype, and the selected record-struct implementation.

All variants used the same Release benchmark assembly, replacing only Reactor.dll. Measurements used Windows x64, .NET 10 runtime 10.0.12, SDK 11.0.100, and DOTNET_TieredCompilation=0.

The tables report medians from nine interleaved fresh-process runs per variant, following a discarded warm-up round. Timed loops exclude process startup.

The mixed scenario combines Grid, LayoutAnimation, Animate, InteractionStates, Stagger, and Transition.

Scenario / operation Main (ns/op) Record class (ns/op) Record struct (ns/op)
Attached properties — construction 148.6 133.1 163.0
Animate — construction 138.0 164.5 143.9
Mixed — construction 515.9 527.2 544.0
Animate — shallow comparison 64.8 62.9 63.6
Mixed — shallow comparison 85.3 135.3 136.5

The mixed comparison now checks declarations that main omitted, so its additional comparison time is expected. All measured shallow comparisons allocate 0 B/op.

The following values are allocated B/op / retained managed B per element:

Scenario Main Record class Record struct
Plain Button 88 / 87.7 88 / 87.7 88 / 87.7
Attached properties 392 / 298.0 320 / 227.2 392 / 298.0
Animate 400 / 305.9 424 / 328.0 400 / 305.9
Mixed 1952 / 624.0 2000 / 648.0 1952 / 624.0

Retained memory was measured after full GC with 20,000 retained elements, excluding the root array. It represents managed live memory, not process RSS or native compositor memory.

Test plan

Regression coverage includes:

  • Equivalent, changed, and removed configurations.
  • Shared arrays versus distinct arrays with equal contents.
  • Copying and clearing one configuration while preserving other extras and the original record.
  • Metadata-only bucket normalization and equality/hash consistency.
  • Direct Update and parent child-skip against actual WinUI animation durations.
  • Scroll configuration comparisons using a real ScrollViewer.
  • The existing 152-byte Extras allocation guard.

The added unit regressions produced 8 failures on unchanged main and all 10 passed with both prototypes.

Validation results:

  • Related unit regressions: 464 passed, 1 skipped.
  • Final targeted native fixtures: 2 fixtures, 24 assertions passed.
  • Release unit-project and native-host builds: passed with 0 warnings and 0 errors.
  • Animation documentation regenerated; a second generation produced no changes.
  • Strict animation topic validation and strict MkDocs build: passed.
  • git diff --check: passed.
  • Full unit suite: 15,734 passed, 18 skipped, 2 failed.

The same two failures were reproduced with the unchanged main DLL:

  • DidYouMeanAnalyzerParityTests.CS1503_string_for_element_fires_in_both_engines
  • SymbolSuggesterTests.CS1503_Element_expected_string_supplied_proposes_text_factory

Broader native regression attempts were interrupted by Host exits with 0xC000027B, including with the unchanged main DLL. The targeted fixtures pass, but the broader native corpus has not been fully validated.

A full solution build, NativeAOT, packaged selftests, and E2E tests were not run.

Risk / breaking changes

  • No public API changes.
  • Configuration changes that were previously skipped now reach the existing update paths.
  • Array contents are not compared deeply; in-place mutation is not newly tracked.
  • Animation execution, pooling, and handoff Visual behavior are unchanged.
  • The broader handoff Visual work remains outside this PR.

)

Group animation declarations in an internal record struct while preserving the public get/init properties and existing field equality semantics. Add unit and native regressions, and update the generated animation guide and changelog.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the animation and transition comparison changes.

No open issues 🎉

What changed in this PR

Fixes #1536 by making Reactor’s shallow comparison account for all animation and transition declarations, so configuration-only changes reach the existing update paths.

Changes:

  • Groups ten animation settings into an internal record struct while preserving public properties and existing equality semantics.
  • Adds unit and native regression coverage for configuration changes, removal, copying, and direct versus parent child-skip updates.
  • Updates the animation guide and changelog to describe the corrected behavior.
File Description
tests/​Reactor.Tests/​AnimationExtrasEqualityTests.cs Tests equality, configuration changes, removal, and copy preservation.
tests/​Reactor.AppTests.Host/​SelfTest/​SelfTestFixtureRegistry.cs Registers two native regression fixtures.
tests/​Reactor.AppTests.Host/​SelfTest/​Fixtures/​AnimateModifierTests.cs Tests live animation updates and scroll configuration comparisons.
src/​Reactor/​Core/​Element.cs Groups animation extras and includes them in shallow comparison and empty-group detection.
docs/​guide/​animation.md Updates the generated guide with configuration-only update behavior.
docs/​_pipeline/​templates/​animation.md.dt Adds the corresponding guide source text.
CHANGELOG.md Records the fix under Unreleased.

Review effort: Balanced

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix. Grouping the fields means the next animation property can't silently fall out of the comparison again, and the allocation numbers are convincing.

One thing on the docs. The CHANGELOG and guide say equivalent configurations still skip, but that's only true for the plain-data configs. OpacityTransition, WithTransitions, Keyframes and ScrollLinked all allocate a new native object or array every render, so those elements never skip now. That's the safe behavior, I'd just narrow the wording so nobody expects a skip there.

Small thing. This also fixes Keyframes triggers being ignored when nothing else on the element changed. Might be worth a line in the CHANGELOG, and a selftest if you have time.

Limit skip wording to value-equivalent plain-data configurations and explain reference equality for native objects and arrays. Strengthen the existing Keyframes selftest to verify that only a trigger change restarts animation on the same Button.
@PaperHammer

Copy link
Copy Markdown
Contributor Author

Thank you for the review and guidance. I’ve clarified the equality wording in the guide and changelog, and documented trigger-only Keyframes playback.

I also strengthened the existing selftest to check that the same Button replays only when its trigger changes. The regression fails on unchanged main and passes with the fix; the related tests pass as well.

The changes are pushed. Could you please take another look when you have time?

@azchohfi

Copy link
Copy Markdown
Collaborator

Thanks, this looks good. The PlaybackRate trick is a nice way to detect a restart without timing anything. I'll approve once CI is green.

@azchohfi
Alexandre Zollinger Chohfi (azchohfi) merged commit 983911c into microsoft:main Nov 18, 2026
42 checks passed
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Nov 26, 2026
* Skip unchanged renders for rebuilt animation declarations (#1702)

Since #1552 the shallow skip compares AnimationExtras with record equality, and
.Keyframes(), .ScrollLinked(), implicit transitions, .WithTransitions() and
.InteractionStates() rebuild arrays and WinUI objects on every render, so an
unchanged element using them never skipped. .ScrollLinked() also restarted its
expressions on every parent render.

The declarations now compare by value: keyframe definitions and arrays,
scroll expressions with the same ScrollViewer, implicit transition durations
and components, theme transition settings per WinUI type, and solid brushes by
color. AnimationExtras stays compiler-generated, so a new field is still
compared. A changed or removed declaration still updates (#1536).

ShallowEquals compares animations after the element's own properties, so an
element that changed anyway doesn't pay for the WinUI reads. An update that
leaves .ScrollLinked() unchanged no longer restarts its expressions unless the
element declares another animation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Address review findings for the animation skip fix (#1702)

- Restart scroll expressions on every non-skipped update again. A modifier
  write on the same channel can replace one, and the value-equality skip
  already avoids the restarts the issue reported.
- Compare keyframe channel owner scopes by sequence, so a skipped equal render
  doesn't block the deferred modifier reset.
- Refresh every element when the "Animation effects" setting changes, since
  implicit transitions apply that gate and equal elements now skip.
- Compare navigation transition infos by type and setting.
- Move brush equality to BrushHelper, and note the UI-thread requirement on
  the public Equals overrides.
- Cover each hand-compared field, and fix the docs and CHANGELOG wording.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Address review round 1

Subscribe to the "Animation effects" notification once, process-wide, in
TransitionEngine, and refresh every registered host through the theme
resource listeners. Chart-free windows and embedded hosts now get the
refresh too, and a palette notification arriving first can't suppress it.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Address review round 4

Before Windows 10 2004 "Animation effects" has no change notification, and
equal elements now skip their updates, so each root pass polls the setting
there and refreshes every host when it moved.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Address review round 5

Before Windows 10 2004 the root pass's own poll drops the key, so the
fixture's equal-render positive control depends on that capability.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Element.ShallowEquals ignores changes to animation extras other than .Animate()

3 participants