Skip to content

Commit

Permalink
introduce logic for shared native module queue
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.

Differential Revision: D50398635
  • Loading branch information
philIip authored and facebook-github-bot committed Oct 18, 2023
1 parent c9d0a00 commit 95eb1de
Showing 1 changed file with 18 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,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
_bridgeProxy = bridgeProxy;
_bridgeModuleDecorator = bridgeModuleDecorator;
_invalidating = false;
_enableSharedModuleQueue = NO;

if (RCTTurboModuleInteropEnabled()) {
NSMutableDictionary<NSString *, id<RCTBridgeModule>> *legacyInitializedModules = [NSMutableDictionary new];
Expand Down Expand Up @@ -685,8 +689,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 = [self _sharedModuleQueue];
} else {
NSString *methodQueueName = [NSString stringWithFormat:@"com.facebook.react.%sQueue", moduleName];
methodQueue = dispatch_queue_create(methodQueueName.UTF8String, DISPATCH_QUEUE_SERIAL);
}

if (moduleHasMethodQueueGetter) {
/**
Expand Down Expand Up @@ -1067,4 +1075,12 @@ - (void)_invalidateModules
_legacyModuleCache.clear();
}

- (dispatch_queue_t)_sharedModuleQueue
{
if (!_sharedModuleQueue) {
_sharedModuleQueue = dispatch_queue_create("com.meta.react.turbomodulemanager.queue", DISPATCH_QUEUE_SERIAL);
}
return _sharedModuleQueue;
}

@end

0 comments on commit 95eb1de

Please sign in to comment.