Speed up Flipper by using background queue for serialization
Reviewed By: jknoxville Differential Revision: D21290732 fbshipit-source-id: 21fcb793900a6517d764fa3a581255fd75a39801
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b483e0688d
commit
c62760b3e8
@@ -10,6 +10,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import <FlipperKit/FlipperPlugin.h>
|
||||
#import <FlipperKit/SKMacros.h>
|
||||
|
||||
#import "SKDescriptorMapper.h"
|
||||
#import "SKInvalidation.h"
|
||||
@@ -29,4 +30,7 @@
|
||||
|
||||
@end
|
||||
|
||||
/** Exposed for tests only. */
|
||||
SK_EXTERN_C dispatch_queue_t SKLayoutPluginSerialBackgroundQueue(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -258,7 +258,10 @@
|
||||
[elements addObject:node];
|
||||
}
|
||||
|
||||
[responder success:@{@"elements" : elements}];
|
||||
// Converting to folly::dynamic is expensive, do it on a bg queue:
|
||||
dispatch_async(SKLayoutPluginSerialBackgroundQueue(), ^{
|
||||
[responder success:@{@"elements" : elements}];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)onCallSetData:(NSString*)objectId
|
||||
@@ -560,4 +563,22 @@
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
Operations like converting NSDictionary to folly::dynamic can be expensive.
|
||||
Do them on this serial background queue to avoid blocking the main thread.
|
||||
(Of course, ideally we wouldn't bother with building NSDictionary objects
|
||||
in the first place, in favor of just using folly::dynamic directly...)
|
||||
*/
|
||||
dispatch_queue_t SKLayoutPluginSerialBackgroundQueue(void) {
|
||||
static dispatch_queue_t queue;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
queue = dispatch_queue_create("flipper.layout.bg", DISPATCH_QUEUE_SERIAL);
|
||||
// This should be relatively high priority, to prevent Flipper lag.
|
||||
dispatch_set_target_queue(
|
||||
queue, dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0));
|
||||
});
|
||||
return queue;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user