Skip to content

Commit c3577c2

Browse files
[devicelab] Unify web benchmarks entrypoint using BENCHMARK_SERVER_PORT define (flutter#192765)
Removes the duplicate `lib/web_benchmarks_ddc.dart` entrypoint in macrobenchmarks and unifies the entrypoint target across both DDC (`flutter run`) and non-DDC (`flutter build`) modes to `lib/web_benchmarks.dart`. - Passes `--dart-define=BENCHMARK_SERVER_PORT=$benchmarkServerPort` to `flutter run` in DDC mode to match `flutter build`. - Reads `BENCHMARK_SERVER_PORT` in `lib/web_benchmarks.dart` via `const String.fromEnvironment`, defaulting to `9999`. - Deletes `dev/benchmarks/macrobenchmarks/lib/web_benchmarks_ddc.dart`. Part of flutter#191316 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent c96c123 commit c3577c2

3 files changed

Lines changed: 11 additions & 36 deletions

File tree

‎dev/benchmarks/macrobenchmarks/lib/web_benchmarks.dart‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,11 @@ Future<void> main(List<String> args) async {
9898
'API required for orchestrating macrobenchmarks.',
9999
);
100100
final ArgResults argResults = parser.parse(args);
101-
Uri serverOrigin;
102-
if (argResults.wasParsed('port')) {
103-
final int port = int.parse(argResults['port'] as String);
104-
serverOrigin = Uri.http('localhost:$port');
105-
} else {
106-
serverOrigin = Uri.base;
107-
}
101+
const portEnv = String.fromEnvironment('BENCHMARK_SERVER_PORT');
102+
final int? port = argResults.wasParsed('port')
103+
? int.tryParse(argResults['port'] as String)
104+
: int.tryParse(portEnv);
105+
final Uri serverOrigin = port != null ? Uri.http('localhost:$port') : Uri.base;
108106

109107
_client = LocalBenchmarkServerClient(serverOrigin);
110108

@@ -120,14 +118,6 @@ Future<void> main(List<String> args) async {
120118
web.window.location.reload();
121119
}
122120

123-
/// Shared entrypoint used for DDC, which runs the macrobenchmarks server on a
124-
/// separate port.
125-
// TODO(markzipan): Use `main` in `'web_benchmarks.dart` when Flutter Web supports the `--dart-entrypoint-args` flag.
126-
// ignore: unreachable_from_main
127-
Future<void> sharedMain(List<String> args) {
128-
return main(args);
129-
}
130-
131121
Future<void> _runBenchmark(String benchmarkName) async {
132122
final RecorderFactory? recorderFactory = benchmarks[benchmarkName];
133123

‎dev/benchmarks/macrobenchmarks/lib/web_benchmarks_ddc.dart‎

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

‎dev/devicelab/lib/tasks/web_benchmarks.dart‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import '../framework/task_result.dart';
1717
import '../framework/utils.dart';
1818

1919
/// The port at which the local benchmark server is served.
20-
/// This is hard-coded and must be the same as the port used for DDC's benchmark at `flutter/dev/benchmarks/macrobenchmarks/lib/web_benchmarks_ddc.dart`.
2120
const int benchmarkServerPort = 9999;
2221

2322
/// The port at which Chrome listens for a debug connection.
@@ -188,6 +187,9 @@ Future<TaskResult> runWebBenchmark(WebBenchmarkOptions benchmarkOptions) async {
188187
try {
189188
return await inDirectory(macrobenchmarksDirectory, () async {
190189
await flutter('clean');
190+
191+
server = await io.HttpServer.bind('localhost', benchmarkServerPort);
192+
191193
// DDC runs the benchmarks suite with 'flutter run', attaching to its
192194
// Chrome instance instead of starting a new one.
193195
if (benchmarkOptions.useDdc) {
@@ -225,9 +227,11 @@ Future<TaskResult> runWebBenchmark(WebBenchmarkOptions benchmarkOptions) async {
225227
'--web-browser-flag=--password-store=basic',
226228
if (io.Platform.isMacOS) '--web-browser-flag=--use-mock-keychain',
227229
'--dart-define=FLUTTER_WEB_ENABLE_PROFILING=true',
230+
'--dart-define=BENCHMARK_SERVER_PORT=${server!.port}',
228231
if (!benchmarkOptions.withHotReload) '--no-web-experimental-hot-reload',
229232
'--no-web-resources-cdn',
230-
'lib/web_benchmarks_ddc.dart',
233+
'-t',
234+
'lib/web_benchmarks.dart',
231235
],
232236
);
233237
flutterRunProcess!.stdout.transform(utf8.decoder).transform(const LineSplitter()).listen((
@@ -373,7 +377,6 @@ Future<TaskResult> runWebBenchmark(WebBenchmarkOptions benchmarkOptions) async {
373377
);
374378
}
375379

376-
server = await io.HttpServer.bind('localhost', benchmarkServerPort);
377380
shelf_io.serveRequests(server!, cascade.handler);
378381

379382
final String dartToolDirectory = path.join(macrobenchmarksDirectory, '.dart_tool');

0 commit comments

Comments
 (0)