Skip to content

Rerunning the same flutter test test on a target device causes a full rebuild every time #108400

@jmagman

Description

@jmagman

flutter test is taking almost the same amount of time on a second run as the first, when the app should already be built.
On iOS this causes every test run to take an additional ~15 seconds.

test is subverting flutter assemble caching logic by passing in a new temp directory target listener.dart path every run, even when running the same test. This causes the build system to create a new build directory from the hash of the inputs including TargetFile.

for (final String key in keys) {
buffer.write(key);
buffer.write(defines[key]);
}
buffer.write(outputDir.path);
final String output = buffer.toString();
final Digest digest = md5.convert(utf8.encode(output));
buildPrefix = hex.encode(digest.bytes);

Every subsequent test run shows the assemble steps as needing a rerun due to InvalidatedReasonKind.inputChanged since each new build directory is missing the file store cache file from the last run:

            [  +31 ms] debug_unpack_ios: Starting due to {InvalidatedReasonKind.inputChanged: The following inputs have updated contents: /Users/m/Projects/flutter/packages/flutter_tools/lib/src/build_system/targets/ios.dart,/Users/magder/Projects/flutter/bin/internal/engine.version}
            [+1026 ms] Skipping target: gen_localizations
            [   +5 ms] gen_dart_plugin_registrant: Starting due to {InvalidatedReasonKind.inputChanged: The following inputs have updated contents: /Users/m/Projects/plugins/packages/google_maps_flutter/google_maps_flutter/example/.dart_tool/package_config_subset}
            [   +4 ms] debug_unpack_ios: Complete
...
            [   +6 ms] gen_dart_plugin_registrant: Complete

For example, in google_maps_flutter example project running the same command twice:

$ flutter --no-color test --machine --start-paused --plain-name testGetVisibleRegion  -v integration_test/google_maps_test.dart

calls identical assemble except for the different -dTargetFiles:

--verbose assemble --no-version-check --output=/Users/m/Projects/plugins/packages/google_maps_flutter/google_maps_flutter/example/build/ios/Debug-iphonesimulator/ -dTargetPlatform=ios -dTargetFile=/var/folders/bx/pyplw7v92lj58gm3_lztz5sc00mfq2/T/flutter_tools.5RYflD/flutter_test_listener.sO5mgy/listener.dart -dBuildMode=debug -dIosArchs=x86_64 -dSdkRoot=/Users/m/Applications/Xcode-14_beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.0.sdk -dSplitDebugInfo= -dTreeShakeIcons=false -dTrackWidgetCreation=true -dDartObfuscation=false -dEnableBitcode= --ExtraGenSnapshotOptions= --DartDefines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,SU5URUdSQVRJT05fVEVTVF9TSE9VTERfUkVQT1JUX1JFU1VMVFNfVE9fTkFUSVZFPWZhbHNl --ExtraFrontEndOptions= -dCodesignIdentity=- debug_ios_bundle_flutter_assets

--verbose assemble --no-version-check --output=/Users/m/Projects/plugins/packages/google_maps_flutter/google_maps_flutter/example/build/ios/Debug-iphonesimulator/ -dTargetPlatform=ios -dTargetFile=/var/folders/bx/pyplw7v92lj58gm3_lztz5sc00mfq2/T/flutter_tools.r0Vvcj/flutter_test_listener.uguobQ/listener.dart -dBuildMode=debug -dIosArchs=x86_64 -dSdkRoot=/Users/m/Applications/Xcode-14_beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.0.sdk -dSplitDebugInfo= -dTreeShakeIcons=false -dTrackWidgetCreation=true -dDartObfuscation=false -dEnableBitcode= --ExtraGenSnapshotOptions= --DartDefines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,SU5URUdSQVRJT05fVEVTVF9TSE9VTERfUkVQT1JUX1JFU1VMVFNfVE9fTkFUSVZFPWZhbHNl --ExtraFrontEndOptions= -dCodesignIdentity=- debug_ios_bundle_flutter_assets

// Prepare a temporary directory to store the Dart file that will talk to us.
final Directory tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_test_listener.');
finalizers.add(() async {
globals.printTrace('test $ourTestCount: deleting temporary directory');
tempDir.deleteSync(recursive: true);
});
// Prepare the Dart file that will talk to us and start the test.
final File listenerFile = globals.fs.file('${tempDir.path}/listener.dart');

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listperf: speedPerformance issues related to (mostly rendering) speedteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    Status

    Future bugs/improvements

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions