Commit 5ccd5a1e authored by jensjoha's avatar jensjoha Committed by Alexander Aprelev

[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
parent 06d12a78
...@@ -35,6 +35,8 @@ abstract class AssetBundle { ...@@ -35,6 +35,8 @@ abstract class AssetBundle {
Map<String, DevFSContent> get entries; Map<String, DevFSContent> get entries;
bool wasBuiltOnce();
bool needsBuild({String manifestPath: _ManifestAssetBundle.defaultManifestPath}); bool needsBuild({String manifestPath: _ManifestAssetBundle.defaultManifestPath});
/// Returns 0 for success; non-zero for failure. /// Returns 0 for success; non-zero for failure.
...@@ -89,6 +91,9 @@ class _ManifestAssetBundle implements AssetBundle { ...@@ -89,6 +91,9 @@ class _ManifestAssetBundle implements AssetBundle {
} }
} }
@override
bool wasBuiltOnce() => _lastBuildTimestamp != null;
@override @override
bool needsBuild({String manifestPath: defaultManifestPath}) { bool needsBuild({String manifestPath: defaultManifestPath}) {
if (_fixed) if (_fixed)
......
...@@ -34,6 +34,11 @@ abstract class DevFSContent { ...@@ -34,6 +34,11 @@ abstract class DevFSContent {
/// or if the entry has been modified since this method was last called. /// or if the entry has been modified since this method was last called.
bool get isModified; 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; int get size;
Future<List<int>> contentsAsBytes(); Future<List<int>> contentsAsBytes();
...@@ -103,6 +108,13 @@ class DevFSFileContent extends DevFSContent { ...@@ -103,6 +108,13 @@ class DevFSFileContent extends DevFSContent {
return _oldFileStat == null || _fileStat.modified.isAfter(_oldFileStat.modified); 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 @override
int get size { int get size {
if (_fileStat == null) if (_fileStat == null)
...@@ -124,12 +136,14 @@ class DevFSByteContent extends DevFSContent { ...@@ -124,12 +136,14 @@ class DevFSByteContent extends DevFSContent {
List<int> _bytes; List<int> _bytes;
bool _isModified = true; bool _isModified = true;
DateTime _modificationTime = new DateTime.now();
List<int> get bytes => _bytes; List<int> get bytes => _bytes;
set bytes(List<int> value) { set bytes(List<int> value) {
_bytes = value; _bytes = value;
_isModified = true; _isModified = true;
_modificationTime = new DateTime.now();
} }
/// Return true only once so that the content is written to the device only once. /// Return true only once so that the content is written to the device only once.
...@@ -140,6 +154,11 @@ class DevFSByteContent extends DevFSContent { ...@@ -140,6 +154,11 @@ class DevFSByteContent extends DevFSContent {
return modified; return modified;
} }
@override
bool isModifiedAfter(DateTime time) {
return time == null || _modificationTime.isAfter(time);
}
@override @override
int get size => _bytes.length; int get size => _bytes.length;
...@@ -383,6 +402,8 @@ class DevFS { ...@@ -383,6 +402,8 @@ class DevFS {
String mainPath, String mainPath,
String target, String target,
AssetBundle bundle, AssetBundle bundle,
DateTime firstBuildTime,
bool bundleFirstUpload: false,
bool bundleDirty: false, bool bundleDirty: false,
Set<String> fileFilter, Set<String> fileFilter,
ResidentCompiler generator, ResidentCompiler generator,
...@@ -445,10 +466,10 @@ class DevFS { ...@@ -445,10 +466,10 @@ class DevFS {
// that isModified does not reset last check timestamp because we // that isModified does not reset last check timestamp because we
// want to report all modified files to incremental compiler next time // want to report all modified files to incremental compiler next time
// user does hot reload. // user does hot reload.
if (content.isModified || (bundleDirty && archivePath != null)) { if (content.isModified || ((bundleDirty || bundleFirstUpload) && archivePath != null)) {
dirtyEntries[deviceUri] = content; dirtyEntries[deviceUri] = content;
numBytes += content.size; numBytes += content.size;
if (archivePath != null) if (archivePath != null && (!bundleFirstUpload || content.isModifiedAfter(firstBuildTime)))
assetPathsToEvict.add(archivePath); assetPathsToEvict.add(archivePath);
} }
}); });
......
...@@ -365,6 +365,8 @@ class FlutterDevice { ...@@ -365,6 +365,8 @@ class FlutterDevice {
String mainPath, String mainPath,
String target, String target,
AssetBundle bundle, AssetBundle bundle,
DateTime firstBuildTime,
bool bundleFirstUpload: false,
bool bundleDirty: false, bool bundleDirty: false,
Set<String> fileFilter, Set<String> fileFilter,
bool fullRestart: false bool fullRestart: false
...@@ -379,6 +381,8 @@ class FlutterDevice { ...@@ -379,6 +381,8 @@ class FlutterDevice {
mainPath: mainPath, mainPath: mainPath,
target: target, target: target,
bundle: bundle, bundle: bundle,
firstBuildTime: firstBuildTime,
bundleFirstUpload: bundleFirstUpload,
bundleDirty: bundleDirty, bundleDirty: bundleDirty,
fileFilter: fileFilter, fileFilter: fileFilter,
generator: generator, generator: generator,
......
...@@ -66,6 +66,7 @@ class HotRunner extends ResidentRunner { ...@@ -66,6 +66,7 @@ class HotRunner extends ResidentRunner {
// The initial launch is from a snapshot. // The initial launch is from a snapshot.
bool _runningFromSnapshot = true; bool _runningFromSnapshot = true;
bool previewDart2 = false; bool previewDart2 = false;
DateTime firstBuildTime;
bool strongMode = false; bool strongMode = false;
void _addBenchmarkData(String name, int value) { void _addBenchmarkData(String name, int value) {
...@@ -213,6 +214,8 @@ class HotRunner extends ResidentRunner { ...@@ -213,6 +214,8 @@ class HotRunner extends ResidentRunner {
return 1; return 1;
} }
firstBuildTime = new DateTime.now();
for (FlutterDevice device in flutterDevices) { for (FlutterDevice device in flutterDevices) {
final int result = await device.runHot( final int result = await device.runHot(
hotRunner: this, hotRunner: this,
...@@ -262,6 +265,7 @@ class HotRunner extends ResidentRunner { ...@@ -262,6 +265,7 @@ class HotRunner extends ResidentRunner {
// Did not update DevFS because of a Dart source error. // Did not update DevFS because of a Dart source error.
return false; return false;
} }
final bool isFirstUpload = assetBundle.wasBuiltOnce() == false;
final bool rebuildBundle = assetBundle.needsBuild(); final bool rebuildBundle = assetBundle.needsBuild();
if (rebuildBundle) { if (rebuildBundle) {
printTrace('Updating assets'); printTrace('Updating assets');
...@@ -275,7 +279,9 @@ class HotRunner extends ResidentRunner { ...@@ -275,7 +279,9 @@ class HotRunner extends ResidentRunner {
mainPath: mainPath, mainPath: mainPath,
target: target, target: target,
bundle: assetBundle, bundle: assetBundle,
bundleDirty: rebuildBundle, firstBuildTime: firstBuildTime,
bundleFirstUpload: isFirstUpload,
bundleDirty: isFirstUpload == false && rebuildBundle,
fileFilter: _dartDependencies, fileFilter: _dartDependencies,
fullRestart: fullRestart fullRestart: fullRestart
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment