You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I demo'd my app to the Serverpod team, numerous times queries took 1 or more seconds (the worst response time was about 8 seconds). This is for only 50 items in the database.
I have looked into this more closely, and the problem is definitely not happening on the server (total endpoint runtime is consistently low). The problem happens at this line, in serverpod_client_io.dart:
var response =await request.close().timeout(connectionTimeout);
I have absolutely no idea why closing a request would take this long, but profiling in Dart is utterly useless and broken (I tried), and the http library is nearly impossible to properly debug because it was written back before async/await (even before null-safety and generics...).
I have had other bad experiences with http before, and I have seen numerous reports online of other people running into problems with http. The Dart team don't seem interested in rewriting it or even updating it to modern Dart.
I filed a bug about this here, but I don't anticipate seeing any action on this:
After all the work of #1928, the problem is not fixed (Dio.post shows the same erratic timing behavior, and I assume Dio is not using HttpClient at the core).
(In spite of this, it's still probably a good idea to use dio rather than http, since the http code is a mess...)
I tried debugging this on the server too, at the point where the requests came in to HttpServer, but the erratic delay problem is not there either.
It looks like the delay issue is in the Android emulator. If I run with the same debug build on a physical device, against the same server instance, the response times are no longer erratic.
I'll close this, but I will leave the PR open, since the dio port is probably a worthwhile improvement.
Using Dart's http package allows the app developers to easily swap the implementation depending on the platform, e.g., cupertino_http, cronet_http, rhttp, dio.
Activity
lukehutch commentedon Feb 17, 2024
After all the work of #1928, the problem is not fixed (
Dio.postshows the same erratic timing behavior, and I assumeDiois not usingHttpClientat the core).(In spite of this, it's still probably a good idea to use
diorather thanhttp, since thehttpcode is a mess...)lukehutch commentedon Feb 17, 2024
I tried debugging this on the server too, at the point where the requests came in to
HttpServer, but the erratic delay problem is not there either.It looks like the delay issue is in the Android emulator. If I run with the same debug build on a physical device, against the same server instance, the response times are no longer erratic.
I'll close this, but I will leave the PR open, since the dio port is probably a worthwhile improvement.
lukehutch commentedon Mar 30, 2024
For the record, here is the reason why HTTP requests can be very slow in Flutter:
dart-lang/sdk#50868
EchoEllet commentedon May 27, 2026
I wouldn't hardcode any implementation. Instead, it probably should be abstracted.
Both
dioandhttpdepend ondart:ioso moving todiousually does not fix the core issue.Alternative: rhttp
Using Dart's
httppackage allows the app developers to easily swap the implementation depending on the platform, e.g., cupertino_http, cronet_http,rhttp,dio.https://pub.dev/packages/rhttp#compatibility-layer
httppackage's API design, while it comes with fewer features, is at least slightly more polished thandio.Tip
Edit: It seems this was already addressed in #5134