Problem:
———————
Using a WebView to determine the userAgent requires about 250ms on a
Nexus 5. Worse, this blocks the main thread!
At Uber, this causes startup performance problems in our Rider app.
We're going to have a meeting with John B on Thursday to discuss ways
we can address the performance problem. It would be cool if we could
engineer a solution before hand :)
Fix:
———————
Instead, lets use the “http.agent” system property when it is
available (should be available on >= 2.1).
This does not return the exact same user agent string. Instead of
returning the web browser's user agent we now get the android OS's user
agent. This is more appropriate. We aren't tracking mobile web apps. We
are tracking mobile android apps. Plus, I suspect you guys aren't using
the WebView userAgent to determine whether the user clicked a browser
add with the same userAgent, since the user's android browser's user
agent doesn't always match the WebView useragent.
Example user agent before change:
———————
Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48G)
AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0
Mobile Safari/537.36
Example user agent after change:
———————
Dalvik/2.1.0 (Linux; U; Android 5.1.1; Nexus 5 Build/LMY48G)
Testing:
———————
Executed 10 times on a Nexus 5 before and after change. Verified that
the average startup performance of the Uber Rider application improved
by over 200ms.
Problem: ——————— Using a WebView to determine the userAgent requires about 250ms on a Nexus 5. Worse, this blocks the main thread!
At Uber, this causes startup performance problems in our Rider app. We're going to have a meeting with John B on Thursday to discuss ways we can address the performance problem. It would be cool if we could engineer a solution before hand :)
Fix: ——————— Instead, lets use the “http.agent” system property when it is available (should be available on >= 2.1).
This does not return the exact same user agent string. Instead of returning the web browser's user agent we now get the android OS's user agent. This is more appropriate. We aren't tracking mobile web apps. We are tracking mobile android apps. Plus, I suspect you guys aren't using the WebView userAgent to determine whether the user clicked a browser add with the same userAgent, since the user's android browser's user agent doesn't always match the WebView useragent.
Example user agent before change: ——————— Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48G) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36
Example user agent after change: ——————— Dalvik/2.1.0 (Linux; U; Android 5.1.1; Nexus 5 Build/LMY48G)
Testing: ——————— Executed 10 times on a Nexus 5 before and after change. Verified that the average startup performance of the Uber Rider application improved by over 200ms.