Avoid dispatch_async on RCTProfile when not profiling

Summary: public

Fixes #3953

Bail out soon when the profiler is not running + move string formating into the macro so that it happens in a background queue.

Reviewed By: jspahrsummers

Differential Revision: D2696167

fb-gh-sync-id: a1b91ee4459078ab9a4c0be62bd23362ec05e208
This commit is contained in:
Tadeu Zagallo 2015-11-26 03:15:04 -08:00 committed by facebook-github-bot-0
parent 9365414559
commit ea96a7edb8
2 changed files with 22 additions and 17 deletions

View File

@ -871,12 +871,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
for (RCTModuleData *moduleData in _frameUpdateObservers) {
id<RCTFrameUpdateObserver> observer = (id<RCTFrameUpdateObserver>)moduleData.instance;
if (!observer.paused) {
RCT_IF_DEV(NSString *name = [NSString stringWithFormat:@"[%@ didUpdateFrame:%f]", observer, displayLink.timestamp];)
RCTProfileBeginFlowEvent();
[self dispatchBlock:^{
RCTProfileEndFlowEvent();
RCT_PROFILE_BEGIN_EVENT(0, name, nil);
RCT_PROFILE_BEGIN_EVENT(0, [NSString stringWithFormat:@"[%@ didUpdateFrame:%f]", observer, displayLink.timestamp], nil);
[observer didUpdateFrame:frameUpdate];
RCT_PROFILE_END_EVENT(0, @"objc_call,fps", nil);
} queue:moduleData.methodQueue];

View File

@ -66,13 +66,16 @@ RCT_EXTERN void _RCTProfileBeginEvent(NSThread *calleeThread,
uint64_t tag,
NSString *name,
NSDictionary *args);
#define RCT_PROFILE_BEGIN_EVENT(...) { \
#define RCT_PROFILE_BEGIN_EVENT(...) \
do { \
if (RCTProfileIsProfiling()) { \
NSThread *calleeThread = [NSThread currentThread]; \
NSTimeInterval time = CACurrentMediaTime(); \
dispatch_async(RCTProfileGetQueue(), ^{ \
_RCTProfileBeginEvent(calleeThread, time, __VA_ARGS__); \
}); \
}
} \
} while(0)
/**
* The ID returned by BeginEvent should then be passed into EndEvent, with the
@ -86,14 +89,17 @@ RCT_EXTERN void _RCTProfileEndEvent(NSThread *calleeThread,
NSString *category,
NSDictionary *args);
#define RCT_PROFILE_END_EVENT(...) { \
#define RCT_PROFILE_END_EVENT(...) \
do { \
if (RCTProfileIsProfiling()) { \
NSThread *calleeThread = [NSThread currentThread]; \
NSString *threadName = RCTCurrentThreadName(); \
NSTimeInterval time = CACurrentMediaTime(); \
dispatch_async(RCTProfileGetQueue(), ^{ \
_RCTProfileEndEvent(calleeThread, threadName, time, __VA_ARGS__); \
}); \
}
} \
} while(0)
/**
* Collects the initial event information for the event and returns a reference ID