Retrofit Slower response time in real android devices when compared to emulator and web

10,403

Solution 1

When I run my app in the debugger, it was unusable slow. When I run it outside the debugger, it performs better.

So conclusion is that Mentioned problem was not related with tool and libraries that I was using . Issue was with USB debugging .

Since I was new To android development I was not aware of the performance of APP in USB debugging mode .

Solution 2

In retrofit, it does following work:

  1. Build up the Retrofit class.
  2. Impl the Interface with DynamicProxy
  3. Parse and create the Http request accourding to the annotations.
  4. Send and receive HTTP(socket) IOs with OkHttp in ThreadPool(In Android, Network can't be done on main thread).
  5. Deserialize your Http body with some lib (eg. gson).
  6. update UI in callback.

In your phone, I think 1,2,3 won't be necessary, they can even be done on main thread or cached. In my device (Qcom615, 2Gram), it will take less than one ms.

So you need to debug with your network.

fix problem one by one:

  1. Is your server use HTTPS or no-cacahe or no-gzip? Logging your data and tell your server's partner, they can give you some advice.
  2. try faster lib for converters.
  3. improve your view's code(eg. void redraw/relayout, void a long-time job in main thread).

Solution 3

Slow response has nothing to do you with your phone it may be due to several reasons. Some noticeable reason i know are mentioned below.

1) Internet connection on your device may be slower comparatively to your emulator which uses network connection of your machine (wifi or lan connected).

2) There are multiple applications using internet on your device in background. Check application running background process and stop them.

To ensure test your internet speed on your device using speedtest.net. Hope it helps you .

Share:
10,403
Rahul
Author by

Rahul

In a state of absolute willingness, the whole cosmos becomes yours

Updated on July 25, 2022

Comments

  • Rahul
    Rahul almost 2 years

    I am making a restful API call from Android device to populate a list view .

    I have used swagger codegen to generate my retrofit client .

    Dagger 2 for dependency injection

    Device : Asus Zenfone 5

    I have tried to make call from postman, web and also in emulator (genymotion) it is much faster compared to a real device.

    And interesting thing is that every time when I restart my phone for two to three request the response time is normal and after that getting slower.

    I read some blog regarding gzip compression in okHTTP and try to implement that but no effect.

    It would be really helpful if someone can help me to figure out the issue.

    • Karan Maru
      Karan Maru about 8 years
      please provide your web request and response code
    • Eugen Martynov
      Eugen Martynov about 8 years
      I think it is natural that your phone connection is slower. I would not bother with this too much and I will make UI code robust against this problem
    • Rahul
      Rahul about 8 years
      My network speed is 8Mbps so I think it is not the problem with network
    • William Cheng
      William Cheng about 8 years
      We recently added Android Volley library support to the android template. Please pull the latest master of swagger-codegen to generate Android API client with the volley to see if other HTTP libraries will perform better in your scenario.
    • Rahul
      Rahul about 8 years
      Ok I will try it and let you know
    • Rahul
      Rahul about 8 years
      @wing328 facing same issue with Volley too
    • William Cheng
      William Cheng about 8 years
      Maybe cURL on android can help trouble shoot the issue to see if the issue is device-specified.
    • Rahul
      Rahul about 8 years
      @wing328 when I clean ram and junk files the response time is getting faster . I have also noticed that if I connect my phone for USB debugging it is getting more and more slower and if I remove my data cable . Response time is normal . Is that any problem with cache
    • William Cheng
      William Cheng about 8 years
      @Rahul I'm not surprised if the response is slow given that USB debugging is on.
    • Rahul
      Rahul about 8 years
      @wing328 Is this expected ?
  • Rahul
    Rahul about 8 years
    as mentioned in the above comment My network speed is 8Mbps so I think it is not the problem with network . In my condition for a response of 50kb it is taking more than a minute . So i don't this is due to network .
  • UMESH0492
    UMESH0492 about 8 years
    @Rahul if it's taking more than a min for 50kb and your network speed is 8Mbps, then i guess there is something wrong with the implementation you have done. Also there must be a timeout implementation, if request is taking more than 25 sec say.
  • Rahul
    Rahul about 8 years
    @UMESH0492 Please see my answer . Thanks a lot for your help and support
  • Rahul
    Rahul about 8 years
    Thanks for your time and effort . Please see my answer Issue was not with the tools and libraries used .
  • dasar
    dasar about 8 years
    App working slower when it's optimized for debug and especially when you debugging it in IDE. That's not an issue, overhead of debugging - that's why there is release/debug builds.