Skip to content

Conversation

@rozele
Copy link
Contributor

@rozele rozele commented Sep 14, 2022

Description

Type of Change

Erase all that don't apply.

  • Perf (non-breaking change which improves performance)

Why

Recalculation of Yoga layout due to root view size change does not require that we re-run layout on all roots. It also does not require that we invoke UpdateLayout on any new nodes (as a resize operation is independent of a batch of UIManager operations).

What

This change limits the scope of Yoga calculation and application of Yoga results to XAML views to only the root view that changed size. This optimization primarily impacts apps with multiple windows, but can also benefit any React Native Windows app with multiple roots.

In a future PR, we could also track impacted roots in view manager operations by looking up the rootTag field on the ShadowNode, and only running Yoga layout on windows with actual updates in a given batch.

Testing

Ran RNTester, window resize still adapts correctly.

2022-09-14.15-30-18.mp4
Microsoft Reviewers: Open in CodeFlow

@rozele rozele requested review from a team as code owners September 14, 2022 18:57
@rozele rozele marked this pull request as draft September 14, 2022 18:57
@rozele rozele marked this pull request as ready for review September 14, 2022 19:31
@rozele rozele force-pushed the resizeOptimization branch from 195232b to af30530 Compare October 4, 2022 15:22
@rozele rozele requested a review from a team as a code owner October 4, 2022 15:22
@rozele rozele marked this pull request as draft October 4, 2022 15:23
@rozele
Copy link
Contributor Author

rozele commented Oct 4, 2022

Marking as draft until #10671 merges and we can rebase this PR.

@rozele rozele force-pushed the resizeOptimization branch from af30530 to 2c8a5b0 Compare October 22, 2022 02:06
rozele added 2 commits April 2, 2023 18:04
Recalculation of Yoga layout due to root view size change does not
require that we re-run layout on all roots. It also does not require
that we invoke UpdateLayout on any new nodes (as a resize operation is
independent of a batch of UIManager operations).

This change limits the scope of Yoga calculation and application of Yoga
results to XAML views to only the root view that changed size. This
optimization primarily impacts apps with multiple windows, but can also
benefit any React Native Windows app with multiple roots.
@rozele rozele force-pushed the resizeOptimization branch from 2c8a5b0 to dedbbac Compare April 2, 2023 22:06
@rozele rozele marked this pull request as ready for review April 2, 2023 22:06
@chiaramooney chiaramooney requested a review from acoates-ms April 12, 2023 22:30
m_sizeChangedVector.push_back(
view.as<xaml::FrameworkElement>().SizeChanged(winrt::auto_revoke, [this](auto &&, auto &&) { DoLayout(); }));
m_sizeChangedVector.push_back(view.as<xaml::FrameworkElement>().SizeChanged(
winrt::auto_revoke, [this, rootTag](auto &&, xaml::SizeChangedEventArgs const &args) {
Copy link
Member

Choose a reason for hiding this comment

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

Is it safe to capture rootTag, or should it be a weak_ref? Is there a scenario where this thing gets torn down and we need to care about this SizeChanged event firing? Probably not?

I noticed that m_sizeChangedVector doesn't have the element removed in removeRootView. Preexisting, but... given that you're capturing a value now it made me wonder if that's all buttoned up.

view.as<xaml::FrameworkElement>().SizeChanged(winrt::auto_revoke, [this](auto &&, auto &&) { DoLayout(); }));
m_sizeChangedVector.push_back(view.as<xaml::FrameworkElement>().SizeChanged(
winrt::auto_revoke, [this, rootTag](auto &&, xaml::SizeChangedEventArgs const &args) {
ApplyLayout(rootTag, args.NewSize().Width, args.NewSize().Height);
Copy link
Member

Choose a reason for hiding this comment

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

This is slightly different than what was there before. This takes the size right from the size changed event. The previous implementation (via DoLayout) would use the ActualSize of the XAML type. Are those for sure the same? Sounds like... sure? In which case this is fine. Just checking.

@chiaramooney chiaramooney merged commit 684db13 into microsoft:main May 30, 2023
@rozele rozele deleted the resizeOptimization branch June 1, 2023 13:33
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.

4 participants