diff --git a/src/Client.js b/src/Client.js index 95b00b797..5d5a067c6 100644 --- a/src/Client.js +++ b/src/Client.js @@ -14,6 +14,8 @@ import type {OS} from './devices/BaseDevice.js'; import {FlipperDevicePlugin} from './plugin.js'; import {setPluginState} from './reducers/pluginStates.js'; import {ReactiveSocket, PartialResponder} from 'rsocket-core'; +// $FlowFixMe perf_hooks is a new API in node +import {performance} from 'perf_hooks'; const EventEmitter = (require('events'): any); const invariant = require('invariant'); diff --git a/src/dispatcher/tracking.js b/src/dispatcher/tracking.js index 229bb113e..bb8c6431a 100644 --- a/src/dispatcher/tracking.js +++ b/src/dispatcher/tracking.js @@ -6,6 +6,8 @@ */ import {ipcRenderer} from 'electron'; +// $FlowFixMe perf_hooks is a new API in node +import {performance} from 'perf_hooks'; import type {Store} from '../reducers/index.js'; import type Logger from '../fb-stubs/Logger.js'; diff --git a/src/plugins/layout/index.js b/src/plugins/layout/index.js index 089a914a8..037800def 100644 --- a/src/plugins/layout/index.js +++ b/src/plugins/layout/index.js @@ -27,6 +27,8 @@ import { ToggleButton, SidebarExtensions, } from 'flipper'; +// $FlowFixMe perf_hooks is a new API in node +import {performance} from 'perf_hooks'; import type {TrackType} from '../../fb-stubs/Logger.js'; diff --git a/src/reducers/connections.js b/src/reducers/connections.js index b6afe84a0..66dfc64bf 100644 --- a/src/reducers/connections.js +++ b/src/reducers/connections.js @@ -11,6 +11,8 @@ import type {UninitializedClient} from '../UninitializedClient'; import {isEqual} from 'lodash'; import {RecurringError} from '../utils/errors'; import iosUtil from '../fb-stubs/iOSContainerUtility'; +// $FlowFixMe perf_hooks is a new API in node +import {performance} from 'perf_hooks'; export type State = {| devices: Array, diff --git a/src/utils/performance.js b/src/utils/performance.js deleted file mode 100644 index 0cea95882..000000000 --- a/src/utils/performance.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright 2018-present Facebook. - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * @format - */ - -let debugId = 0; - -export function mark(): string { - const id = String(debugId++); - if (typeof performance === 'object') { - performance.mark(id); - } - return id; -} - -export function measure(id: string, name: string) { - if (typeof performance === 'object') { - performance.measure(name, id); - performance.clearMeasures(id); - performance.clearMarks(id); - } -} diff --git a/static/transforms/__tests__/electron-stubs.node.js b/static/transforms/__tests__/electron-stubs.node.js index a1f7757e1..89ee2cf3d 100644 --- a/static/transforms/__tests__/electron-stubs.node.js +++ b/static/transforms/__tests__/electron-stubs.node.js @@ -6,8 +6,6 @@ */ import {transform} from '@babel/core'; -import generate from '@babel/generator'; - import electronStubs from '../electron-stubs'; const babelOptions = { @@ -23,14 +21,3 @@ test('transform electron requires to inlined stubs', () => { expect(body.type).toBe('ExpressionStatement'); expect(body.expression.properties.map(p => p.key.name)).toContain('remote'); }); - -test('transform performance calls to requires', () => { - for (const method of ['mark', 'measure']) { - const src = `performance.${method}('something')`; - const transformed = transform(src, babelOptions).ast; - const {code} = generate(transformed); - expect(code).toBe( - `require('perf_hooks').performance.${method}('something');`, - ); - } -}); diff --git a/static/transforms/electron-stubs.js b/static/transforms/electron-stubs.js index 9c2019766..d7d3c5bbf 100644 --- a/static/transforms/electron-stubs.js +++ b/static/transforms/electron-stubs.js @@ -11,7 +11,6 @@ var fs = require('fs'); var electronStubs = babylon.parseExpression( fs.readFileSync('static/electron-stubs.notjs').toString(), ); -var perfHooks = babylon.parseExpression("require('perf_hooks').performance"); module.exports = function(babel) { return { @@ -28,17 +27,6 @@ module.exports = function(babel) { path.replaceWith(electronStubs); } } - if ( - path.node.type === 'CallExpression' && - path.node.callee.type === 'MemberExpression' && - path.node.callee.object.name === 'performance' - ) { - // 'perf_hooks' was added in Node 8.5.0 but doesn't appear to be - // present in electron. We can remove this and switch to using - // interval when it is. Until then, continue using browser.performance - // for real and swap in node's perf_hooks when we dont have electron. - path.node.callee.object = perfHooks; - } }, }, };