Unverified Commit b075229d authored by Alexander Aprelev's avatar Alexander Aprelev Committed by GitHub

Preserve original kernel file for isolate spawn requests. (#18127)

* Preserve original kernel file for isolate spawn requests.

This change gives incremental kernel files ".incremental.dill" extension thereby preserving original kernel file.

Bug: https://github.com/flutter/flutter/issues/16084
Bug: https://github.com/flutter/flutter/issues/17012
Bug: https://github.com/flutter/flutter/issues/17983

* Factor out naming logic into separate function

* Fix string vs uri
parent 1363bd17
...@@ -67,8 +67,8 @@ abstract class AssetBundle { ...@@ -67,8 +67,8 @@ abstract class AssetBundle {
final ByteData data = await load(key); final ByteData data = await load(key);
if (data == null) if (data == null)
throw new FlutterError('Unable to load asset: $key'); throw new FlutterError('Unable to load asset: $key');
if (data.lengthInBytes < 20 * 1024) { if (data.lengthInBytes < 10 * 1024) {
// 20KB takes about 6ms to parse on a Pixel 2 XL. // 10KB takes about 3ms to parse on a Pixel 2 XL.
// See: https://github.com/dart-lang/sdk/issues/31954 // See: https://github.com/dart-lang/sdk/issues/31954
return utf8.decode(data.buffer.asUint8List()); return utf8.decode(data.buffer.asUint8List());
} }
......
...@@ -442,7 +442,7 @@ class ResidentCompiler { ...@@ -442,7 +442,7 @@ class ResidentCompiler {
/// accepted previously so that next call to [recompile] produces complete /// accepted previously so that next call to [recompile] produces complete
/// kernel file. /// kernel file.
void reset() { void reset() {
_server.stdin.writeln('reset'); _server?.stdin?.writeln('reset');
} }
String _mapFilename(String filename) { String _mapFilename(String filename) {
......
...@@ -412,6 +412,7 @@ class DevFS { ...@@ -412,6 +412,7 @@ class DevFS {
String dillOutputPath, String dillOutputPath,
bool fullRestart = false, bool fullRestart = false,
String projectRootPath, String projectRootPath,
String pathToReload,
}) async { }) async {
// Mark all entries as possibly deleted. // Mark all entries as possibly deleted.
for (DevFSContent content in _entries.values) { for (DevFSContent content in _entries.values) {
...@@ -510,13 +511,12 @@ class DevFS { ...@@ -510,13 +511,12 @@ class DevFS {
packagesFilePath : _packagesFilePath); packagesFilePath : _packagesFilePath);
final String compiledBinary = compilerOutput?.outputFilename; final String compiledBinary = compilerOutput?.outputFilename;
if (compiledBinary != null && compiledBinary.isNotEmpty) { if (compiledBinary != null && compiledBinary.isNotEmpty) {
final String entryUri = projectRootPath != null ? final Uri entryUri = fs.path.toUri(projectRootPath != null ?
fs.path.relative(mainPath, from: projectRootPath): fs.path.relative(pathToReload, from: projectRootPath):
mainPath; pathToReload);
final Uri kernelUri = fs.path.toUri(entryUri + '.dill'); if (!dirtyEntries.containsKey(entryUri)) {
if (!dirtyEntries.containsKey(kernelUri)) {
final DevFSFileContent content = new DevFSFileContent(fs.file(compiledBinary)); final DevFSFileContent content = new DevFSFileContent(fs.file(compiledBinary));
dirtyEntries[kernelUri] = content; dirtyEntries[entryUri] = content;
numBytes += content.size; numBytes += content.size;
} }
} }
......
...@@ -381,6 +381,7 @@ class FlutterDevice { ...@@ -381,6 +381,7 @@ class FlutterDevice {
Set<String> fileFilter, Set<String> fileFilter,
bool fullRestart = false, bool fullRestart = false,
String projectRootPath, String projectRootPath,
String pathToReload,
}) async { }) async {
final Status devFSStatus = logger.startProgress( final Status devFSStatus = logger.startProgress(
'Syncing files to device ${device.name}...', 'Syncing files to device ${device.name}...',
...@@ -400,6 +401,7 @@ class FlutterDevice { ...@@ -400,6 +401,7 @@ class FlutterDevice {
fullRestart: fullRestart, fullRestart: fullRestart,
dillOutputPath: dillOutputPath, dillOutputPath: dillOutputPath,
projectRootPath: projectRootPath, projectRootPath: projectRootPath,
pathToReload: pathToReload
); );
} on DevFSException { } on DevFSException {
devFSStatus.cancel(); devFSStatus.cancel();
...@@ -450,6 +452,10 @@ abstract class ResidentRunner { ...@@ -450,6 +452,10 @@ abstract class ResidentRunner {
String get projectRootPath => _projectRootPath; String get projectRootPath => _projectRootPath;
String _mainPath; String _mainPath;
String get mainPath => _mainPath; String get mainPath => _mainPath;
String getReloadPath({bool fullRestart}) =>
debuggingOptions.buildInfo.previewDart2
? mainPath + (fullRestart? '' : '.incremental') + '.dill'
: mainPath;
AssetBundle _assetBundle; AssetBundle _assetBundle;
AssetBundle get assetBundle => _assetBundle; AssetBundle get assetBundle => _assetBundle;
......
...@@ -180,7 +180,7 @@ class HotRunner extends ResidentRunner { ...@@ -180,7 +180,7 @@ class HotRunner extends ResidentRunner {
return 3; return 3;
} }
final Stopwatch initialUpdateDevFSsTimer = new Stopwatch()..start(); final Stopwatch initialUpdateDevFSsTimer = new Stopwatch()..start();
final bool devfsResult = await _updateDevFS(); final bool devfsResult = await _updateDevFS(fullRestart: true);
_addBenchmarkData('hotReloadInitialDevFSSyncMilliseconds', _addBenchmarkData('hotReloadInitialDevFSSyncMilliseconds',
initialUpdateDevFSsTimer.elapsed.inMilliseconds); initialUpdateDevFSsTimer.elapsed.inMilliseconds);
if (!devfsResult) if (!devfsResult)
...@@ -324,6 +324,7 @@ class HotRunner extends ResidentRunner { ...@@ -324,6 +324,7 @@ class HotRunner extends ResidentRunner {
fileFilter: _dartDependencies, fileFilter: _dartDependencies,
fullRestart: fullRestart, fullRestart: fullRestart,
projectRootPath: projectRootPath, projectRootPath: projectRootPath,
pathToReload: getReloadPath(fullRestart: fullRestart),
); );
if (!result) if (!result)
return false; return false;
...@@ -579,7 +580,7 @@ class HotRunner extends ResidentRunner { ...@@ -579,7 +580,7 @@ class HotRunner extends ResidentRunner {
final Stopwatch vmReloadTimer = new Stopwatch()..start(); final Stopwatch vmReloadTimer = new Stopwatch()..start();
try { try {
final String entryPath = fs.path.relative( final String entryPath = fs.path.relative(
debuggingOptions.buildInfo.previewDart2 ? mainPath + '.dill' : mainPath, getReloadPath(fullRestart: false),
from: projectRootPath, from: projectRootPath,
); );
final Completer<Map<String, dynamic>> retrieveFirstReloadReport = new Completer<Map<String, dynamic>>(); final Completer<Map<String, dynamic>> retrieveFirstReloadReport = new Completer<Map<String, dynamic>>();
......
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