[ReactNative] Fix timers for debugger executors

Summary:
@public

`-[RCTJavaScriptExecutor executeBlockOnJavaScriptQueue:]` would always `dispatch_async`
for the WebView and WebSocket executors, what caused for any frame aligned dispatch.

Test Plan:
Test the `Timers, TimerMixin` example on UIExplorer, `requestAnimationFrame` was
taking ~33.3ms when debugging, now takes ~16.6ms as expected.
This commit is contained in:
Tadeu Zagallo 2015-06-12 17:01:27 -07:00
parent 781b17fd0f
commit efd386eba2
3 changed files with 23 additions and 15 deletions

View File

@ -185,6 +185,15 @@ RCT_EXPORT_MODULE()
}
- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block
{
if ([NSThread isMainThread]) {
block();
} else {
dispatch_async(dispatch_get_main_queue(), block);
}
}
- (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block
{
dispatch_async(dispatch_get_main_queue(), block);
}

View File

@ -182,25 +182,19 @@ RCT_EXPORT_MODULE()
[_webView loadHTMLString:runScript baseURL:url];
}
/**
* In order to avoid `UIWebView` thread locks, all JS executions should be
* performed outside of the event loop that notifies the `UIWebViewDelegate`
* that the page has loaded. This is only an issue with the remote debug mode of
* `UIWebView`. For a production `UIWebView` deployment, this delay is
* unnecessary and possibly harmful (or helpful?)
*
* The delay might not be needed as soon as the following change lands into
* iOS7. (Review the patch linked here and search for "crash"
* https://bugs.webkit.org/show_bug.cgi?id=125746).
*/
- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block
{
dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_MSEC);
dispatch_after(when, dispatch_get_main_queue(), ^{
RCTAssertMainThread();
if ([NSThread isMainThread]) {
block();
});
} else {
dispatch_async(dispatch_get_main_queue(), block);
}
}
- (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block
{
dispatch_async(dispatch_get_main_queue(), block);
}
/**

View File

@ -182,6 +182,11 @@ RCT_EXPORT_METHOD(createTimer:(NSNumber *)callbackID
NSTimeInterval jsSchedulingOverhead = -jsSchedulingTime.timeIntervalSinceNow;
if (jsSchedulingOverhead < 0) {
RCTLogWarn(@"jsSchedulingOverhead (%ims) should be positive", (int)(jsSchedulingOverhead * 1000));
/**
* Probably debugging on device, set to 0 so we don't ignore the interval
*/
jsSchedulingOverhead = 0;
}
NSTimeInterval targetTime = jsDuration - jsSchedulingOverhead;