mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Dispatch module setup asynchronously to avoid blocking main thread when bridge starts
Summary:Initializing native modules can block the main thread for tens of milliseconds when it starts up, making it difficult to instantiate the bridge on demand without causing a performance blip. This diff splits up the initialization of modules so that - although they still happen on the main thread - they don't block the thread continuously. Reviewed By: javache Differential Revision: D2965438 fb-gh-sync-id: 38c9c9d281e4672b5874d68b57d4c60d1d268344 shipit-source-id: 38c9c9d281e4672b5874d68b57d4c60d1d268344
This commit is contained in:
committed by
Facebook Github Bot 6
parent
8f3e5b1e93
commit
dc13115445
@@ -141,17 +141,8 @@ RCT_EXPORT_MODULE()
|
||||
}
|
||||
|
||||
if (!_handlers) {
|
||||
|
||||
// get handlers
|
||||
NSMutableArray<id<RCTURLRequestHandler>> *handlers = [NSMutableArray array];
|
||||
for (Class moduleClass in _bridge.moduleClasses) {
|
||||
if ([moduleClass conformsToProtocol:@protocol(RCTURLRequestHandler)]) {
|
||||
[handlers addObject:[_bridge moduleForClass:moduleClass]];
|
||||
}
|
||||
}
|
||||
|
||||
// Sort handlers in reverse priority order (highest priority first)
|
||||
[handlers sortUsingComparator:^NSComparisonResult(id<RCTURLRequestHandler> a, id<RCTURLRequestHandler> b) {
|
||||
// Get handlers, sorted in reverse priority order (highest priority first)
|
||||
_handlers = [[_bridge modulesConformingToProtocol:@protocol(RCTURLRequestHandler)] sortedArrayUsingComparator:^NSComparisonResult(id<RCTURLRequestHandler> a, id<RCTURLRequestHandler> b) {
|
||||
float priorityA = [a respondsToSelector:@selector(handlerPriority)] ? [a handlerPriority] : 0;
|
||||
float priorityB = [b respondsToSelector:@selector(handlerPriority)] ? [b handlerPriority] : 0;
|
||||
if (priorityA > priorityB) {
|
||||
@@ -162,8 +153,6 @@ RCT_EXPORT_MODULE()
|
||||
return NSOrderedSame;
|
||||
}
|
||||
}];
|
||||
|
||||
_handlers = handlers;
|
||||
}
|
||||
|
||||
if (RCT_DEBUG) {
|
||||
|
||||
Reference in New Issue
Block a user