Skip to content

Commit 8ebc33e

Browse files
rubennortemeta-codesync[bot]
authored andcommitted
Run benchmarks in test mode by default instead of excluding them (#56418)
Summary: Pull Request resolved: #56418 Changelog: [internal] D92150163 excluded benchmark tests by default when running `yarn fantom` without `--benchmarks`. This was incorrect because it means benchmarks could silently break without being caught. This changes the behavior so: 1. By default (without `--benchmarks`), benchmarks run in test mode (single iteration for correctness only), ensuring they do not break. 2. With `--benchmarks`, benchmarks run in full benchmark mode (multiple iterations for performance measurement). Also renames `FANTOM_FORCE_TEST_MODE` to `FANTOM_RUN_BENCHMARKS` and `forceTestModeForBenchmarks` to `runBenchmarks` to better reflect the intent (opt-in to full benchmarks rather than opt-in to test mode). Differential Revision: D100464314
1 parent 8629a34 commit 8ebc33e

File tree

6 files changed

+23
-31
lines changed

6 files changed

+23
-31
lines changed

private/react-native-fantom/config/jest.config.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ module.exports = {
2929
] /*:: as ReadonlyArray<string> */,
3030
// This allows running Meta-internal tests with the `-test.fb.js` suffix.
3131
testRegex: '/__tests__/.*-itest(\\.fb)?\\.js$',
32-
testPathIgnorePatterns: [
33-
...baseConfig.testPathIgnorePatterns,
34-
...(process.env.FANTOM_INCLUDE_BENCHMARKS != null
35-
? []
36-
: ['benchmark-itest']),
37-
] /*:: as ReadonlyArray<string> */,
32+
testPathIgnorePatterns: baseConfig.testPathIgnorePatterns,
3833
transformIgnorePatterns: ['.*'],
3934
testRunner: '<rootDir>/private/react-native-fantom/runner/index.js',
4035
watchPathIgnorePatterns: ['<rootDir>/private/react-native-fantom/build/'],

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ const VALID_ENVIRONMENT_VARIABLES = [
1515
'FANTOM_ENABLE_CPP_DEBUGGING',
1616
'FANTOM_FORCE_CI_MODE',
1717
'FANTOM_FORCE_OSS_BUILD',
18-
'FANTOM_FORCE_TEST_MODE',
19-
'FANTOM_INCLUDE_BENCHMARKS',
18+
'FANTOM_RUN_BENCHMARKS',
2019
'FANTOM_LOG_COMMANDS',
2120
'FANTOM_PRINT_OUTPUT',
2221
'FANTOM_DEBUG_JS',
@@ -60,11 +59,12 @@ export const isCI: boolean =
6059
Boolean(process.env.GITHUB_ACTIONS);
6160

6261
/**
63-
* Forces benchmarks to run in test mode (running a single time to ensure
64-
* correctness instead of multiples times to measure performance).
62+
* Runs benchmarks in benchmark mode (measuring performance with multiple
63+
* iterations). When false, benchmarks run in test mode (single iteration
64+
* for correctness only).
6565
*/
66-
export const forceTestModeForBenchmarks: boolean = Boolean(
67-
process.env.FANTOM_FORCE_TEST_MODE,
66+
export const runBenchmarks: boolean = Boolean(
67+
process.env.FANTOM_RUN_BENCHMARKS,
6868
);
6969

7070
export const debugJS: boolean = Boolean(process.env.FANTOM_DEBUG_JS);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = function entrypointTemplate({
3737
const constants: FantomRuntimeConstants = {
3838
isOSS: EnvironmentOptions.isOSS,
3939
isRunningFromCI: EnvironmentOptions.isCI,
40-
forceTestModeForBenchmarks: EnvironmentOptions.forceTestModeForBenchmarks,
40+
runBenchmarks: EnvironmentOptions.runBenchmarks,
4141
fantomConfigSummary: formatFantomConfig(testConfig),
4242
jsTraceOutputPath,
4343
jsHeapSnapshotOutputPathTemplate,

private/react-native-fantom/src/Benchmark.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ export function suite(
113113
throw new Error('No benchmark tests defined');
114114
}
115115

116-
const {isRunningFromCI, forceTestModeForBenchmarks} = getConstants();
116+
const {isRunningFromCI, runBenchmarks} = getConstants();
117117

118118
// If we're running from CI and there's no verification function, there's
119119
// no point in running the benchmark.
120120
// We still run a single iteration of each test just to make sure that the
121121
// logic in the benchmark doesn't break.
122122
const isTestOnly =
123123
suiteOptions.testOnly === true ||
124-
forceTestModeForBenchmarks ||
124+
!runBenchmarks ||
125125
(isRunningFromCI && verifyFns.length === 0);
126126

127127
const benchOptions: BenchOptions = isTestOnly
@@ -180,7 +180,11 @@ export function suite(
180180
bench.add(task.name, task.fn, options);
181181
}
182182

183-
if (!isTestOnly) {
183+
if (isTestOnly) {
184+
console.log(
185+
`Running benchmark in test mode: ${suiteName}. Use --benchmarks to run in benchmark mode.`,
186+
);
187+
} else {
184188
console.log(`Running benchmark: ${suiteName}. Please wait.`);
185189
}
186190

private/react-native-fantom/src/Constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
export type FantomRuntimeConstants = Readonly<{
1212
isOSS: boolean,
1313
isRunningFromCI: boolean,
14-
forceTestModeForBenchmarks: boolean,
14+
runBenchmarks: boolean,
1515
fantomConfigSummary: string,
1616
jsHeapSnapshotOutputPathTemplate: string,
1717
jsHeapSnapshotOutputPathTemplateToken: string,
@@ -21,7 +21,7 @@ export type FantomRuntimeConstants = Readonly<{
2121
let constants: FantomRuntimeConstants = {
2222
isOSS: false,
2323
isRunningFromCI: false,
24-
forceTestModeForBenchmarks: false,
24+
runBenchmarks: false,
2525
fantomConfigSummary: '',
2626
jsHeapSnapshotOutputPathTemplate: '',
2727
jsHeapSnapshotOutputPathTemplateToken: '',

scripts/fantom.sh

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,13 @@ fi
1818

1919
export NODE_OPTIONS='--max-old-space-size=8192'
2020

21-
# Parse arguments to check for --benchmarks flag
22-
INCLUDE_BENCHMARKS=false
21+
# Parse arguments to extract custom flags
2322
ARGS=()
2423
for arg in "$@"; do
25-
if [[ "$arg" == "--benchmarks" ]]; then
26-
INCLUDE_BENCHMARKS=true
27-
else
28-
ARGS+=("$arg")
29-
fi
24+
case "$arg" in
25+
--benchmarks) export FANTOM_RUN_BENCHMARKS=1 ;;
26+
*) ARGS+=("$arg") ;;
27+
esac
3028
done
3129

32-
# When --benchmarks is passed, set env var so jest.config.js includes benchmark tests
33-
if [[ "$INCLUDE_BENCHMARKS" == true ]]; then
34-
FANTOM_INCLUDE_BENCHMARKS=1 yarn jest --config private/react-native-fantom/config/jest.config.js "${ARGS[@]}"
35-
else
36-
yarn jest --config private/react-native-fantom/config/jest.config.js "${ARGS[@]}"
37-
fi
30+
yarn jest --config private/react-native-fantom/config/jest.config.js "${ARGS[@]}"

0 commit comments

Comments
 (0)