Граф коммитов

3465 Коммитов

Автор SHA1 Сообщение Дата
Samuel Susla bf54f1cae9 Back out "Fix default value for scrollView.contentInsetAdjustmentBehavior"
Summary:
changelog: [internal]

Original commit changeset: 290ae428a720

Original Phabricator Diff: D37881453 (e98a835bfc)

in the original diff I made a mistake. The default value for RN is never, we override it in one of our subclasses.

Reviewed By: cortinico

Differential Revision: D37884715

fbshipit-source-id: 3c5b5ef5550120034e33ae9047292f38159dea3e
2022-07-15 09:54:35 -07:00
Samuel Susla e98a835bfc Fix default value for scrollView.contentInsetAdjustmentBehavior
Summary:
Changelog: [internal]

The dafault UIKit value of `UIScrollView.contentInsetAdjustmentBehavior` is automatic. Fabric had incorrect value never.

source: https://developer.apple.com/documentation/uikit/uiscrollview/2902261-contentinsetadjustmentbehavior?language=objc

This was causing bug for one navigation library that's migrating to Fabric: https://github.com/reactwg/react-native-new-architecture/discussions/43#discussioncomment-2885450

Reviewed By: javache

Differential Revision: D37881453

fbshipit-source-id: 290ae428a720f00ed61f2a3e5c2c9bbf54e1ac6e
2022-07-15 06:42:50 -07:00
Vincent Riemer 1eebbbc803 Implement offsetX/offsetY properties on the PointerEvent interface
Summary:
Changelog: [iOS][Internal] - Implement offsetX/offsetY properties on the PointerEvent interface

Simple diff implementing the offsetX/offsetY properties on PointerEvent — thankfully the touch events already kept track of these so it was mostly a matter of forwarding that data to the pointer events.

Reviewed By: lunaleaps

Differential Revision: D37830139

fbshipit-source-id: 77f33a99393350d32cbe449e6a009bdeb2a12d08
2022-07-14 15:07:18 -07:00
Michael Anthony Leon 753038cf34 Use RuntimeConfig for microtasks
Summary:
Changelog:
[general][change] - Use RuntimeConfig instead of VM Experiment Flag to set up the micro task queue.

Reviewed By: neildhar

Differential Revision: D37353947

fbshipit-source-id: 5c8f35c0a79d70cb0d234e881e55058cffb44ac8
2022-07-13 20:59:16 -07:00
Vincent Riemer 5665a77152 Implement screenX/screenY properties on the PointerEvent interface
Summary:
Changelog: [iOS][Internal] - Implement screenX/screenY properties on the PointerEvent interface

This diff implements the screenX/screenY properties which report the position of a pointer in the device's physical screen coordinates.

Reviewed By: lunaleaps

Differential Revision: D37794415

fbshipit-source-id: 6c39c3651812f99e66b93647579a2935598ef6f2
2022-07-13 18:09:22 -07:00
John Porto c81a3c5242 Pass the correct runtime when disabling the debugger
Summary:
The RN Hermes Inspector keeps a mapping of pageId to
Connection. This mapping is created in the call to
enableDebugging. Later, when disableDebugging is invoked,
the inspector will iterate over the pageId to Connection map
to find which page to is being disabled.

The DecoratedRuntime enables debugging on construction, and
disables on destruction. When disabling debugging, the
DecoratedRuntime then passes the "naked" hermesRuntime,
which in turn gets checked against all connections' runtimes.

It turns our that ```HermesExecutorRuntimeAdapter::getRuntime```
returns the runtime **wrapped** by the DecoratedRuntime, and
not hermesRuntime itself.

This means that no connections match the request for
disabling debugging. Which means the Connection never
gets deleted, which in turns keep its underlying adapter (in
this case, the ```HermesRuntimeExecutorAdapter```) alive,
which has a shared_ptr to the runtime wrapped by the DecoratedRuntime.

Other than effectively leaking this connection (and thus the runtime),
this also causes an issue when the app tries to re-load the page -- at
which point the inspector will remove the old entry from the page to
connection mapping, thus initiating the destruction of the (leaked)
Runtime in a thread other than the thread that created the runtime.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D37809467

fbshipit-source-id: e73caa357a300a0d48e69aa3a1a8b00a97519f24
2022-07-13 10:28:16 -07:00
Pieter De Baets a42170e0f8 Replace SharedProps with Props::Shared
Summary:
Similarly to D37653146 (13a0556aaa), standardize on one type to refer to this.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D37658743

fbshipit-source-id: 9834cfc4bbe4ca1a19f10c2c8718e3f74b88d9b6
2022-07-13 07:09:34 -07:00
Genki Kondo 5a47463e1f Prevent double application of opacity and backgroundColor on text
Summary:
The new props parsing path (introduced in https://www.internalfb.com/diff/D37051020 (af1eae9ea3)) resulted in opacity and backgroundColor being applied twice.

Specifically, the new prop setter path basically results in the ParagraphProps' textAttributes (via ConcreteComponentDescriptor.cloneProps, via ParagraphProps.setProp) to include opacity and backgroundColor, which is not desired as they are both applied again on view.

Similar issue faced in the past: https://www.internalfb.com/diff/D19764144 (8fe6883fea)

Changelog:
[Internal] - Prevent double application of opacity and backgroundColor on text

Reviewed By: ryancat

Differential Revision: D37801663

fbshipit-source-id: 4b5ebe5ff20b80833edb2141df883f33c69ab5d6
2022-07-12 20:01:52 -07:00
Vincent Riemer beca1a1c44 Add x/y & pageX/Y implementations to PointerEvent interface
Summary:
Changelog: [iOS][Internal] - add x/y & pageX/Y implementations to PointerEvent interface

This diff adds the x/y properties, which are defined as aliases of clientX/clientY respectively. In addition this diff adds pageX/pageY which, while not definted as aliases of clientX/clientY, are effectively aliases in React Native since the root view is not scrollable (client and page points only differ on the web when a user has scrolled the document element).

Reviewed By: lunaleaps

Differential Revision: D37766818

fbshipit-source-id: c7ad3750460b1913889c6d1a55b4c1edc6918f5b
2022-07-12 18:10:27 -07:00
Vincent Riemer 5989bca8ae Add twist property to PointerEvent interface
Summary:
Changelog: [iOS][internal] - Add twist property to PointerEvent interface

This adds the twist property to the PointerEvent implementation on iOS which similarly to tangentialPressure doesn't really apply so we default to a hard-coded value of 0.

Reviewed By: lunaleaps

Differential Revision: D37760511

fbshipit-source-id: f1fccfd6b5d07024cea83d86925a9bfc2e6cc8cf
2022-07-12 18:10:27 -07:00
Vincent Riemer 3cc335e615 Add tangentialPressure property to PointerEvent interface
Summary:
Changelog: [iOS][internal] - Add tangentialPressure property to PointerEvent interface

This diff adds the tangentialPressure property to the PointerEvent implementation on iOS. This one is pretty simple considering iOS doesn't have the concept of tangential pressure so we just hard code it to 0 as defined by the spec.

Reviewed By: lunaleaps

Differential Revision: D37759634

fbshipit-source-id: 7ca0e47267f5fde76ace2b96d05ea2e154cb4b8f
2022-07-12 18:10:27 -07:00
Pieter De Baets 13a0556aaa Remove deprecated ShadowNode type aliases
Summary:
Fix todo and inconsistency across codebase. It's better to have just one way to refer to these types.

Changelog: [Internal]

Reviewed By: philIip

Differential Revision: D37653146

fbshipit-source-id: e82f09caa6cd6eec5512b78f413708d9c04a7a83
2022-07-12 04:37:32 -07:00
Kevin Gozali 5e23ed699f Kill unused FBRotatablePhotoPlayer component
Summary:
This component is no longer relevant.

Changelog: [Internal]

Reviewed By: philIip

Differential Revision: D37733807

fbshipit-source-id: 267d69e5ffbb9bf9281f715b3e4e07c1f2f7ca9a
2022-07-08 19:06:39 -07:00
Vincent Riemer e89874c563 Add implementation of buttons property to PointerEvent interface
Summary:
Changelog: [iOS][Internal] - Add `buttons` implementation to the PointerEvent interface

This diff adds an implementation of the `buttons` property by leveraging `UIEvent`'s `buttonMask` property.

Reviewed By: lunaleaps

Differential Revision: D37430270

fbshipit-source-id: 69fd3aebcb403e665349a24283a04c0eb82ff3e2
2022-07-08 13:33:04 -07:00
Luna Wei 1753e7697d Fix: Ensure forms stacking context for events
Summary: Changelog: [Internal] - If any relevant view events (pointer, touch events, gesture responder, etc.) are declared on view, then the view must form stacking context. We need this change for pointer events specifically to determine whether we've entered/exited a view

Reviewed By: vincentriemer

Differential Revision: D37678352

fbshipit-source-id: 02641549ef608b1c9468ac693c7da629143212cb
2022-07-08 13:11:56 -07:00
Luna Wei d473881bd7 Fix: Clean up duplicate prop conversions
Summary: Changelog: [Internal] - Clean up duplicate properties from pointer event rename

Reviewed By: javache

Differential Revision: D37662527

fbshipit-source-id: f310d16103f12cdfe4e02546ea156553c9cd5443
2022-07-08 13:11:56 -07:00
John Porto 11bae63bb1 Add BigInt skeleton
Summary:
Adds a jsi::BigInt skeleton.

Changelog:
[General][Added] jsi::BigInt

Reviewed By: kodafb

Differential Revision: D35706101

fbshipit-source-id: 435b108050279ff30953b3e209cdc2f0ff84f40b
2022-07-08 11:40:33 -07:00
Pieter De Baets b4e6a786b7 Use preprocessor flags to set CREATE_SHARED_LIBRARY instead of mode file
Summary: Changelog: [Internal]

Reviewed By: MartinSherburn

Differential Revision: D37600540

fbshipit-source-id: 40cf30ec2960864fc862c31661b1308c57f33bec
2022-07-08 08:41:05 -07:00
Ron Edelstein 0d915aa942 Explicitly set language to JAVA where it is missing [xplat] (round 1)
Reviewed By: IanChilds

Differential Revision: D37594044

fbshipit-source-id: 0bbcaaed951a212651d3cc0fc3371751ced13852
2022-07-06 09:07:07 -07:00
Luna Wei 8be49e8746 PointerEvents: Remove '2' suffix
Summary: Changelog: [Internal] - We can now remove the '2' suffix as we had an internal implementation that was not truly aligned with W3C pointers but used the same name. We have aligned the internal types to match w3c so we can now remove the suffix that differentiates them.

Reviewed By: vincentriemer

Differential Revision: D37545813

fbshipit-source-id: 6f2336ae9e314066c340161113268c1f28621a71
2022-07-05 20:00:42 -07:00
Pieter De Baets 71e89213aa Make ReactCommon and tests compile for CXX platform
Summary:
If you don't list `Cxx` as a supported platform, we will use Android builds, even when using `buck run` for local execution.

Changelog: [Internal]

Reviewed By: derolf

Differential Revision: D37600464

fbshipit-source-id: 6ba8566cde4180524351c9d8c647ce1d4ac5279d
2022-07-05 05:56:35 -07:00
Joshua Gross b30ad9a77d Fix accessibilityRole prop parsing
Summary:
During the refactor in D36889794 (782e004e49) and later D37050215 (47280de85e) this block of code was erroneously deleted; add it back, because if the props iterator setter is disabled, nothing sets this property anymore.

Changelog: [Internal]

Reviewed By: ryancat, nscoding

Differential Revision: D37539700

fbshipit-source-id: 0850180721e0549fed6089cb278402c56eb9d627
2022-06-29 19:07:17 -07:00
Joshua Gross 4f93f63f54 Fix non-deterministic crash in LayoutAnimations
Summary:
LA needs to ignore the new RemoveDeleteTree mutation coming from the differ.

Changelog: [Internal]

Reviewed By: jehartzog

Differential Revision: D37531217

fbshipit-source-id: c05b4106b6e955083e5e7e93619a13c4a2858404
2022-06-29 18:51:15 -07:00
Joshua Gross d1d11c7639 (Attempt to) Fix compilation of new props parsing for MSVC
Summary:
MSVC doesn't like Clang macros. Oops!

Constraints with this bit of code:

1. I'm trying to enforce constexpr in the most obvious, intuitive way possible. Macros are ugly but a "proper" solution would result in 10x as much code that is, totally subjectively, less readable to me.
2. This is evaluating at compile-time a hash of a string which is usually used in the `case` line of a switch statement.

For now I'm just hoping that MSVC will allow us to shadow `hash` which Xcode doesn't like. We might need to add a special pragma(s) for MSVC if it still doesn't like this.

Changelog: [Internal]

Reviewed By: lyahdav

Differential Revision: D37529949

fbshipit-source-id: 9aa605a9786bf5d194819ef8dade778875ae744e
2022-06-29 16:01:24 -07:00
Pieter De Baets e23520bb56 Fix inconsistent-missing-destructor-override warning
Summary: Changelog: [internal]

Reviewed By: neildhar, jpporto

Differential Revision: D37454445

fbshipit-source-id: 423fa99f91e54ade807a56169204c523ad1f9d20
2022-06-29 12:56:01 -07:00
Pieter De Baets a5a956bab8 Remove unused MicroProfiler
Summary:
This was introduced a while ago in D3635319 (0418353249), and was never really adopted.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D37460402

fbshipit-source-id: 70586b23697e02208c393e556625ae534773177f
2022-06-28 02:51:34 -07:00
Joshua Gross b6bbbf8efa RemoveDeleteTree mount instruction
Summary:
TL;DR: For applications using JS navigation, save 50-95% of CPU during mounting phase in N>2 navigations that replace ~most of screen.

During investigation of performance on the UI thread of React Native applications, I noticed that the /initial/ render of an screen for an application using JS navigation is /mostly/ consumed (on the UI thread) by tearing-down the previous View hierarchy. In one 185ms segment on the UI thread in production, 95% of the CPU time was Remove/Delete instructions and only 5% of CPU time was consumed by actually displaying the new hierarchy (this is specific to Android and also assumes that View Preallocation is being used, so post-commit work consists of Insert and UpdateLayout mutations primarily).

There are /some/ cases where the C++ differ knows that we are deleting an entire subtree and therefore we could communicate this to the mounting layer. All that matters is that these Views are removed from the View hierarchy immediately; and secondarily that their memory is cleaned up ASAP, but that doesn't need to happen immediately.

Some additional constraints and notes:

1) As noted in the comments, we cannot simply stop producing Remove and Delete instructions. We need to produce /both/ the new RemoveDeleteTree instruction, /and/ produce all the Remove/Delete instructions, primarily because LayoutAnimations relies heavily on these Remove/Delete instructions and certain things would break if we removed those instructions entirely. However, we can mark those Remove/Delete instructions as redundant, process them only in LayoutAnimations, and not send them to the Android mounting layer.
2) We want to make sure that View Recycling is not impacted. Since Android cannot take advantage of View Recycling until /after/ the second major render (preallocation of views will happen before any views are recycled), this doesn't impact View Recycling and we'll make sure Views are recycled whenever they are deleted.

