Enable synchronous void method invocations via feature flag - RFC#56740
Open
christophpurrer wants to merge 1 commit intofacebook:mainfrom
Open
Enable synchronous void method invocations via feature flag - RFC#56740christophpurrer wants to merge 1 commit intofacebook:mainfrom
christophpurrer wants to merge 1 commit intofacebook:mainfrom
Conversation
Summary:
Introduce a feature flag `enableSyncVoidMethods` that allows TurboModule methods with void return types to be invoked synchronously on the JS thread instead of being dispatched asynchronously.
The flag only applies to pure TurboModules (not interop modules) to avoid impacting backward compatibility with legacy Native Modules. When enabled, void methods behave like other synchronous methods, improving performance for operations that don't need async dispatch.
# Behavior mismatch
Currently:
- C++ Turbo Modules run void methods `sync`
- Java / ObjC Turbo Modules run void methods `async`
# Rationale
JavaScript code like this
```
const buffer = new ArrayBuffer(4);
const view = new Uint8Array(buffer);
view[0] = 1;
view[1] = 2;
view[2] = 3;
view[3] = 4;
const result = NativeCxxModuleExample.passArrayBuffer(buffer);
/** In native code do something like:
* std::span<uint8_t> bytes(arg.data(rt), arg.size(rt));
* std::reverse(bytes.begin(), bytes.end());
**/
// ArrayBuffer was Shared with native code and value updates are reflected to JS code
// view[0] = 4;
// view[1] = 3;
// view[2] = 2;
// view[3] = 1;
```
for a TM spec as
```
+passArrayBuffer: (arg: ArrayBuffer) => void;
```
works for C++ Turbo Modules
see: facebook#56690
but currently fails for Java / Objc Turbo Modules as calling
```
const result = NativeCxxModuleExample.passArrayBuffer(buffer); //
```
is done `async` for Java/ObjC Modules and hence we would need to copy the `ArrayBuffer` in native code.
Changelog: [Internal]
Differential Revision: D104331837
|
@christophpurrer has exported this pull request. If you are a Meta employee, you can view the originating Diff in D104331837. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
Introduce a feature flag
enableSyncVoidMethodsthat allows TurboModule methods with void return types to be invoked synchronously on the JS thread instead of being dispatched asynchronously.The flag only applies to pure TurboModules (not interop modules) to avoid impacting backward compatibility with legacy Native Modules. When enabled, void methods behave like other synchronous methods, improving performance for operations that don't need async dispatch.
Behavior mismatch
Currently:
syncasyncRationale
JavaScript code like this
for a TM spec as
works for C++ Turbo Modules
see: #56690
but currently fails for Java / Objc Turbo Modules as calling
is done
asyncfor Java/ObjC Modules and hence we would need to copy theArrayBufferin native code.Changelog: [Internal]
Differential Revision: D104331837