Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Unified Diff: runtime/bin/builtin.dart

Issue 203213002: Make http-imports faster to load, by hinting persistent connection on request. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/builtin.dart
diff --git a/runtime/bin/builtin.dart b/runtime/bin/builtin.dart
index be17c3f919576b178b06d3748da33e5a68efeb43..ab6eb07ff1a7e249fbb0a7ab366cd00208392c63 100644
--- a/runtime/bin/builtin.dart
+++ b/runtime/bin/builtin.dart
@@ -79,16 +79,32 @@ void _makeHttpRequest(String uri) {
try {
Uri requestUri = Uri.parse(uri);
_client.getUrl(requestUri)
- .then((HttpClientRequest request) => request.close())
+ .then((HttpClientRequest request) {
+ request.persistentConnection = false;
+ return request.close();
+ })
.then((HttpClientResponse response) {
- return response
- .fold(new BytesBuilder(), (b, d) => b..add(d))
- .then((builder) {
- _requestCompleted(builder.takeBytes(), response);
- // This client is only used for a single request. Force closing
- // it now otherwise we wait around until it times out.
Ivan Posva 2014/03/18 12:13:43 This comment was crucial in understanding why the
Anders Johnsen 2014/03/18 12:22:33 No, it was crucial to why we were using `force: tr
- _client.close(force:true);
- });
+ // Only create a ByteBuilder, if multiple chunks is received.
floitsch 2014/03/18 12:26:24 are received.
Anders Johnsen 2014/03/18 12:33:24 Done.
+ var bufferOrBuilder;
+ response.listen(
+ (data) {
+ if (bufferOrBuilder == null) {
+ bufferOrBuilder = data;
+ } else {
+ if (bufferOrBuilder is! BytesBuilder) {
+ bufferOrBuilder = new BytesBuilder()
+ ..add(bufferOrBuilder);
+ }
+ bufferOrBuilder.add(data);
+ }
+ },
+ onDone: () {
+ var data = bufferOrBuilder;
+ if (data is BytesBuilder) data = data.takeBytes();
+ _requestCompleted(data, response);
+ _client.close();
+ },
+ onError: _requestFailed);
}).catchError((error) {
_requestFailed(error);
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698