Skip to content

Commit

Permalink
Use timer type as Systrace identifier
Browse files Browse the repository at this point in the history
Summary:
Removes the use of `parseErrorStack` in `_allocateCallback`, which was used to determine which timer API was allocating the callback (for Systrace purposes). Instead, we now use the already-existing `type` argument, which achieves the exact same thing but is much faster than parsing the stack trace.

Changelog: [General] [Fixed] - Reduce overhead of setting up timers in DEV

Reviewed By: yinghuitan

Differential Revision: D18233182

fbshipit-source-id: 190c0ffad8734cd889b790248e5a77cfb147454b
  • Loading branch information
motiz88 authored and facebook-github-bot committed Nov 18, 2019
1 parent db4a7ae commit 75a154b
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions Libraries/Core/Timers/JSTimers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const timerIDs: Array<?number> = [];
let immediates: Array<number> = [];
let requestIdleCallbacks: Array<number> = [];
const requestIdleCallbackTimeouts: {[number]: number} = {};
const identifiers: Array<null | {methodName: string}> = [];

let GUID = 1;
let errors: ?Array<Error> = null;
Expand All @@ -81,14 +80,6 @@ function _allocateCallback(func: Function, type: JSTimerType): number {
timerIDs[freeIndex] = id;
callbacks[freeIndex] = func;
types[freeIndex] = type;
if (__DEV__) {
const parseErrorStack = require('../Devtools/parseErrorStack');
// TODO: (moti) T55685778 Use Error.captureStackTrace on Hermes
const stack = parseErrorStack(new Error());
if (stack) {
identifiers[freeIndex] = stack[1]; // skip _allocateCallback's own stack frame
}
}
return id;
}

Expand Down Expand Up @@ -122,8 +113,7 @@ function _callTimer(timerID: number, frameTime: number, didTimeout: ?boolean) {
}

if (__DEV__) {
const identifier = identifiers[timerIndex] || {};
Systrace.beginEvent('Systrace.callTimer: ' + identifier.methodName);
Systrace.beginEvent('Systrace.callTimer: ' + type);
}

// Clear the metadata
Expand Down Expand Up @@ -204,7 +194,6 @@ function _clearIndex(i: number) {
timerIDs[i] = null;
callbacks[i] = null;
types[i] = null;
identifiers[i] = null;
}

function _freeCallback(timerID: number) {
Expand Down

0 comments on commit 75a154b

Please sign in to comment.