Thus, we do two things:

1) Introduce a new RemoveDeleteTree operation that can delete an entire subtree recursively as part of one operation. This allows us to avoid serializing hundreds or thousands of instructions and prevents JNI traffic.
2) Besides removing the topmost View from the View hierarchy, and ensuring it's not drawn, the full teardown and recycling of the tree can happen /after/ the paint.

In some flows with JS navigation this saves us 95% of CPU during the mount phase. In the general case it is probably closer to 25-50% of CPU time that is saved and/or deferred.

Changelog: [Android][Changed] Significant perf optimization to Fabric Remove/Delete operations

Reviewed By: ryancat

Differential Revision: D37257864

fbshipit-source-id: a7d33fc74683939965cfb98be4db7890644110b2
2022-06-25 16:41:23 -07:00
Pieter De Baets a13cc68133 Fix runtimeScheduler definition of getCurrentPriorityLevel
Summary:
`getCurrentPriorityLevel` is a function which should return the priority level on invocation.

Changelog: [Internal]

Reviewed By: ryancat

Differential Revision: D37314727

fbshipit-source-id: fe385af02af49d1ca444beb881a4893f7f0712f0
2022-06-24 03:33:05 -07:00
Neil Dhar ef6ab3f5ca Throw JSINativeException from asHostObject
Summary:
`asHostObject` should throw a `JSINativeException` like the other `as*`
functions. This should be a safe change to make in most cases, since
this function already did not work when JSI was being provided by a
dynamic library. However, I defer to mhorowitz.

