[kernel/flutter] Improve speed of first hot reload (#13699)
* [kernel/flutter] Improve speed of first hot reload * [kernel/flutter] Improve speed of first hot reload * Revert "[kernel/flutter] Improve speed of first hot reload" This reverts commit f3dc133878ec7405a8efb5715f1cfe720f4ea05f. * Revert "[kernel/flutter] Improve speed of first hot reload" This reverts commit f7bcb082b01cf9cf48f02c6aad9e5c79705def8f. * Revert "Revert "[kernel/flutter] Improve speed of first hot reload"" This reverts commit 73c7a1a8e85a4c0397984d8b65a98b2f71bf84f3. * [kernel/flutter] Improve speed of first hot reload Do so by not evicting unnecessary paths (while still evicting paths that was changed between the generation of the package file and the initial upload). * Fix grammar in method name * Fix bad merge * Add method to super class
This commit is contained in:
committed by
Alexander Aprelev
parent
06d12a78d7
commit
5ccd5a1e75
@@ -35,6 +35,8 @@ abstract class AssetBundle {
|
||||
|
||||
Map<String, DevFSContent> get entries;
|
||||
|
||||
bool wasBuiltOnce();
|
||||
|
||||
bool needsBuild({String manifestPath: _ManifestAssetBundle.defaultManifestPath});
|
||||
|
||||
/// Returns 0 for success; non-zero for failure.
|
||||
@@ -89,6 +91,9 @@ class _ManifestAssetBundle implements AssetBundle {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool wasBuiltOnce() => _lastBuildTimestamp != null;
|
||||
|
||||
@override
|
||||
bool needsBuild({String manifestPath: defaultManifestPath}) {
|
||||
if (_fixed)
|
||||
|
||||
@@ -34,6 +34,11 @@ abstract class DevFSContent {
|
||||
/// or if the entry has been modified since this method was last called.
|
||||
bool get isModified;
|
||||
|
||||
/// Return true if this is the first time this method is called
|
||||
/// or if the entry has been modified after the given time
|
||||
/// or if the given time is null.
|
||||
bool isModifiedAfter(DateTime time);
|
||||
|
||||
int get size;
|
||||
|
||||
Future<List<int>> contentsAsBytes();
|
||||
@@ -103,6 +108,13 @@ class DevFSFileContent extends DevFSContent {
|
||||
return _oldFileStat == null || _fileStat.modified.isAfter(_oldFileStat.modified);
|
||||
}
|
||||
|
||||
@override
|
||||
bool isModifiedAfter(DateTime time) {
|
||||
final FileStat _oldFileStat = _fileStat;
|
||||
_stat();
|
||||
return _oldFileStat == null || time == null || _fileStat.modified.isAfter(time);
|
||||
}
|
||||
|
||||
@override
|
||||
int get size {
|
||||
if (_fileStat == null)
|
||||
@@ -124,12 +136,14 @@ class DevFSByteContent extends DevFSContent {
|
||||
List<int> _bytes;
|
||||
|
||||
bool _isModified = true;
|
||||
DateTime _modificationTime = new DateTime.now();
|
||||
|
||||
List<int> get bytes => _bytes;
|
||||
|
||||
set bytes(List<int> value) {
|
||||
_bytes = value;
|
||||
_isModified = true;
|
||||
_modificationTime = new DateTime.now();
|
||||
}
|
||||
|
||||
/// Return true only once so that the content is written to the device only once.
|
||||
@@ -140,6 +154,11 @@ class DevFSByteContent extends DevFSContent {
|
||||
return modified;
|
||||
}
|
||||
|
||||
@override
|
||||
bool isModifiedAfter(DateTime time) {
|
||||
return time == null || _modificationTime.isAfter(time);
|
||||
}
|
||||
|
||||
@override
|
||||
int get size => _bytes.length;
|
||||
|
||||
@@ -383,6 +402,8 @@ class DevFS {
|
||||
String mainPath,
|
||||
String target,
|
||||
AssetBundle bundle,
|
||||
DateTime firstBuildTime,
|
||||
bool bundleFirstUpload: false,
|
||||
bool bundleDirty: false,
|
||||
Set<String> fileFilter,
|
||||
ResidentCompiler generator,
|
||||
@@ -445,10 +466,10 @@ class DevFS {
|
||||
// that isModified does not reset last check timestamp because we
|
||||
// want to report all modified files to incremental compiler next time
|
||||
// user does hot reload.
|
||||
if (content.isModified || (bundleDirty && archivePath != null)) {
|
||||
if (content.isModified || ((bundleDirty || bundleFirstUpload) && archivePath != null)) {
|
||||
dirtyEntries[deviceUri] = content;
|
||||
numBytes += content.size;
|
||||
if (archivePath != null)
|
||||
if (archivePath != null && (!bundleFirstUpload || content.isModifiedAfter(firstBuildTime)))
|
||||
assetPathsToEvict.add(archivePath);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -365,6 +365,8 @@ class FlutterDevice {
|
||||
String mainPath,
|
||||
String target,
|
||||
AssetBundle bundle,
|
||||
DateTime firstBuildTime,
|
||||
bool bundleFirstUpload: false,
|
||||
bool bundleDirty: false,
|
||||
Set<String> fileFilter,
|
||||
bool fullRestart: false
|
||||
@@ -379,6 +381,8 @@ class FlutterDevice {
|
||||
mainPath: mainPath,
|
||||
target: target,
|
||||
bundle: bundle,
|
||||
firstBuildTime: firstBuildTime,
|
||||
bundleFirstUpload: bundleFirstUpload,
|
||||
bundleDirty: bundleDirty,
|
||||
fileFilter: fileFilter,
|
||||
generator: generator,
|
||||
|
||||
@@ -66,6 +66,7 @@ class HotRunner extends ResidentRunner {
|
||||
// The initial launch is from a snapshot.
|
||||
bool _runningFromSnapshot = true;
|
||||
bool previewDart2 = false;
|
||||
DateTime firstBuildTime;
|
||||
bool strongMode = false;
|
||||
|
||||
void _addBenchmarkData(String name, int value) {
|
||||
@@ -213,6 +214,8 @@ class HotRunner extends ResidentRunner {
|
||||
return 1;
|
||||
}
|
||||
|
||||
firstBuildTime = new DateTime.now();
|
||||
|
||||
for (FlutterDevice device in flutterDevices) {
|
||||
final int result = await device.runHot(
|
||||
hotRunner: this,
|
||||
@@ -262,6 +265,7 @@ class HotRunner extends ResidentRunner {
|
||||
// Did not update DevFS because of a Dart source error.
|
||||
return false;
|
||||
}
|
||||
final bool isFirstUpload = assetBundle.wasBuiltOnce() == false;
|
||||
final bool rebuildBundle = assetBundle.needsBuild();
|
||||
if (rebuildBundle) {
|
||||
printTrace('Updating assets');
|
||||
@@ -275,7 +279,9 @@ class HotRunner extends ResidentRunner {
|
||||
mainPath: mainPath,
|
||||
target: target,
|
||||
bundle: assetBundle,
|
||||
bundleDirty: rebuildBundle,
|
||||
firstBuildTime: firstBuildTime,
|
||||
bundleFirstUpload: isFirstUpload,
|
||||
bundleDirty: isFirstUpload == false && rebuildBundle,
|
||||
fileFilter: _dartDependencies,
|
||||
fullRestart: fullRestart
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user