From cb19eac08e27c4a3d4c7b277abdb6a4d61cf5f3a Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Wed, 15 May 2024 12:57:02 -0700 Subject: [PATCH] Short-circuit crawling all targets in `et {build|test|query}` (flutter/engine#52832) Closes https://github.com/flutter/flutter/issues/147666. This is a large change, I'd be happy to either review synchronously or change commands one at a time, but I think this is overall the right approach. I also didn't see any reason to reuse the `BuildRunner` code for these commands, the flow is basically: ```mermaid graph LR A[et targetsOrPatterns] --> B[gn desc --format=json] B --> C[existing code that runs ninja/workers] ``` Quick summary of changes: - Introduced a [`Label` and `TargetPattern`][1] type to avoid awkward string parsing/manipulation all over - Replaced `gn_utils` (i.e. `targetsFromCommandLine` and friends) with [an invocation of `gn desc`][2] - Some tests were brittle in terms of expected output, I mostly left them alone and wrote TODOs where applicable Here is the fun part, results (and some manual integration tests): ```sh # build, previously was 10-15s, is now ~3s flutter % time et build -c host_debug_unopt_arm64 //flutter/impeller:impeller_unittests [2024-05-14T19:05:55.163][macos/host_debug_unopt_arm64: GN]: OK [2024-05-14T19:05:56.119][macos/host_debug_unopt_arm64: RBE startup]: Proxy started successfully. [macos/host_debug_unopt_arm64: ninja] 0.0% (0/1) Regenerating ninja files[2024-05-14T19:05:57.309][macos/host_debug_unopt_arm64: ninja]: OK [2024-05-14T19:05:57.573][macos/host_debug_unopt_arm64: RBE shutdown]: Actions completed: 0 $ENGINE/flutter/bin/et build -c host_debug_unopt_arm64 3.20s user 0.87s system 107% cpu 3.776 total # test, also benefits from speedup, but I didn't time it flutter % et test -c host_debug_unopt_arm64 //flutter/fml:fml_unittests [2024-05-14T19:07:01.843][macos/host_debug_unopt_arm64: GN]: OK [2024-05-14T19:07:02.707][macos/host_debug_unopt_arm64: RBE startup]: Proxy started successfully. [2024-05-14T19:07:07.400][macos/host_debug_unopt_arm64: ninja]: 100.0% (3/3) LINK ./fml_unittests [2024-05-14T19:07:07.404][macos/host_debug_unopt_arm64: ninja]: OK [2024-05-14T19:07:07.748][macos/host_debug_unopt_arm64: RBE shutdown]: Actions completed: 1 (1 racing local) OKAY: 7s.95ms //flutter/fml:fml_unittests # query, also benefits from speedup flutter % time et query targets -c host_debug_unopt_arm64 //flutter/display_list:display_list_benchmarks //flutter/display_list:display_list_builder_benchmarks # ... many targets omitted ... $ENGINE/flutter/bin/et query targets -c host_debug_unopt_arm64 1.27s user 0.18s system 147% cpu 0.978 total ``` In other words, ~5x improvement on `et build` and `et query` is _much_ faster as well. [1]: https://github.com/flutter/engine/compare/main...matanlurey:engine:gn-label?expand=1#diff-ac008475ce9e209f4ecf6594b0cd48d12d86a1ffa0aa7d555375ff43b983eb2b [2]: https://github.com/flutter/engine/compare/main...matanlurey:engine:gn-label?expand=1#diff-ad116b8504dd0a500bf758a327c7052e5733a2b465d3295e35b74458d483276f --- .../engine_tool/lib/src/build_utils.dart | 5 +- .../lib/src/commands/build_command.dart | 39 ++- .../lib/src/commands/command_runner.dart | 4 +- .../lib/src/commands/lint_command.dart | 1 - .../lib/src/commands/query_command.dart | 47 +-- .../lib/src/commands/test_command.dart | 82 +++--- .../flutter/tools/engine_tool/lib/src/gn.dart | 187 ++++++++++++ .../tools/engine_tool/lib/src/gn_utils.dart | 273 ------------------ .../tools/engine_tool/lib/src/label.dart | 250 ++++++++++++++++ .../tools/engine_tool/lib/src/logger.dart | 2 +- .../tools/engine_tool/lib/src/typed_json.dart | 7 + .../engine_tool/test/build_command_test.dart | 6 +- .../tools/engine_tool/test/gn_utils_test.dart | 129 --------- .../tools/engine_tool/test/label_test.dart | 94 ++++++ .../engine_tool/test/query_command_test.dart | 26 +- .../engine_tool/test/test_command_test.dart | 53 +++- 16 files changed, 694 insertions(+), 511 deletions(-) create mode 100644 engine/src/flutter/tools/engine_tool/lib/src/gn.dart delete mode 100644 engine/src/flutter/tools/engine_tool/lib/src/gn_utils.dart create mode 100644 engine/src/flutter/tools/engine_tool/lib/src/label.dart delete mode 100644 engine/src/flutter/tools/engine_tool/test/gn_utils_test.dart create mode 100644 engine/src/flutter/tools/engine_tool/test/label_test.dart diff --git a/engine/src/flutter/tools/engine_tool/lib/src/build_utils.dart b/engine/src/flutter/tools/engine_tool/lib/src/build_utils.dart index 5018b01a16..0674129dd3 100644 --- a/engine/src/flutter/tools/engine_tool/lib/src/build_utils.dart +++ b/engine/src/flutter/tools/engine_tool/lib/src/build_utils.dart @@ -5,6 +5,7 @@ import 'package:engine_build_configs/engine_build_configs.dart'; import 'environment.dart'; +import 'label.dart'; import 'logger.dart'; /// A function that returns true or false when given a [BuilderConfig] and its @@ -121,7 +122,7 @@ Future runBuild( Build build, { required bool enableRbe, List extraGnArgs = const [], - List targets = const [], + List