Changelog: [Fixed] Throw JSINativeException from asHostObject

Reviewed By: jpporto

Differential Revision: D36873355

fbshipit-source-id: 589ac50ebb4ecec4bacfd923d8b0795c0a6c0e34
2022-06-23 16:54:32 -07:00
Pieter De Baets a0d597dbca Throw error when accessing undefined property on runtimeScheduler
Summary:
This improves errors significantly, which is especially helpful as the runtime scheduler only implements a subset of the JS API.

Example error: `Error: Exception in HostObject::get for prop 'unstable_next': undefined property`

Changelog: [Internal]

Reviewed By: rickhanlonii

Differential Revision: D37313924

fbshipit-source-id: b53bc67b9cc36dee34dba86c07fdcf2353338c72
2022-06-23 03:37:56 -07:00
Pieter Vanderwerff e7a4dbcefc Add LTI annotations to function params in xplat/js [1/2]
Summary: Add annotations to function parameters required for Flow's Local Type Inference project. This codemod prepares the codebase to match Flow's new typechecking algorithm. The new algorithm will make Flow more reliable and predicatable.

Reviewed By: evanyeung

Differential Revision: D37353648

fbshipit-source-id: e5a0c685ced85a8ff353d578b373f836b376bb28
2022-06-22 21:36:52 -07:00
Vincent Riemer c25c4abe4a Add detail property to the PointerEvent object
Summary: Changelog: [iOS][Internal] Add detail property to the PointerEvent interface

