Home / File/ RankedChartBuilder.js — react Source File

RankedChartBuilder.js — react Source File

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

File javascript BabelCompiler Validation 4 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  2c3a67b8_4c71_e64d_dc53_5096af434452["RankedChartBuilder.js"]
  0f941e70_3fdb_aa42_7939_2878d5d4125b["utils.js"]
  2c3a67b8_4c71_e64d_dc53_5096af434452 --> 0f941e70_3fdb_aa42_7939_2878d5d4125b
  98e7cbed_f4b4_9f35_838e_6e7cf3e5edcf["types.js"]
  2c3a67b8_4c71_e64d_dc53_5096af434452 --> 98e7cbed_f4b4_9f35_838e_6e7cf3e5edcf
  aec7978f_0a19_ba93_de9e_ac8cf5ddc74b["types"]
  2c3a67b8_4c71_e64d_dc53_5096af434452 --> aec7978f_0a19_ba93_de9e_ac8cf5ddc74b
  a492fbd6_4e1c_c19f_6b2f_72218f3abe3f["ProfilerStore"]
  2c3a67b8_4c71_e64d_dc53_5096af434452 --> a492fbd6_4e1c_c19f_6b2f_72218f3abe3f
  0ad6c6d5_5d6d_2d8a_d957_e1433af66ea0["CommitRanked.js"]
  0ad6c6d5_5d6d_2d8a_d957_e1433af66ea0 --> 2c3a67b8_4c71_e64d_dc53_5096af434452
  style 2c3a67b8_4c71_e64d_dc53_5096af434452 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
 */

import {
  ElementTypeForwardRef,
  ElementTypeMemo,
} from 'react-devtools-shared/src/frontend/types';
import {formatDuration} from './utils';
import ProfilerStore from 'react-devtools-shared/src/devtools/ProfilerStore';

import type {CommitTree} from './types';

export type ChartNode = {
  id: number,
  label: string,
  name: string,
  value: number,
};

export type ChartData = {
  maxValue: number,
  nodes: Array<ChartNode>,
};

const cachedChartData: Map<string, ChartData> = new Map();

export function getChartData({
  commitIndex,
  commitTree,
  profilerStore,
  rootID,
}: {
  commitIndex: number,
  commitTree: CommitTree,
  profilerStore: ProfilerStore,
  rootID: number,
}): ChartData {
  const commitDatum = profilerStore.getCommitData(rootID, commitIndex);

  const {fiberActualDurations, fiberSelfDurations} = commitDatum;
  const {nodes} = commitTree;

  const chartDataKey = `${rootID}-${commitIndex}`;
  if (cachedChartData.has(chartDataKey)) {
    return ((cachedChartData.get(chartDataKey): any): ChartData);
  }

  let maxSelfDuration = 0;

  const chartNodes: Array<ChartNode> = [];
  fiberActualDurations.forEach((actualDuration, id) => {
    const node = nodes.get(id);

    if (node == null) {
      throw Error(`Could not find node with id "${id}" in commit tree`);
    }

    const {displayName, key, parentID, type, compiledWithForget} = node;

    // Don't show the root node in this chart.
    if (parentID === 0) {
      return;
    }
    const selfDuration = fiberSelfDurations.get(id) || 0;
    maxSelfDuration = Math.max(maxSelfDuration, selfDuration);

    const name = displayName || 'Anonymous';
    const maybeKey = key !== null ? ` key="${key}"` : '';
    const maybeForgetBadge = compiledWithForget ? '✨ ' : '';

    let maybeBadge = '';
    if (type === ElementTypeForwardRef) {
      maybeBadge = ' (ForwardRef)';
    } else if (type === ElementTypeMemo) {
      maybeBadge = ' (Memo)';
    }

    const label = `${maybeForgetBadge}${name}${maybeBadge}${maybeKey} (${formatDuration(
      selfDuration,
    )}ms)`;
    chartNodes.push({
      id,
      label,
      name,
      value: selfDuration,
    });
  });

  const chartData = {
    maxValue: maxSelfDuration,
    nodes: chartNodes.sort((a, b) => b.value - a.value),
  };

  cachedChartData.set(chartDataKey, chartData);

  return chartData;
}

export function invalidateChartData(): void {
  cachedChartData.clear();
}

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

What does RankedChartBuilder.js do?
RankedChartBuilder.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in RankedChartBuilder.js?
RankedChartBuilder.js defines 1 function(s): getChartData.
What does RankedChartBuilder.js depend on?
RankedChartBuilder.js imports 4 module(s): ProfilerStore, types, types.js, utils.js.
What files import RankedChartBuilder.js?
RankedChartBuilder.js is imported by 1 file(s): CommitRanked.js.
Where is RankedChartBuilder.js in the architecture?
RankedChartBuilder.js is located at packages/react-devtools-shared/src/devtools/views/Profiler/RankedChartBuilder.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/devtools/views/Profiler).

Analyze Your Own Codebase

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

Try Supermodel Free