The following blog gives comparison between the speed of the various Android Async Http Clients. Can someone explain what makes retrofit so ridiculously fast?
EDIT: After going through the blog post again, the single-vs-multi thread issue might not be true. The problem is that they didn't share the gory details of their profiling/benchmarking; that single set of numbers doesn't provide much insight. They state, "we determined that retrieving data from the API (the networking) was the bottleneck" but they don't break that down much. Did they make all the Volley and Retrofit requests single-threaded? Did they try to multi-thread their AsyncTask
s so they could compare apples to apples? They don't specify.
If parsing a response into a JSONObject is slowing your app, one approach I have taken is using a JSONReader to parse the response in an event-driven manner. This may involve more code, but the benefit is that you get fine-grained control, so you can skip over things and not waste cycles parsing values that you don't care about. Depending on your application, this alone could speed things up quite a bit.
Personally, I find their assertion that Retrofit is easier to use as a more compelling reason to choose it for handling server access in my app.
From the AsyncTask
doc under "Order of Execution":
When first introduced, AsyncTasks were executed serially on a single background thread. Starting with
DONUT
, this was changed to a pool of threads allowing multiple tasks to operate in parallel. Starting withHONEYCOMB
, tasks are executed on a single thread to avoid common application errors caused by parallel execution.If you truly want parallel execution, you can invoke
executeOnExecutor(java.util.concurrent.Executor, Object[])
withTHREAD_POOL_EXECUTOR
.
This means that each request is waiting not only for the previous request to complete, but for all its JSON to be read/parsed as well.
Whereas AsyncTask
is by default single-threaded, Retrofit is not. For the test to be fair, they should have used the ThreadPoolExecutor
for the AsyncTask
s. Not pointing out this distinction borders on disingenuous. I'd be very surprised that they were not aware of the single-threaded nature of AsyncTask
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With