Reviewed By: necolas

Differential Revision: D37117932

fbshipit-source-id: a5f1c6386d2521e22651453efeffe2005e4a8b6e
2022-06-21 14:05:44 -07:00
Vincent Riemer 27c004745b Add tiltX/tiltY properties to PointerEvent object
Summary: Changelog: [iOS][Internal] - Add tiltX/tiltY properties to the PointerEvent interface

Reviewed By: necolas

Differential Revision: D37117909

fbshipit-source-id: 277d1296b16bbf729dbc32f385634752fd145c8f
2022-06-21 14:05:44 -07:00
Luis Santana 68f3a42fc7 bump RTC-Folly to 2021.07.22 (#33841)
Summary:
Bumping RTC-Folly version used to address CVE-2022-24440.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General][Security] - Bump RTC-Folly to 2021-07-22

Pull Request resolved: https://github.com/facebook/react-native/pull/33841

Reviewed By: Andjeliko, philIip

Differential Revision: D36425598

Pulled By: cortinico

fbshipit-source-id: d38c5f020dbecf794b10f12ed2da30e1825071af
2022-06-21 12:36:43 -07:00
Kudo Chien f97c6a5b49 Fix broken use_frameworks from React-bridging (#34011)
Summary:
`use_frameworks!` is broken again in react-native 0.69 because React-bridging. in the `use_frameworks!` mode, header structures are flattened, so `#include <react/bridging/CallbackWrapper.h>` is not reachable to the header. to somehow workaround the issue without touch React-bridging imports, the pr do these things:

- use `header_mappings_dir` to keep `react/bridging` header structure
- because the header structure is not default framework header structure, explicitly `HEADER_SEARCH_PATHS` is necessary.
- forward declare `CallbackWrapper` and use it internally in ReactCommon. so that we don't need to add `HEADER_SEARCH_PATHS` for React-bridging to every pods depending on `ReactCommon/turbomodule/core`, e.g. React-RCTSettings.podspec.

## Changelog

[iOS] [Fixed] - Fix use_frameworks! for 0.69

Pull Request resolved: https://github.com/facebook/react-native/pull/34011

Test Plan:
```sh
$ npx react-native init RN069 --version next
# add `use_frameworks!` to ios/Podsfile
# comment out use_flipper!() in ios/Podfile
# patch node_modules/react-native with these changes
$ yarn ios
```

Reviewed By: cortinico, cipolleschi

Differential Revision: D37169699

Pulled By: dmitryrykun

fbshipit-source-id: 309c55f1c611a2fc3902a83e8af814daaf2af6a0
2022-06-21 02:56:42 -07:00
Ramanpreet Nara 168f020d5e Unbreak SurfaceRegistry users in bridge mode
Summary: Changelog: [Internal]

Reviewed By: nlutsenko

Differential Revision: D37250414

fbshipit-source-id: be3b98ba661c6f267d0d0dcac8d816584ef58c51
2022-06-17 15:06:31 -07:00
Ramanpreet Nara ea29ae1ceb SurfaceRegistryBinding: Display RedBox when RN$SurfaceRegistry isn't available
Summary:
SurfaceRegistryBinding::startSurface [checks whether global.RN$SurfaceRegistry binding is installed](https://www.internalfb.com/code/fbsource/[7040bef7d4fe43298c5f9dc1fef10f47ec396e79]/xplat/js/react-native-github/ReactCommon/react/renderer/uimanager/SurfaceRegistryBinding.cpp?lines=28-29). If not, control flow goes directly into the bridge path: [callFunctionOnModule](https://www.internalfb.com/code/fbsource/[7040bef7d4fe43298c5f9dc1fef10f47ec396e79]/xplat/js/react-native-github/ReactCommon/react/renderer/uimanager/SurfaceRegistryBinding.cpp?lines=40-46). callMethodOfModule [react_native_asserts, if the requested callable JS module isn't available](https://www.internalfb.com/code/fbsource/[7040bef7d4fe43298c5f9dc1fef10f47ec396e79]/xplat/js/react-native-github/ReactCommon/react/renderer/uimanager/bindingUtils.cpp?lines=29) on the batched bridge. This crashes the app.

We could make this error experience better:
1. We shouldn't crash the app.
2. We should fail fast, and produce an error message that is more descriptive of the actual cause of the error.
3. We can leverage the RedBox infra to display this error on the screen.

## Fixes
This diff modifies the gating inside SurfaceRegistryBinding. Now, in bridgeless mode, if global.RN$SurfaceRegistry isn't instaled, we'll display a RedBox instead, that shows what the error is.

Changelog: [Internal]

Reviewed By: sshic

Differential Revision: D37223640

fbshipit-source-id: 8fbf57f5d9cf359046dc94f0a5f7d66624caee4e
2022-06-17 04:34:59 -07:00
Ramanpreet Nara 4967e50989 Make LogBox render through SurfaceRegistry
Summary:
LogBox was using AppRegistry to render on to the screen. Switch LogBox over to using SurfaceRegistry instead.

Changelog: [Internal]

Reviewed By: sshic

Differential Revision: D37223641

fbshipit-source-id: 59001ad290c1e2c2f14828d38a96f48bd1ab39ca
2022-06-17 04:34:59 -07:00
Vincent Riemer 8cf57a5bdd Add width/height properties to PointerEvent object
Summary: Changelog: [iOS][Internal] Add width/height properties to the PointerEvent object

Reviewed By: kacieb

Differential Revision: D37116854

fbshipit-source-id: 686266d480bb2ee1d2b6696d80ad42865fa2111c
2022-06-16 13:05:54 -07:00
Vincent Riemer 033ffcc14b Remove unecessary PointerEvent attributes
Summary: Changelog: [iOS][Internal] Remove unecessary PointerEvent attributes

Reviewed By: kacieb

Differential Revision: D37115465

fbshipit-source-id: 079a297d1ce5b3d2c6766036a111c73bd75535f1
2022-06-16 13:05:54 -07:00
Joshua Gross af1eae9ea3 New Props parsing infrastructure for perf improvements: visitor pattern vs random-map-access pattern (BaseTextProps and derived props)
Summary:
See commentary at top of stack.

Changelog: [Added][Fabric] New API for efficient props construction

Reviewed By: javache

Differential Revision: D37051020

fbshipit-source-id: 643e433c0d0590cfcd17bc7a43d105bed6ff12ef
2022-06-15 23:37:34 -07:00
Joshua Gross 2ab585ac26 New Props parsing infrastructure for perf improvements: visitor pattern vs random-map-access pattern (ScrollViewProps)
Summary:
See commentary at top of stack.

Changelog: [Added][Fabric] New API for efficient props construction

Reviewed By: javache

Differential Revision: D37050961

fbshipit-source-id: 170a09c08d7406b6aac51d7e78cf295a72fdcf91
2022-06-15 23:37:34 -07:00
Joshua Gross 9f8c45deb7 New Props parsing infrastructure for perf improvements: visitor pattern vs random-map-access pattern (YogaLayoutableShadowNode / YGStyle)
Summary:
See commentary at top of stack.

Changelog: [Added][Fabric] New API for efficient props construction

Reviewed By: javache

Differential Revision: D37050376

fbshipit-source-id: 2bea35a6d604704cf430bd3b2914988227d1abf8
2022-06-15 23:37:34 -07:00
Joshua Gross 47280de85e New Props parsing infrastructure for perf improvements: visitor pattern vs random-map-access pattern (ViewProps, minus YogaLayoutableShadowNode)
Summary:
Perf numbers for this stack are given in terms of before-stack and after-stack, but the changes are split up for ease of review, and also to show that this migration CAN happen per-component and is 100% opt-in. Most existing C++ components do not /need/ to change at all.

# Problem Statement

During certain renders (select critical scenarios in specific products), UIManagerBinding::createNode time takes over 50% of JS thread CPU time. This could be higher or lower depending on the specific product and interaction, but overall createNode takes a lot of CPU time. The question is: can we improve this? What is the minimal overhead needed?

The vast, vast majority of time is taken up by prop parsing (specifically, converting JS values across the JSI into concrete values on the C++ props structs). Other methods like appendChild, etc, do not take up a significant amount of time; so we conclude that createNode is special, and the JSI itself, or calling into C++, is not the problem. Props parsing is the perf problem.

Can we improve it? (Spoiler: yes)

# How does props parsing work today?

Today, props parsing works as follows:

1. The ConcreteComponentDescriptor will construct a RawPropsParser (one per component /type/, per application: so one for View, one for Image, one for Text... etc)
2. Once per component type per application, ConcreteComponentDescriptor will call "prepare" on the RawPropsParser with an empty, default-constructed ConcreteProps struct. This ConcreteProps struct will cause RawProps.at(field) for every single field.
3. Based on the RawProps::at calls in part 2, RawPropsParser constructs a Map from props string names (width, height, position, etc) to a position within a "value index" array.
4. The above is what happens before any actual props are parsed; and the RawPropsParser is now ready to parse actual Props.
5. When props are actually being parsed from a JSI dictionary, we now have two phases:
  1. The RawPropsParser `preparse`s the RawProps, by iterating over the JSI map and filling in two additional data structures: a linear list of RawValues, and a mapping from the ValueIndex array (`keyIndexToValueIndex_`; see step 3) to a value's position in the values list (`value_` in RawPropsParser/RawProps);
  2. The ConcretePropT constructor is called, which is the same as in step 2/3, which calls `fieldValue = rawProps.at("fieldName")` repeatedly.
  3. For each `at` call, the RawProps will look up a prop name in the Map constructed in step 3, and either return an empty value, or map the key name to the `keyIndexToValueIndex_` array, which maps to a value in `values_`, which is then returned and further parsed.

So, a few things that become clear with the current architecture:

1. Complexity is a property of the number of /possible/ props that /can/ be parsed, not what is actually used in product code. This violates the "only pay for what you use" principal. If you have `<View opacity={0.5} />`, the ViewProps constructor will request ~170 properties, not 1!
2. There's a lot of pre-parsing which isn't free
3. The levels of indirection aren't free, and make cache misses more likely and pipelining is more challenging
4. The levels of indirection also require more memory - minor, but not free

# How can we improve it?

The goal is to improve props parsing with minimal or zero impact on backwards-compability. We should be able to migrate over components when it's clear there's a performance issue, without requiring everything gets migrated over at once. This both (1) helps us prove out the new architecture, (2) derisks the project, (3) gives us time, internally and externally, to perfect the APIs and gradually migrate everything over before deleting the old infrastructure code entirely.

Thus, the goal is to do something that introduces a zero-cost abstraction. This isn't entirely possible in practice, and in fact this method slightly regresses components that do not use the new architecture /at all/, while dramatically improving migrated components and causing the impact of the /old/ architecture to be minimal.

# Solution

1. We still keep the existing system in place entirely.
2. After Props are constructed (see ConcreteComponentDescriptor changes) we iterate over all the /values/ set from JS, and call PropsT::setProp. Incidentally, this allows us to easily reuse the same prop for multiple values for "free", which was expensive in the old system.
3. It's worth noting that this makes a Props struct "less immutable" than it was before, and essentially now we have a "builder pattern" for Props. (If we really wanted to, we could still require a single constructor for Props, and then actually use an intermediate PropsBuilder to accumulate values - but I don't think this overhead would be worth for the conceptual "immutability" win, and instead a "Construct/Set/Seal" model works fine, and we still have all the same guarantees of immutability after the parsing phase)

# Implementation Details
# How to properly construct a single Prop value

Minor detail: parsing a single prop is a 3-step process. We imagine two scenarios: (1) Creating a new ShadowNode/Props A from nothing/void, so the previous Props value is just the default constructor. (2) Cloning a ShadowNode A->B and therefore Props A must be copied to Props B before parsing.

We will denote this as a clone from A->B, where A may or may not be a previous node or a default-constructed Props node; and imagine in particular that we're setting the "opacity" value for PropsB.

We must first (1) copy a value over from the previous version of the Props struct, so B.opacity = A.opacity; (2) Determine if opacity has been set from JS. If so, and there is a value, B.opacity = parse(JSValue). (3) If JS has passed in a value for the prop, BUT the value is `null`, it means that JS is resetting or deleting the prop, so we must set it BACK to the default. In this case we set PropsB.opacity = DefaultConstructedProps.opacity.

We must take care in general to ensure that the correct behavior is achieved here, which should help to explain some of the code below.

## String comparisons vs hash comparisons

In the previous system, a RawPropsKey is three `const char*` strings, concatenated together repeatedly /at runtime/. In practice, the ONLY reason we have the prefix, name, suffix Key structure is for the templated prop parsing in ViewProps and YogaStyableProps - that's it. It's not used anywhere else. Further, the key {"margin", "Left", "Width"} is identical to the key {"marginLeftWidth", null, null} and we don't do anything fancy with matching prefixes before comparing the whole string, or similar. Before comparison, keys are concatenated into a single string and then we use `strcmp`. The performance of this isn't terrible, but it's nonzero overhead.

I think we can do better and it's sufficient to compare hashed string values; even better, we can construct most of these /at compile time/ using constexpr, and using `switch` statements guarantee no hash collisions within a single Props struct (it's possible there's a collision between Props.cpp and ViewProps.cpp, for example, since they're different switch statements). We may eventually want to be more robust against has collisions; I personally don't find the risk to be too great, hash collisions with these keys are exceedingly unlikely (or maybe I just like to live dangerously). Thus, at runtime, each setProp requires computing a single hash for the value coming from JS, and then int comparisons with a bunch of pre-compiled values.

