Skip to content

Commit f5efdf6

Browse files
committed
Get rid of isolate buffering.
Since we don't load isolates from code being generated by the main isolate, there's no need to work around dart-lang/sdk#12617. This dramatically decreases load times for VM tests.
1 parent 70287f3 commit f5efdf6

File tree

2 files changed

+8
-41
lines changed

2 files changed

+8
-41
lines changed

lib/src/util/dart.dart

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,55 +31,21 @@ Future<IsolateWrapper> runInIsolate(String code, message, {packageRoot}) async {
3131
var dir = createTempDir();
3232
var dartPath = p.join(dir, 'runInIsolate.dart');
3333
new File(dartPath).writeAsStringSync(code);
34-
var port = new ReceivePort();
3534

36-
try {
37-
var isolate = await Isolate.spawn(_isolateBuffer, {
38-
'replyTo': port.sendPort,
39-
'uri': p.toUri(dartPath).toString(),
40-
'packageRoot': packageRoot == null ? null : packageRoot.toString(),
41-
'message': message
42-
});
43-
44-
var response = await port.first;
45-
if (response['type'] != 'error') {
46-
return new IsolateWrapper(isolate,
47-
() => new Directory(dir).deleteSync(recursive: true));
48-
}
35+
if (packageRoot is String) packageRoot = Uri.parse(packageRoot);
4936

50-
isolate.kill();
51-
var asyncError = RemoteException.deserialize(response['error']);
52-
await new Future.error(asyncError.error, asyncError.stackTrace);
53-
throw 'unreachable';
37+
try {
38+
var isolate = await Isolate.spawnUri(
39+
p.toUri(dartPath), [], message,
40+
packageRoot: packageRoot);
41+
return new IsolateWrapper(isolate,
42+
() => new Directory(dir).deleteSync(recursive: true));
5443
} catch (error) {
5544
new Directory(dir).deleteSync(recursive: true);
5645
rethrow;
5746
}
5847
}
5948

60-
// TODO(nweiz): remove this when issue 12617 is fixed.
61-
/// A function used as a buffer between the host isolate and [spawnUri].
62-
///
63-
/// [spawnUri] synchronously loads the file and its imports, which can deadlock
64-
/// the host isolate if there's an HTTP import pointing at a server in the host.
65-
/// Adding an additional isolate in the middle works around this.
66-
Future _isolateBuffer(message) async {
67-
var replyTo = message['replyTo'];
68-
var packageRoot = message['packageRoot'];
69-
if (packageRoot != null) packageRoot = Uri.parse(packageRoot);
70-
71-
try {
72-
await Isolate.spawnUri(Uri.parse(message['uri']), [], message['message'],
73-
packageRoot: packageRoot);
74-
replyTo.send({'type': 'success'});
75-
} catch (error, stackTrace) {
76-
replyTo.send({
77-
'type': 'error',
78-
'error': RemoteException.serialize(error, stackTrace)
79-
});
80-
}
81-
}
82-
8349
// TODO(nweiz): Move this into the analyzer once it starts using SourceSpan
8450
// (issue 22977).
8551
/// Takes a span whose source is the value of a string that has been parsed from

lib/src/util/isolate_wrapper.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class IsolateWrapper {
4242
String toString() => _inner.toString();
4343

4444
void kill() {
45+
_inner.kill();
4546
_onExit();
4647
}
4748
}

0 commit comments

Comments
 (0)