Skip to content

Commit

Permalink
introduce logic for shared native module queue (facebook#41042)
Browse files Browse the repository at this point in the history
Summary:

Changelog: [Internal]

currently, each native module creates a new module queue if `methodQueue` is not overridden in the native module.

we want to see if we can use a single execution queue for a few reasons:
- parity with android's queue model
- performance: creating so many queues... for what? the overhead of this feels like it exceeds any potential benefit
- set us up to remove the assocs from the module to the method queue, which will allow us to deprecate `synthesize methodQueue` and `-(dispatch_queue_t)moduleQueue` API.

in this QE, we just start with replacing the KVO assoc'd queue with the shared module queue.

Reviewed By: cipolleschi

Differential Revision: D50398635
  • Loading branch information
philIip authored and facebook-github-bot committed Oct 20, 2023
1 parent d4fe550 commit 7a60c0b
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ @implementation RCTTurboModuleManager {

RCTBridgeProxy *_bridgeProxy;
RCTBridgeModuleDecorator *_bridgeModuleDecorator;

BOOL _enableSharedModuleQueue;
dispatch_queue_t _sharedModuleQueue;
}

- (instancetype)initWithBridge:(RCTBridge *)bridge
Expand All @@ -221,6 +224,11 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
_bridgeProxy = bridgeProxy;
_bridgeModuleDecorator = bridgeModuleDecorator;
_invalidating = false;
_enableSharedModuleQueue = NO;

if (_enableSharedModuleQueue) {
_sharedModuleQueue = dispatch_queue_create("com.meta.react.turbomodulemanager.queue", DISPATCH_QUEUE_SERIAL);
}

if (RCTTurboModuleInteropEnabled()) {
NSMutableDictionary<NSString *, id<RCTBridgeModule>> *legacyInitializedModules = [NSMutableDictionary new];
Expand Down Expand Up @@ -685,8 +693,12 @@ - (BOOL)_shouldCreateObjCModule:(Class)moduleClass
* following if condition's block.
*/
if (!methodQueue) {
NSString *methodQueueName = [NSString stringWithFormat:@"com.facebook.react.%sQueue", moduleName];
methodQueue = dispatch_queue_create(methodQueueName.UTF8String, DISPATCH_QUEUE_SERIAL);
if (_enableSharedModuleQueue) {
methodQueue = _sharedModuleQueue;
} else {
NSString *methodQueueName = [NSString stringWithFormat:@"com.facebook.react.%sQueue", moduleName];
methodQueue = dispatch_queue_create(methodQueueName.UTF8String, DISPATCH_QUEUE_SERIAL);
}

if (moduleHasMethodQueueGetter) {
/**
Expand Down

0 comments on commit 7a60c0b

Please sign in to comment.