If we want to be really paranoid, we could be robust to hash collisions by doing `switch COMPILED_HASH("opacity"): if (strcmp(strFromJs, "opacity") == 0)`. I'm happy to do this if there's enough concern.

## Macros

Yuck! I'm using lots of C preprocessor macros. In general I found this way, way easier in reducing code and (essentially) doing codegen for me vs templated code for the switch cases and hashing prop names at compile-time. Maybe there's a better way.

Changelog: [Added][Fabric] New API for efficient props construction

Reviewed By: javache

Differential Revision: D37050215

fbshipit-source-id: d2dcd351a93b9715cfeb5197eb0d6f9194ec6eb9
2022-06-15 23:37:34 -07:00
Nikita Lutsenko 70788313fe react-native | Fix a crash on deserilization of props when using 'px'/'em' units.
Summary:
A huge set of props use YGValue directly, say something really basic like `margin`/`position`/`padding`/`border`.
All of these according to CSS spec actually support `number | "em" | "px" | %` units, but we are going to throw and hard crash on `em` and `px`, which are unsupported in React Native.

Using `tryTo` instead of `to` (noexcept vs throwing method) for conversion, and treating things like `margin: 50px` same way as we would treat `margin: false` which is not really supported.

Changelog:
    [General][Fixed] - Fixed a crash on deserialization of props when using 'px'/'em' units.

Reviewed By: bvanderhoof

Differential Revision: D37163250

fbshipit-source-id: 59cbe65a821052f6c7e9588b6d4a0ac14e344684
2022-06-15 00:12:58 -07:00
Pieter De Baets 34e51191e7 Optimize lookup of PlatformColor on Android
Summary:
We currently wrap colors in an object to make it look similar to a `PlatformColor` object, but since this is a hot codepath, let's just optimize it to a simple array of strings. The next step is to apply a layer of caching here, but this should be a simple improvement.

Changelog: [internal]

Reviewed By: JoshuaGross

Differential Revision: D31057046

fbshipit-source-id: f68e17167ddd5bba3b545d039600c7c9b40808f5
2022-06-10 16:20:22 -07:00
Kudo Chien c2088e1267 revert #33381 changes (#33973)
Summary:
https://github.com/facebook/yoga/pull/1150 is better than the tricky https://github.com/facebook/react-native/issues/33381 and fix the build error on react-native 0.69 with swift clang module. as https://github.com/facebook/yoga/pull/1150 is landed as 43f831b23c, i'm reverting the previous change, only leaving the necessary react_native_pods.rb change.

## Changelog

[iOS] [Changed] - Better fix for yoga + swift clang module build error

Pull Request resolved: https://github.com/facebook/react-native/pull/33973

