Home / File/ PerformanceLoggingUtils.js — react Source File

PerformanceLoggingUtils.js — react Source File

Architecture documentation for PerformanceLoggingUtils.js, a javascript file in the react codebase. 1 imports, 1 dependents.

File javascript BabelCompiler 1 imports 1 dependents

Entity Profile

Dependency Diagram

graph LR
  65802b54_1b70_c424_1a67_236a67c06eb1["PerformanceLoggingUtils.js"]
  bcb71f5e_1ecf_5620_9a9e_55d6ab61dd1f["constants.js"]
  65802b54_1b70_c424_1a67_236a67c06eb1 --> bcb71f5e_1ecf_5620_9a9e_55d6ab61dd1f
  2e5340ff_c18c_8b58_8a45_86e8bb6884f5["hookNamesCache.js"]
  2e5340ff_c18c_8b58_8a45_86e8bb6884f5 --> 65802b54_1b70_c424_1a67_236a67c06eb1
  style 65802b54_1b70_c424_1a67_236a67c06eb1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow strict-local
 */

import {__PERFORMANCE_PROFILE__} from './constants';

const supportsUserTiming =
  typeof performance !== 'undefined' &&
  // $FlowFixMe[method-unbinding]
  typeof performance.mark === 'function' &&
  // $FlowFixMe[method-unbinding]
  typeof performance.clearMarks === 'function';

const supportsPerformanceNow =
  // $FlowFixMe[method-unbinding]
  typeof performance !== 'undefined' && typeof performance.now === 'function';

function mark(markName: string): void {
  if (supportsUserTiming) {
    performance.mark(markName + '-start');
  }
}

function measure(markName: string): void {
  if (supportsUserTiming) {
    performance.mark(markName + '-end');
    performance.measure(markName, markName + '-start', markName + '-end');
    performance.clearMarks(markName + '-start');
    performance.clearMarks(markName + '-end');
  }
}

function now(): number {
  if (supportsPerformanceNow) {
    return performance.now();
  }
  return Date.now();
}

export async function withAsyncPerfMeasurements<TReturn>(
  markName: string,
  callback: () => Promise<TReturn>,
  onComplete?: number => void,
): Promise<TReturn> {
  const start = now();
  if (__PERFORMANCE_PROFILE__) {
    mark(markName);
  }
  const result = await callback();

  if (__PERFORMANCE_PROFILE__) {
    measure(markName);
  }

  if (onComplete != null) {
    const duration = now() - start;
    onComplete(duration);
  }

  return result;
}

export function withSyncPerfMeasurements<TReturn>(
  markName: string,
  callback: () => TReturn,
  onComplete?: number => void,
): TReturn {
  const start = now();
  if (__PERFORMANCE_PROFILE__) {
    mark(markName);
  }
  const result = callback();

  if (__PERFORMANCE_PROFILE__) {
    measure(markName);
  }

  if (onComplete != null) {
    const duration = now() - start;
    onComplete(duration);
  }

  return result;
}

export function withCallbackPerfMeasurements<TReturn>(
  markName: string,
  callback: (done: () => void) => TReturn,
  onComplete?: number => void,
): TReturn {
  const start = now();
  if (__PERFORMANCE_PROFILE__) {
    mark(markName);
  }

  const done = () => {
    if (__PERFORMANCE_PROFILE__) {
      measure(markName);
    }

    if (onComplete != null) {
      const duration = now() - start;
      onComplete(duration);
    }
  };
  return callback(done);
}

Domain

Dependencies

Frequently Asked Questions

What does PerformanceLoggingUtils.js do?
PerformanceLoggingUtils.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain.
What does PerformanceLoggingUtils.js depend on?
PerformanceLoggingUtils.js imports 1 module(s): constants.js.
What files import PerformanceLoggingUtils.js?
PerformanceLoggingUtils.js is imported by 1 file(s): hookNamesCache.js.
Where is PerformanceLoggingUtils.js in the architecture?
PerformanceLoggingUtils.js is located at packages/react-devtools-shared/src/PerformanceLoggingUtils.js (domain: BabelCompiler, directory: packages/react-devtools-shared/src).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free