Don't generate plugin registry in ResidentWebRunner (#91281)

* Don't generate plugin registry in ResidentWebRunner

generateDartPluginRegistry was being set to true unconditionally in
ResidentRunner, bypassing the primary check in
DartPluginRegistrantTarget, and the targetPlatform was not set in that
codepath, bypassing the second after the changes in
https://github.com/flutter/flutter/pull/87991. This caused web hot
restarts to be slower due to doing unnecessary work.

This ensures that generateDartPluginRegistry is false in the
ResidentWebRunner to skip that unnecessary step.

Fixes https://github.com/flutter/flutter/issues/91262

* Formatting

Co-authored-by: Zachary Anderson <zanderso@users.noreply.github.com>

Co-authored-by: Zachary Anderson <zanderso@users.noreply.github.com>
This commit is contained in:
stuartmorgan 2021-10-05 15:27:53 -04:00 committed by GitHub
parent 947ffa1f90
commit 64fd68ed42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 1 deletions

View File

@ -66,6 +66,8 @@ class DartPluginRegistrantTarget extends Target {
// TODO(stuartmorgan): Investigate removing this check entirely; ideally the
// source generation step shouldn't be platform dependent, and the generated
// code should just do the right thing on every platform.
// Failing that, consider throwing if `targetPlatform` isn't set and finding
// all violations, as it's not consistently set here.
return targetPlatform == TargetPlatform.fuchsia_arm64 ||
targetPlatform == TargetPlatform.fuchsia_x64 ||
targetPlatform == TargetPlatform.web_javascript;

View File

@ -145,6 +145,10 @@ class ResidentWebRunner extends ResidentRunner {
@override
bool get supportsWriteSkSL => false;
@override
// Web uses a different plugin registry.
bool get generateDartPluginRegistry => false;
bool get _enableDwds => debuggingEnabled;
ConnectionResult _connectionResult;

View File

@ -1101,6 +1101,10 @@ abstract class ResidentRunner extends ResidentHandlers {
bool get trackWidgetCreation => debuggingOptions.buildInfo.trackWidgetCreation;
/// True if the shared Dart plugin registry (which is different than the one
/// used for web) should be generated during source generation.
bool get generateDartPluginRegistry => true;
// Returns the Uri of the first connected device for mobile,
// and only connected device for web.
//
@ -1152,7 +1156,7 @@ abstract class ResidentRunner extends ResidentHandlers {
processManager: globals.processManager,
platform: globals.platform,
projectDir: globals.fs.currentDirectory,
generateDartPluginRegistry: true,
generateDartPluginRegistry: generateDartPluginRegistry,
);
final CompositeTarget compositeTarget = CompositeTarget(<Target>[

View File

@ -941,6 +941,47 @@ void main() {
ProcessManager: () => processManager,
});
// While this file should be ignored on web, generating it here will cause a
// perf regression in hot restart.
testUsingContext('Does not generate generated_main.dart', () async {
// Create necessary files for [DartPluginRegistrantTarget]
final File packageConfig = globals.fs.directory('.dart_tool')
.childFile('package_config.json');
packageConfig.createSync(recursive: true);
packageConfig.writeAsStringSync('''
{
"configVersion": 2,
"packages": [
{
"name": "path_provider_linux",
"rootUri": "../../../path_provider_linux",
"packageUri": "lib/",
"languageVersion": "2.12"
}
]
}
''');
// Start with a generated_main.dart file.
globals.fs.directory('.dart_tool')
.childDirectory('flutter_build')
.childFile('generated_main.dart')
.createSync(recursive: true);
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
await residentWebRunner.runSourceGenerators();
// generated_main.dart should be untouched, indicating that its
// generation didn't run. If it had run, the file would have been removed as
// there are no plugins in the project.
expect(project.dartPluginRegistrant.existsSync(), true);
expect(project.dartPluginRegistrant.readAsStringSync(), '');
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('Successfully turns WebSocketException into ToolExit', () async {
final BufferLogger logger = BufferLogger.test();
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: logger);