Test Plan: ci passed

Reviewed By: cortinico, cipolleschi

Differential Revision: D36998007

Pulled By: dmitryrykun

fbshipit-source-id: fa11bd950e2a1be6396f286086f4e7941ad2ff5b
2022-06-10 02:09:13 -07:00
Pieter De Baets 1b6584b9f5 Fix TurboModule binding improvements for TurboCxxModule
Summary:
TurboCxxModule doesn't use the the default JSI getter that TurboModule offers, and has custom behaviour for `getConstants` which broke the I18nAssets module in the binding experiment.

Changelog: [Internal]

Reviewed By: ryancat

Differential Revision: D37030917

fbshipit-source-id: 187f159abc76f792ad2c7045dc2852d216ea978d
2022-06-09 17:25:24 -07:00
Scott Kyle 68e4e91bd4 Support optional return types
Summary:
This fixes an issue in the C++ TurboModule codegen where optional return types would result in a compiler error because they were not being defaulted to `null` when converting to `jsi::Value`.

Changelog:
Internal

Reviewed By: javache

Differential Revision: D36989312

fbshipit-source-id: 525f9ce7a5638ba5a655fa69ba9647978030ab0b
2022-06-08 21:15:53 -07:00
Vincent Riemer 21a4c1f6d6 Add dispatch of pointerover/pointerout events
Summary: Changelog: [iOS][Internal] - Add dispatching of pointerover/pointerout events

Reviewed By: lunaleaps

Differential Revision: D36718156

fbshipit-source-id: c2fee2332ac52e617db938e321e3b38fd5c35ad3
2022-06-07 16:08:50 -07:00