Files
Devan BuggayandFacebook GitHub Bot 6d51bce9ed Refactor native/js modes (#52822)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52822

Refactors underlying modes by adding `isNativeOpt`, `isJsOpt`, and `isJsBytecode` to allow for more granular control in a future diff.

### View ###

| (index) | Task name                                                 | Latency average (ns)   | Latency median (ns)       | Throughput average (ops/s) | Throughput median (ops/s) | Samples |
| ------- | --------------------------------------------------------- | ---------------------- | ------------------------- | -------------------------- | ------------------------- | ------- |
| 0       | 'render 100 uncollapsable views'                          | '23005778.16 ± 0.53%'  | '22877194.50 ± 11607.50'  | '43 ± 0.50%'               | '44'                      | 64      |
| 1       | 'render 1000 uncollapsable views'                         | '271276451.70 ± 0.61%' | '268378201.00 ± 9925.00'  | '4 ± 0.59%'                | '4'                       | 64      |
| 2       | 'render 100 views with large amount of props and styles'  | '47580650.91 ± 1.21%'  | '47212012.00 ± 2979.00'   | '21 ± 0.89%'               | '21'                      | 64      |
| 3       | 'render 1000 views with large amount of props and styles' | '521237370.22 ± 1.09%' | '516142815.00 ± 41682.00' | '2 ± 0.84%'                | '2'                       | 64      |
| 4       | 'render 1500 views with large amount of props and styles' | '828143691.48 ± 0.94%' | '824723257.50 ± 11331.50' | '1 ± 0.73%'                | '1'                       | 64      |

### View (mode 🚀, jsMode 🚀, bytecode) ###

| (index) | Task name                                                 | Latency average (ns)   | Latency median (ns)        | Throughput average (ops/s) | Throughput median (ops/s) | Samples |
| ------- | --------------------------------------------------------- | ---------------------- | -------------------------- | -------------------------- | ------------------------- | ------- |
| 0       | 'render 100 uncollapsable views'                          | '4051033.45 ± 2.01%'   | '3876618.00'               | '251 ± 1.29%'              | '258'                     | 247     |
| 1       | 'render 1000 uncollapsable views'                         | '86134420.23 ± 1.38%'  | '85815369.50 ± 281477.50'  | '12 ± 1.38%'               | '12'                      | 64      |
| 2       | 'render 100 views with large amount of props and styles'  | '13921817.92 ± 2.57%'  | '13474963.50 ± 4977.50'    | '72 ± 1.62%'               | '74'                      | 72      |
| 3       | 'render 1000 views with large amount of props and styles' | '182664526.31 ± 0.74%' | '181872565.00 ± 10281.00'  | '5 ± 0.73%'                | '5'                       | 64      |
| 4       | 'render 1500 views with large amount of props and styles' | '313110386.45 ± 1.13%' | '307934163.50 ± 156920.50' | '3 ± 1.07%'                | '3'                       | 64      |

Changelog: [Internal]

Reviewed By: rubennorte

Differential Revision: D78912257

fbshipit-source-id: 16fd0301af98159dbb9818cb8092bd4416ef2559
2025-07-30 14:22:22 -07:00

97 lines
2.6 KiB
JavaScript

/**
* 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
* @format
*/
import type {FeatureFlagValue} from '../../../packages/react-native/scripts/featureflags/types';
import type {FantomTestConfig} from '../runner/getFantomTestConfigs';
import type {HermesVariant} from '../runner/utils';
import type {PartialFantomTestConfig} from './getFantomTestConfigs';
import {FantomTestConfigHermesVariant} from '../runner/getFantomTestConfigs';
import {getOverrides} from './getFantomTestConfigs';
function formatModes(overrides: PartialFantomTestConfig) {
const parts = [];
if (
overrides.isNativeOptimized === false &&
overrides.isJsOptimized === false &&
overrides.isJsBytecode === false
) {
return ['mode 🐛'];
} else if (
overrides.isNativeOptimized === true &&
overrides.isJsOptimized === true &&
overrides.isJsBytecode === true
) {
return ['mode 🚀'];
}
if (overrides.isNativeOptimized != null) {
parts.push(overrides.isNativeOptimized ? 'native 🚀' : 'native 🐛');
}
if (overrides.isJsOptimized != null) {
parts.push(overrides.isJsOptimized ? 'js 🚀' : 'js 🐛');
}
if (overrides.isJsBytecode != null && overrides.isJsBytecode) {
parts.push('bytecode');
}
return parts;
}
function formatFantomHermesVariant(hermesVariant: HermesVariant): string {
switch (hermesVariant) {
case FantomTestConfigHermesVariant.Hermes:
return 'hermes';
case FantomTestConfigHermesVariant.StaticHermesStable:
return 'shermes 🆕';
case FantomTestConfigHermesVariant.StaticHermesExperimental:
return 'shermes 🧪';
}
}
function formatFantomFeatureFlag(
flagName: string,
flagValue: FeatureFlagValue,
): string {
if (typeof flagValue === 'boolean') {
return `${flagName} ${flagValue ? '✅' : '🛑'}`;
}
return `🔐 ${flagName} = ${flagValue}`;
}
export default function formatFantomConfig(config: FantomTestConfig): string {
const overrides = getOverrides(config);
const parts = [];
parts.push(...formatModes(overrides));
if (overrides.hermesVariant) {
parts.push(formatFantomHermesVariant(overrides.hermesVariant));
}
if (overrides.flags) {
for (const flagType of ['common', 'jsOnly', 'reactInternal'] as const) {
if (overrides.flags[flagType]) {
for (const [flagName, flagValue] of Object.entries(
overrides.flags[flagType],
)) {
parts.push(formatFantomFeatureFlag(flagName, flagValue));
}
}
}
}
return parts.join(', ');
}