react-native-windows icon indicating copy to clipboard operation
react-native-windows copied to clipboard

TransferProperties should be Pay-for-Play

Open stecrain opened this issue 7 years ago • 4 comments

Currently TransferProperties (especially notable in FrameworkElementViewManager) attempts to transfer every possible property, even if the property is not set.

Ideally this should be pay-for-play, the shadow node can keep track of what properties have actually been set.

Comparing 59.34 with 59.104 the cost of TransferProperties has doubled. 23ms to 49ms in my app.

before: image

after: image

Traces and symbols here: \scratch2\scratch\stecrain\TransferProperties

stecrain avatar Jul 25 '19 23:07 stecrain

A large new addition to the TransferProperties function is all of the dynamic automation properties for accessibility.

Accessibility is important, but we should be able to avoid paying the cost of transferring these properties when they haven't been set. Lots of this is the cost of transferring empty values.

stecrain avatar Jul 26 '19 02:07 stecrain

There appears to be a potentially bigger issue here where we may be calling TranserProperties more often than necessary because of how often we may be switching the underlying View - this is worthy of investigation in and of itself. @StephenLPeters - can you take a look at this aspect.

The micro-optimizations that @stecrain has pointed out are also good to do. Perhaps @stecrain can complete those.

harinikmsft avatar Jul 31 '19 19:07 harinikmsft

@harinikmsft you're right. why TransferProperties is being called is likely more important than actually making TransferProperties faster.

@StephenLPeters I was starting to look into why TransferProperties is being called so much, and I have some intuition about it but I have not proven it 100% yet. I believe that there is an opportunity to optimize focusable view creation. I see TransferProperties being called quite a bit during startup of my app, and I believe the sequence is something like this.

  • View is created
  • Some arbitrary props are set
  • Props now get set which make the view Focusable (requiring Xaml tree manipulation and Parenting the panel in a ContentControl)
  • TransferProperties is called to move properties from the Panel to the ContentControl.

In my app code I am using TouchableOpacity, and not dynamically modifying any props that would influence whether it is focusable or not.

It looks like looping through the react diff map in ViewViewManager::UpdateProperties and calling ViewViewManager::TryUpdateView after setting all the props has the undesirable consequence of always transferring the props when creating a focusable view. Happy to chat more about this issue

stecrain avatar Aug 02 '19 14:08 stecrain

Not something we plan to address on the Paper renderer as we move towards Fabric. Not sure if this behavior is still applicable on the Fabric renderer. If so, we'd want a fresh analysis.

chrisglein avatar Aug 30 '23 20:08 chrisglein