Skip to content

Commit 7035255

Browse files
authored
make compiler worker count configurable (flutter#17616)
* make compiler worker count configurable
1 parent 68bf137 commit 7035255

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

lib/web_ui/dev/README.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
## What's `felt`?
2+
23
`felt` stands for "Flutter Engine Local Tester". It's a cli tool that aims to make development in the Flutter web engine more productive and pleasant.
34

45
## What can `felt` do?
6+
57
`felt` supports multiple commands as follows:
68

79
1. **`felt check-licenses`**: Checks that all Dart and JS source code files contain the correct license headers.
@@ -11,26 +13,40 @@
1113
You could also run `felt help` or `felt help <command>` to get more information about the available commands and arguments.
1214

1315
## How can I use `felt`?
16+
1417
Once you have your local copy of the engine [setup](https://github.com/flutter/flutter/wiki/Setting-up-the-Engine-development-environment), it's recommended that you add `/path/to/engine/src/flutter/lib/web_ui/dev` to your `PATH`.
1518
Then you would be able to use the `felt` tool from anywhere:
19+
1620
```
1721
felt check-licenses
1822
```
23+
1924
or:
25+
2026
```
2127
felt build --watch
2228
```
2329

2430
If you don't want to add `felt` to your path, you can still invoke it using a relative path like `./web_ui/dev/felt <command>`
2531

26-
## Speeding up your builds
27-
You can speed up your builds by using more CPU cores. Pass `-j` to specify the desired level of parallelism, like so:
32+
## Speeding up your builds and tests
33+
34+
You can speed up `ninja` and `dart2js` by adding parallelism and taking advantage of more cores.
35+
36+
To speed up ninja pass `-j` to specify the desired level of parallelism, like so:
37+
2838
```
2939
felt build [-w] -j 100
3040
```
41+
3142
If you are a Google employee, you can use an internal instance of Goma to parallelize your builds. Because Goma compiles code on remote servers, this option is effective even on low-powered laptops.
3243

44+
By default, when compiling Dart code to JavaScript, we use 4 `dart2js` workers.
45+
If you need to increase or reduce the number of workers, set the `BUILD_MAX_WORKERS_PER_TASK`
46+
environment variable to the desired number.
47+
3348
## Running web engine tests
49+
3450
To run all tests on Chrome. This will run both integration tests and the unit tests:
3551

3652
```
@@ -86,6 +102,7 @@ felt test test/golden_tests/engine/canvas_golden_test.dart
86102
```
87103

88104
To debug a test on Chrome:
105+
89106
```
90107
felt test --debug test/golden_tests/engine/canvas_golden_test.dart
91108
```
@@ -110,7 +127,9 @@ To make sure you are running the `felt` tool with your changes included, you wou
110127
```
111128
FELT_USE_SNAPSHOT=false felt <command>
112129
```
130+
113131
or
132+
114133
```
115134
FELT_USE_SNAPSHOT=0 felt <command>
116135
```

lib/web_ui/dev/test_runner.dart

+14
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,25 @@ class TestCommand extends Command<bool> with ArgUtils {
392392
'--build-filter=${path.relativeToWebUi}.browser_test.dart.js',
393393
],
394394
];
395+
final Stopwatch stopwatch = Stopwatch()..start();
396+
395397
final int exitCode = await runProcess(
396398
environment.pubExecutable,
397399
arguments,
398400
workingDirectory: environment.webUiRootDir.path,
401+
environment: <String, String>{
402+
// This determines the number of concurrent dart2js processes.
403+
//
404+
// By default build_runner uses 4 workers.
405+
//
406+
// In a testing on a 32-core 132GB workstation increasing this number to
407+
// 32 sped up the build from ~4min to ~1.5min.
408+
if (io.Platform.environment.containsKey('BUILD_MAX_WORKERS_PER_TASK'))
409+
'BUILD_MAX_WORKERS_PER_TASK': io.Platform.environment['BUILD_MAX_WORKERS_PER_TASK'],
410+
},
399411
);
412+
stopwatch.stop();
413+
print('The build took ${stopwatch.elapsedMilliseconds ~/ 1000} seconds.');
400414

401415
if (exitCode != 0) {
402416
throw ToolException(

lib/web_ui/dev/utils.dart

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Future<int> runProcess(
4141
List<String> arguments, {
4242
String workingDirectory,
4343
bool mustSucceed: false,
44+
Map<String, String> environment = const <String, String>{},
4445
}) async {
4546
final io.Process process = await io.Process.start(
4647
executable,
@@ -50,6 +51,7 @@ Future<int> runProcess(
5051
// the process is not able to get Dart from path.
5152
runInShell: io.Platform.isWindows,
5253
mode: io.ProcessStartMode.inheritStdio,
54+
environment: environment,
5355
);
5456
final int exitCode = await process.exitCode;
5557
if (mustSucceed && exitCode != 0) {

0 commit comments

Comments
 (0)