-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Delegate implementation of dart:io's networking bits... #39104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Migrating a part of That won't solve the problem because you still can't use We could, perhaps, split
and export all of them from dart:io, but encourage users to migrate to the individual libraries for "greater portability". Before doing anything rash, we might want to consider for each of these whether there is a better API that we'd want to expose, and then have |
also cc @Hixie (I'm not super sure who's driving that effort). Weren't there customers wanting to supply their own cronet implementation to back Dart networking as well? We should align since they likely have the same technical solution. |
cc @vsm @leafpetersen as there was some discussion about this at a recent planning meeting. |
I'd be supportive of this change. As for better APIs, the Flutter tool mainly uses package:file and package:platform instead of directly using those parts of dart:io due to the ease of injecting different implementations. If those APIs (and similar ones for network, processes, etc.) were shifted to As an alternative approach, which I'm not necessarily endorsing, an embedder (like the engine) could set |
@zanderso another issue with doing it in an embedder specific way is that apps still need to package in BoringSSL and the rest of the Dart network static on the C++ side, which last I checked was ~.3MB. That becomes a sticking point for some of our customers. I'm hoping that whatever solution is created would not only improve the Dart API surface but also improve options around binary size for people who want to bring their own. |
@dnfield Yeah, there are really two parts to this issue:
Since the engine build is currently taking the |
If I'm understanding Option 2 in the context of a slimmed down Flutter, that would mean something like entirely removing HttpClient/HttpServer along with the associated native bits? That has a lot of unfortunate side effects. In general, it would make it very difficult to prevent accidental breakages if a downstream dependency of the a SDK. Consider the follow case:
The above scenario is only preventable if Flutter essentially freezes the usage of dart core libraries. That would not be conducive to taking advantage of updates to dart core libraries. |
The goal would be to have some other implementation in use, e.g. NSURLConnection on uOS |
That sounds like option 1 though, the interfaces stay but the implementation changes |
I was assuming it meant backing e.g. the |
/cc @a-siva |
I'm going to work on a design doc for this. |
@mraleph , is it reasonable to track this under https://github.com/dart-lang/sdk/issues?q=is%3Aopen+is%3Aissue+label%3Avm-aot-code-size? |
/cc @mehmetf who is looking at some changes to the HttpClient, and might be interested in this. |
@zoeyfan that label is just about the size of compiled Dart code - so it does not fit this particular issue which is more about the size of the runtime system. |
There has been numerous discussions around this internally. I have asked help from vsm to help organize this work. Flutter's embedding of Dart on a given platform should match the core native characteristics of the platform. Doing this via plugins makes little sense to me. It should be directly provided by Flutter. In here, "core" means the categories that Lasse enumerated above (network, process, file). Recent examples where we had to create inferior solutions:
|
@lrhn could you point us to a document which talks about the current design guidelines and how the dart:io API can be made better. |
I don't believe there is any such document, it's just API design choices that are either internally inconsistent, or that are not following patterns that have become de-facto standard for writing Dart code. For example, the IO library has several classes which extend There is the It's not bad, just not very consistent with almost all other Dart code. |
late Client client;
if (Platform.isIOS) {
final config = URLSessionConfiguration.ephemeralSessionConfiguration()
# Do whatever configuration you want.
..allowsCellularAccess = false
..allowsConstrainedNetworkAccess = false
..allowsExpensiveNetworkAccess = false;
client = CupertinoClient.fromSessionConfiguration(config);
} else {
client = IOClient(); // Uses an HTTP client based on dart:io
}
final response = await client.get(Uri.https(
'www.googleapis.com',
'/books/v1/volumes',
{'q': 'HTTP', 'maxResults': '40', 'printType': 'books'})); I would really appreciate it if you can try Comments or bugs in the |
...or perhaps provide a new library that does so.
Context: Flutter users are concerned about the added size of including a networking stack that they may not want to use (e.g. pre-existing mobile apps may be expected to use some other networking library flutter/flutter#40220) or that may not be taking full advantage of the OS capabilities (e.g. backgrounding download tasks flutter/flutter#32161, or respecting system proxy settings flutter/flutter#20376).
This also causes some headaches with Flutter for web, since the dart:io network implementation is not very compatible with AJAX/XMLHttpRequest.
A key part of this request is to have a way to buid the Dart VM without including the network bits of dart:io, e.g. all of the socket*.cc and BoringSSL, at least in product mode (where we wouldn't need the observatory anymore).
However, it seems like it would be ideal to be able to just fully delegate the nework calls to some other library in this mode (whether in product mode or not) so that existing code using e.g.
HttpClient
would not break but could effectively delegate to some other networking library specific to a platform.It may also work just to have some new
dart:net
library or somesuch with the same API surface as the existing socket and HTTP implementation, but that delegates./cc @zanderso @xster @bkonyi @jonahwilliams who all probably have good thoughts on this.
The text was updated successfully, but these errors were encountered: