0
votes

Say I have an endpoint (I'll call it SERVICE) that returns a simple JSON string. In Dart, the following code is consistently very fast; it runs in less than a second:

main() => HttpRequest.getString(SERVICE).then(print);

However, this code is consistently about 10 times slower:

main() async => print(await HttpRequest.getString(SERVICE));

Why is this so much slower? Am I doing something wrong here?

If it matters, I'm testing this in Dartium using the simple "bare bones web application" example in WebStorm, and I get the same behavior in Chrome.

Is it the same result across multiple runs ? If it is you should file an issue. - Alexandre Ardhuin
how exactly do you measure running times? - Mike
Hmm... it must be an anomaly. I'm trying again now, and I can't seem to reproduce it. Now, both versions are very slow :/ - Brandon
Do you control the SERVICE? If so, print out the timing from the SERVICE side, to eliminate possibility it's the server. I can't reproduce the problem, and we've never heard of this issue before. Try this with a known fast web site, like google.com and see if await is still an issue for you - Seth Ladd
Hi Seth, it's definitely not the server -- as it turns out, the problem seems to be with Chrome/Dartium rather than Dart. I'm using window.performance.now() to measure the time; IE/FireFox are both taking roughly 150 ms, but in Chrome and Dartium it's taking around 20,000 ms. Do you know if this could have anything to do with the fact that I'm making a cross-site call? The Dart code is running via pub serve (localhost:63342) and the backend is a simple Flask app (localhost:5000). If nothing comes to mind I'll try to get a smaller repro and file a bug. - Brandon