Skip to content

Commit f454f5f

Browse files
sbuggayfacebook-github-bot
authored andcommitted
Refactor native/js modes (facebook#52822)
Summary: 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
1 parent db6b591 commit f454f5f

File tree

5 files changed

+95
-89
lines changed

5 files changed

+95
-89
lines changed

private/react-native-fantom/__docs__/README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ Available pragmas:
132132
- Possible values:
133133
- `dev`: development, default for tests.
134134
- `opt`: optimized and using Hermes bytecode, default for benchmarks.
135-
- `dev-bytecode`: development but using Hermes bytecode instead of plain
136-
text JavaScript code.
137135
- `@fantom_react_fb_flags`: used to set overrides for internal React flags set
138136
in ReactNativeInternalFeatureFlags (Meta use only)
139137

@@ -150,14 +148,12 @@ this test:
150148

151149
Would be executed with these combinations of options:
152150

153-
| `jsOnlyTestFlag` | `mode` |
154-
| ---------------- | -------------- |
155-
| `false` | `dev` |
156-
| `true` | `dev` |
157-
| `false` | `dev-bytecode` |
158-
| `true` | `dev-bytecode` |
159-
| `false` | `opt` |
160-
| `true` | `opt` |
151+
| `jsOnlyTestFlag` | `mode` |
152+
| ---------------- | ------ |
153+
| `false` | `dev` |
154+
| `true` | `dev` |
155+
| `false` | `opt` |
156+
| `true` | `opt` |
161157

162158
With an output such as:
163159

private/react-native-fantom/runner/formatFantomConfig.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,41 @@
1111
import type {FeatureFlagValue} from '../../../packages/react-native/scripts/featureflags/types';
1212
import type {FantomTestConfig} from '../runner/getFantomTestConfigs';
1313
import type {HermesVariant} from '../runner/utils';
14+
import type {PartialFantomTestConfig} from './getFantomTestConfigs';
1415

15-
import {
16-
FantomTestConfigHermesVariant,
17-
FantomTestConfigMode,
18-
} from '../runner/getFantomTestConfigs';
16+
import {FantomTestConfigHermesVariant} from '../runner/getFantomTestConfigs';
1917
import {getOverrides} from './getFantomTestConfigs';
2018

21-
function formatFantomMode(mode: FantomTestConfigMode): string {
22-
switch (mode) {
23-
case FantomTestConfigMode.DevelopmentWithSource:
24-
return 'mode 🐛';
25-
case FantomTestConfigMode.DevelopmentWithBytecode:
26-
return 'mode 🐛🔢';
27-
case FantomTestConfigMode.Optimized:
28-
return 'mode 🚀';
19+
function formatModes(overrides: PartialFantomTestConfig) {
20+
const parts = [];
21+
22+
if (
23+
overrides.isNativeOptimized === false &&
24+
overrides.isJsOptimized === false &&
25+
overrides.isJsBytecode === false
26+
) {
27+
return ['mode 🐛'];
28+
} else if (
29+
overrides.isNativeOptimized === true &&
30+
overrides.isJsOptimized === true &&
31+
overrides.isJsBytecode === true
32+
) {
33+
return ['mode 🚀'];
34+
}
35+
36+
if (overrides.isNativeOptimized != null) {
37+
parts.push(overrides.isNativeOptimized ? 'native 🚀' : 'native 🐛');
38+
}
39+
40+
if (overrides.isJsOptimized != null) {
41+
parts.push(overrides.isJsOptimized ? 'js 🚀' : 'js 🐛');
42+
}
43+
44+
if (overrides.isJsBytecode != null && overrides.isJsBytecode) {
45+
parts.push('bytecode');
2946
}
47+
48+
return parts;
3049
}
3150

3251
function formatFantomHermesVariant(hermesVariant: HermesVariant): string {
@@ -55,9 +74,7 @@ export default function formatFantomConfig(config: FantomTestConfig): string {
5574
const overrides = getOverrides(config);
5675
const parts = [];
5776

58-
if (overrides.mode) {
59-
parts.push(formatFantomMode(overrides.mode));
60-
}
77+
parts.push(...formatModes(overrides));
6178

6279
if (overrides.hermesVariant) {
6380
parts.push(formatFantomHermesVariant(overrides.hermesVariant));

private/react-native-fantom/runner/getFantomTestConfigs.js

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ type JsOnlyFeatureFlags = (typeof ReactNativeFeatureFlags)['jsOnly'];
2020

2121
type DocblockPragmas = {[key: string]: string | string[]};
2222

23-
export enum FantomTestConfigMode {
24-
DevelopmentWithBytecode,
25-
DevelopmentWithSource,
26-
Optimized,
27-
}
28-
2923
export type FantomTestConfigCommonFeatureFlags = Partial<{
3024
[key in keyof CommonFeatureFlags]: CommonFeatureFlags[key]['defaultValue'],
3125
}>;
@@ -45,22 +39,27 @@ export type FantomTestConfigFeatureFlags = {
4539
};
4640

4741
export type FantomTestConfig = {
48-
mode: FantomTestConfigMode,
42+
isNativeOptimized: boolean,
43+
isJsOptimized: boolean,
44+
isJsBytecode: boolean,
4945
hermesVariant: HermesVariant,
5046
flags: FantomTestConfigFeatureFlags,
5147
};
5248

5349
export type PartialFantomTestConfig = {
54-
mode?: FantomTestConfigMode,
50+
isNativeOptimized?: boolean,
51+
isJsOptimized?: boolean,
52+
isJsBytecode?: boolean,
5553
hermesVariant?: HermesVariant,
5654
flags?: Partial<FantomTestConfigFeatureFlags>,
5755
};
5856

5957
export const FantomTestConfigHermesVariant = HermesVariant;
6058

61-
export const DEFAULT_MODE: FantomTestConfigMode =
62-
FantomTestConfigMode.DevelopmentWithSource;
63-
59+
export const DEFAULT_IS_OPTIMIZED: boolean = false;
60+
export const DEFAULT_IS_NATIVE_OPTIMIZED: boolean = false;
61+
export const DEFAULT_IS_JS_OPTIMIZED: boolean = false;
62+
export const DEFAULT_IS_JS_BYTECODE: boolean = false;
6463
export const DEFAULT_HERMES_VARIANT: HermesVariant = HermesVariant.Hermes;
6564

6665
export const DEFAULT_FEATURE_FLAGS: FantomTestConfigFeatureFlags = {
@@ -77,9 +76,6 @@ const FANTOM_BENCHMARK_FILENAME_RE = /[Bb]enchmark-itest\./g;
7776
const FANTOM_BENCHMARK_SUITE_RE =
7877
/\n(Fantom\.)?unstable_benchmark(\s*)\.suite\(/g;
7978

80-
const FANTOM_BENCHMARK_DEFAULT_MODE: FantomTestConfigMode =
81-
FantomTestConfigMode.Optimized;
82-
8379
const MAX_FANTOM_CONFIGURATION_VARIATIONS = 12;
8480

8581
const VALID_FANTOM_PRAGMAS = [
@@ -94,8 +90,16 @@ export function getOverrides(
9490
): PartialFantomTestConfig {
9591
const overrides: PartialFantomTestConfig = {};
9692

97-
if (config.mode !== DEFAULT_MODE) {
98-
overrides.mode = config.mode;
93+
if (config.isNativeOptimized !== DEFAULT_IS_NATIVE_OPTIMIZED) {
94+
overrides.isNativeOptimized = config.isNativeOptimized;
95+
}
96+
97+
if (config.isJsOptimized !== DEFAULT_IS_JS_OPTIMIZED) {
98+
overrides.isJsOptimized = config.isJsOptimized;
99+
}
100+
101+
if (config.isJsBytecode !== DEFAULT_IS_JS_BYTECODE) {
102+
overrides.isJsBytecode = config.isJsBytecode;
99103
}
100104

101105
if (config.hermesVariant !== DEFAULT_HERMES_VARIANT) {
@@ -140,7 +144,7 @@ export function getOverrides(
140144
*
141145
* The supported options are:
142146
* - `fantom_mode`: specifies the level of optimization to compile the test
143-
* with. Valid values are `dev`, `dev-bytecode` and `opt`.
147+
* with. Valid values are `dev` and `opt`.
144148
* - `fantom_hermes_variant`: specifies the Hermes variant to use to run the
145149
* test. Valid values are `hermes`, `static_hermes_stable` and
146150
* `static_hermes_experimental`.
@@ -162,7 +166,9 @@ export default function getFantomTestConfigs(
162166
verifyFantomPragmas(pragmas);
163167

164168
const config: FantomTestConfig = {
165-
mode: DEFAULT_MODE,
169+
isNativeOptimized: DEFAULT_IS_NATIVE_OPTIMIZED,
170+
isJsOptimized: DEFAULT_IS_JS_OPTIMIZED,
171+
isJsBytecode: DEFAULT_IS_JS_BYTECODE,
166172
hermesVariant: DEFAULT_HERMES_VARIANT,
167173
flags: {
168174
common: {
@@ -190,19 +196,27 @@ export default function getFantomTestConfigs(
190196

191197
switch (mode) {
192198
case 'dev':
193-
config.mode = FantomTestConfigMode.DevelopmentWithSource;
194-
break;
195-
case 'dev-bytecode':
196-
config.mode = FantomTestConfigMode.DevelopmentWithBytecode;
199+
config.isNativeOptimized = false;
200+
config.isJsOptimized = false;
201+
config.isJsBytecode = false;
197202
break;
198203
case 'opt':
199-
config.mode = FantomTestConfigMode.Optimized;
204+
config.isNativeOptimized = true;
205+
config.isJsOptimized = true;
206+
config.isJsBytecode = true;
200207
break;
201208
case '*':
202209
configVariations.push([
203-
{mode: FantomTestConfigMode.DevelopmentWithSource},
204-
{mode: FantomTestConfigMode.DevelopmentWithBytecode},
205-
{mode: FantomTestConfigMode.Optimized},
210+
{
211+
isNativeOptimized: false,
212+
isJsOptimized: false,
213+
isJsBytecode: false,
214+
},
215+
{
216+
isNativeOptimized: true,
217+
isJsOptimized: true,
218+
isJsBytecode: true,
219+
},
206220
]);
207221
break;
208222
default:
@@ -213,7 +227,9 @@ export default function getFantomTestConfigs(
213227
FANTOM_BENCHMARK_FILENAME_RE.test(testPath) ||
214228
FANTOM_BENCHMARK_SUITE_RE.test(testContents)
215229
) {
216-
config.mode = FANTOM_BENCHMARK_DEFAULT_MODE;
230+
config.isNativeOptimized = true;
231+
config.isJsOptimized = true;
232+
config.isJsBytecode = true;
217233
}
218234
}
219235

@@ -373,7 +389,11 @@ function getConfigurationVariations(
373389

374390
for (const currentConfigVariation of currentConfigVariations) {
375391
const currentConfigWithVariation = {
376-
mode: currentConfigVariation.mode ?? config.mode,
392+
isNativeOptimized:
393+
currentConfigVariation.isNativeOptimized ?? config.isNativeOptimized,
394+
isJsOptimized:
395+
currentConfigVariation.isJsOptimized ?? config.isJsOptimized,
396+
isJsBytecode: currentConfigVariation.isJsBytecode ?? config.isJsBytecode,
377397
hermesVariant:
378398
currentConfigVariation.hermesVariant ?? config.hermesVariant,
379399
flags: {

private/react-native-fantom/runner/runner.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import entrypointTemplate from './entrypoint-template';
2424
import * as EnvironmentOptions from './EnvironmentOptions';
2525
import formatFantomConfig from './formatFantomConfig';
2626
import getFantomTestConfigs from './getFantomTestConfigs';
27-
import {FantomTestConfigMode} from './getFantomTestConfigs';
2827
import {
2928
getInitialSnapshotData,
3029
updateSnapshotsAndGetJestSnapshotResult,
@@ -249,10 +248,7 @@ module.exports = async function runTest(
249248
];
250249

251250
for (const testConfig of testConfigs) {
252-
if (
253-
EnvironmentOptions.isOSS &&
254-
testConfig.mode === FantomTestConfigMode.Optimized
255-
) {
251+
if (EnvironmentOptions.isOSS && testConfig.isNativeOptimized) {
256252
testResultsByConfig.push(
257253
skippedTestResults({
258254
ancestorTitles: ['"@fantom_mode opt" in docblock'],
@@ -277,13 +273,10 @@ module.exports = async function runTest(
277273
continue;
278274
}
279275

280-
if (
281-
EnvironmentOptions.isOSS &&
282-
testConfig.mode !== FantomTestConfigMode.DevelopmentWithSource
283-
) {
276+
if (EnvironmentOptions.isOSS && testConfig.isJsBytecode) {
284277
testResultsByConfig.push(
285278
skippedTestResults({
286-
ancestorTitles: ['"@fantom_mode dev-bytecode" in docblock'],
279+
ancestorTitles: ['"@fantom_mode dev" in docblock'],
287280
title: 'Hermes bytecode is not yet supported in OSS',
288281
}),
289282
);
@@ -320,26 +313,24 @@ module.exports = async function runTest(
320313
entry: entrypointPath,
321314
out: testJSBundlePath,
322315
platform: 'android',
323-
minify: testConfig.mode === FantomTestConfigMode.Optimized,
324-
dev: testConfig.mode !== FantomTestConfigMode.Optimized,
316+
minify: testConfig.isJsOptimized,
317+
dev: !testConfig.isJsOptimized,
325318
sourceMap: true,
326319
sourceMapUrl: sourceMapPath,
327320
});
328321

329-
if (testConfig.mode !== FantomTestConfigMode.DevelopmentWithSource) {
322+
if (testConfig.isJsBytecode) {
330323
generateBytecodeBundle({
331324
sourcePath: testJSBundlePath,
332325
bytecodePath: testBytecodeBundlePath,
333-
isOptimizedMode: testConfig.mode === FantomTestConfigMode.Optimized,
326+
isOptimizedMode: testConfig.isJsOptimized,
334327
hermesVariant: testConfig.hermesVariant,
335328
});
336329
}
337330

338331
const rnTesterCommandArgs = [
339332
'--bundlePath',
340-
testConfig.mode === FantomTestConfigMode.DevelopmentWithSource
341-
? testJSBundlePath
342-
: testBytecodeBundlePath,
333+
!testConfig.isJsBytecode ? testJSBundlePath : testBytecodeBundlePath,
343334
'--featureFlags',
344335
JSON.stringify(testConfig.flags.common),
345336
'--minLogLevel',
@@ -354,9 +345,7 @@ module.exports = async function runTest(
354345
: runBuck2(
355346
[
356347
'run',
357-
...getBuckModesForPlatform(
358-
testConfig.mode === FantomTestConfigMode.Optimized,
359-
),
348+
...getBuckModesForPlatform(testConfig.isNativeOptimized),
360349
...getBuckOptionsForHermes(testConfig.hermesVariant),
361350
'//xplat/js/react-native-github/private/react-native-fantom/tester:tester',
362351
'--',

private/react-native-fantom/src/__tests__/FantomModeDevBytecode-itest.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)