You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by "Braden Shepherdson (JIRA)" <ji...@apache.org> on 2012/08/15 23:11:38 UTC

[jira] [Created] (CB-1250) Speed up fetching of contacts on Android

Braden Shepherdson created CB-1250:
--------------------------------------

             Summary: Speed up fetching of contacts on Android
                 Key: CB-1250
                 URL: https://issues.apache.org/jira/browse/CB-1250
             Project: Apache Cordova
          Issue Type: Improvement
          Components: Android
            Reporter: Braden Shepherdson
            Assignee: Joe Bowser
            Priority: Minor
             Fix For: 2.1.0


Fetching all contacts on Android takes a long time when the user has many contacts (I have ~1450 and it takes 20-30 seconds). The Contacts app can load in less than a second, so what are we doing that's causing it to slow down?

As an alternative or additional enhancement, add "limit" and "offset" functionality to the ContactFindOptions, to retrieve smaller subsets of the contacts more quickly.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-1250) Speed up fetching of contacts on Android

Posted by "Braden Shepherdson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-1250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13436343#comment-13436343 ] 

Braden Shepherdson commented on CB-1250:
----------------------------------------

I'm done for the day, but I'll continue investigating this tomorrow. That sample app has given me confidence that there's something about the current approach that makes it slow; we can make it much faster.
                
> Speed up fetching of contacts on Android
> ----------------------------------------
>
>                 Key: CB-1250
>                 URL: https://issues.apache.org/jira/browse/CB-1250
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Android
>            Reporter: Braden Shepherdson
>            Assignee: Joe Bowser
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> Fetching all contacts on Android takes a long time when the user has many contacts (I have ~1450 and it takes 20-30 seconds). The Contacts app can load in less than a second, so what are we doing that's causing it to slow down?
> As an alternative or additional enhancement, add "limit" and "offset" functionality to the ContactFindOptions, to retrieve smaller subsets of the contacts more quickly.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-1250) Speed up fetching of contacts on Android

Posted by "Simon MacDonald (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-1250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13435579#comment-13435579 ] 

Simon MacDonald commented on CB-1250:
-------------------------------------

It's not as easy as you think. When you look at the way contacts are stored in the DB it is fun, fun, fun to get at all their data. Part of the reason why this is slower is we have to build up a huge array of JSON objects. Feel free to poke around and find a way to make it faster. I'll help answer any questions.
                
> Speed up fetching of contacts on Android
> ----------------------------------------
>
>                 Key: CB-1250
>                 URL: https://issues.apache.org/jira/browse/CB-1250
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Android
>            Reporter: Braden Shepherdson
>            Assignee: Joe Bowser
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> Fetching all contacts on Android takes a long time when the user has many contacts (I have ~1450 and it takes 20-30 seconds). The Contacts app can load in less than a second, so what are we doing that's causing it to slow down?
> As an alternative or additional enhancement, add "limit" and "offset" functionality to the ContactFindOptions, to retrieve smaller subsets of the contacts more quickly.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (CB-1250) Speed up fetching of contacts on Android

Posted by "Braden Shepherdson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CB-1250?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Braden Shepherdson resolved CB-1250.
------------------------------------

    Resolution: Fixed

I submitted a change, which has been committed, to select only the columns we need. This has resulted, in my testing with 1400+ contacts, in a 4x speedup (from just over 40 seconds to just under 10 seconds).

It could still be better, but now around half the time is spent constructing JSON objects and shipping them through the bridge, which I can't see any way to streamline. The efforts to build a faster Android bridge should help this and any other operations with a large payload.
                
> Speed up fetching of contacts on Android
> ----------------------------------------
>
>                 Key: CB-1250
>                 URL: https://issues.apache.org/jira/browse/CB-1250
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Android
>            Reporter: Braden Shepherdson
>            Assignee: Braden Shepherdson
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> Fetching all contacts on Android takes a long time when the user has many contacts (I have ~1450 and it takes 20-30 seconds). The Contacts app can load in less than a second, so what are we doing that's causing it to slow down?
> As an alternative or additional enhancement, add "limit" and "offset" functionality to the ContactFindOptions, to retrieve smaller subsets of the contacts more quickly.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-1250) Speed up fetching of contacts on Android

Posted by "Simon MacDonald (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-1250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13436206#comment-13436206 ] 

Simon MacDonald commented on CB-1250:
-------------------------------------

Grabbing a pre-sized ArrayList using c.getCount() will greatly over-estimate the amount of contacts. Each row in the result set represents a name, phone number, email address, address, etc. So a single contact may take up 20 rows in the DB.

Lemme know what you find in the Android src code.
                
> Speed up fetching of contacts on Android
> ----------------------------------------
>
>                 Key: CB-1250
>                 URL: https://issues.apache.org/jira/browse/CB-1250
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Android
>            Reporter: Braden Shepherdson
>            Assignee: Joe Bowser
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> Fetching all contacts on Android takes a long time when the user has many contacts (I have ~1450 and it takes 20-30 seconds). The Contacts app can load in less than a second, so what are we doing that's causing it to slow down?
> As an alternative or additional enhancement, add "limit" and "offset" functionality to the ContactFindOptions, to retrieve smaller subsets of the contacts more quickly.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (CB-1250) Speed up fetching of contacts on Android

Posted by "Joe Bowser (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CB-1250?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Joe Bowser updated CB-1250:
---------------------------

    Assignee: Braden Shepherdson  (was: Joe Bowser)
    
> Speed up fetching of contacts on Android
> ----------------------------------------
>
>                 Key: CB-1250
>                 URL: https://issues.apache.org/jira/browse/CB-1250
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Android
>            Reporter: Braden Shepherdson
>            Assignee: Braden Shepherdson
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> Fetching all contacts on Android takes a long time when the user has many contacts (I have ~1450 and it takes 20-30 seconds). The Contacts app can load in less than a second, so what are we doing that's causing it to slow down?
> As an alternative or additional enhancement, add "limit" and "offset" functionality to the ContactFindOptions, to retrieve smaller subsets of the contacts more quickly.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-1250) Speed up fetching of contacts on Android

Posted by "Braden Shepherdson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-1250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13436199#comment-13436199 ] 

Braden Shepherdson commented on CB-1250:
----------------------------------------

I'm currently pulling the Android source code. I'll take a look at how the stock ICS and/or JB Contacts app retrieves the user's contacts so quickly. Maybe we're doing something wrong, maybe there's a new, faster API. I can hope.

I'm not sure how much of the time taken is spent allocating and GCing the big set of JSON* objects. I wonder if the big JSONArray of all the contacts is being forced to copy itself multiple times? We could try a pre-sized (with c.getCount()) ArrayList<JSONObject> and use the JSONArray constructor that takes a collection, but it's not clear whether that would help.

I'll see how the Android team did this before any further experimentation.
                
> Speed up fetching of contacts on Android
> ----------------------------------------
>
>                 Key: CB-1250
>                 URL: https://issues.apache.org/jira/browse/CB-1250
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Android
>            Reporter: Braden Shepherdson
>            Assignee: Joe Bowser
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> Fetching all contacts on Android takes a long time when the user has many contacts (I have ~1450 and it takes 20-30 seconds). The Contacts app can load in less than a second, so what are we doing that's causing it to slow down?
> As an alternative or additional enhancement, add "limit" and "offset" functionality to the ContactFindOptions, to retrieve smaller subsets of the contacts more quickly.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-1250) Speed up fetching of contacts on Android

Posted by "Braden Shepherdson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-1250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13436186#comment-13436186 ] 

Braden Shepherdson commented on CB-1250:
----------------------------------------

The limit/offset approach does "work" on Android, and the round-trip time is roughly linear in the number of contacts requested. However there are sometimes multiple rows with the same ID so we combine them into one contact to be returned. That approach breaks with limit/offset, making it impractical.

I also experimented with caching the getColumnIndex values instead of calling it repeatedly. It looks like the profiler is not counting time spent waiting for responses from the data store, because the time consumed by these Java calls does not come close to matching the wallclock time. Even though getColumnIndex calls were supposedly 40% of the work, caching the values and reducing from 1442*n calls to n calls made no discernible impact to the wallclock time to fetch all the contacts.

It looks like neither approach will really improve matters, and I will have to be content that this call is async.
                
> Speed up fetching of contacts on Android
> ----------------------------------------
>
>                 Key: CB-1250
>                 URL: https://issues.apache.org/jira/browse/CB-1250
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Android
>            Reporter: Braden Shepherdson
>            Assignee: Joe Bowser
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> Fetching all contacts on Android takes a long time when the user has many contacts (I have ~1450 and it takes 20-30 seconds). The Contacts app can load in less than a second, so what are we doing that's causing it to slow down?
> As an alternative or additional enhancement, add "limit" and "offset" functionality to the ContactFindOptions, to retrieve smaller subsets of the contacts more quickly.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-1250) Speed up fetching of contacts on Android

Posted by "Braden Shepherdson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-1250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13436143#comment-13436143 ] 

Braden Shepherdson commented on CB-1250:
----------------------------------------

>From my measurements on my Galaxy Nexus with Jelly Bean and 1442 contacts, I have the following timings (repeated with small variance over 3 runs):

1. Javascript -> ContactAccessor's search: more or less instant.
2. Constructing the query data, WHERE clause, etc.: 1.25s
3. query() to retrieve the cursor: 2.5s
4. Populating the list of contacts: 35.8s
5. Java -> Javascript with the result: 3.5s

Many GC calls are done during steps 4 and 5, but the total time taken for GC is around 200ms.

Using Debug.startMethodTracing() and Traceview, 40% of the time is being spent in getColumnIndex, 16% in moveToNext(). The rest is too scattered to really target. However, neither of those functions are ones we can really avoid calling. Calls to getColumnIndex are not being made unnecessarily so far as I can see. I just have a lot of contacts.

There doesn't appear to be any low-hanging fruit here to speed things up.

The limit/offset approach looks like it will work, since those SQL(ish) clauses can be appended to the sortOrder field. I'm looking into that further.
                
> Speed up fetching of contacts on Android
> ----------------------------------------
>
>                 Key: CB-1250
>                 URL: https://issues.apache.org/jira/browse/CB-1250
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Android
>            Reporter: Braden Shepherdson
>            Assignee: Joe Bowser
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> Fetching all contacts on Android takes a long time when the user has many contacts (I have ~1450 and it takes 20-30 seconds). The Contacts app can load in less than a second, so what are we doing that's causing it to slow down?
> As an alternative or additional enhancement, add "limit" and "offset" functionality to the ContactFindOptions, to retrieve smaller subsets of the contacts more quickly.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-1250) Speed up fetching of contacts on Android

Posted by "Braden Shepherdson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-1250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13436322#comment-13436322 ] 

Braden Shepherdson commented on CB-1250:
----------------------------------------

So, good news and bad news.

First, the stock Android contacts app is surprisingly complex, 75k lines. I can't figure out where it actually loads the contacts' names for the main browsable list.

Second, removing all JSON* creation and everything else from the loop over the contacts, and replacing it with just add()ing the displayNames to an ArrayList<String> only changes the runtime a bit. There's something else going on.

Much simpler than the real contacts app, one of the sample apps shipped with the SDK can load a list of my contacts' names quickly, so I'll be examining that to see why it works fast. It uses SimpleCursorAdapter, which I've never encountered before. I've been digging through that code trying to figure out how this tangle of ViewBinders and *Adapters eventually results in a ListView full of TextViews with the contacts' names. Hopefully once I figure it out we can duplicate that approach or see what's making our approach slow. We know now that it's not the contents of the loop, but something more general in this technique.
                
> Speed up fetching of contacts on Android
> ----------------------------------------
>
>                 Key: CB-1250
>                 URL: https://issues.apache.org/jira/browse/CB-1250
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Android
>            Reporter: Braden Shepherdson
>            Assignee: Joe Bowser
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> Fetching all contacts on Android takes a long time when the user has many contacts (I have ~1450 and it takes 20-30 seconds). The Contacts app can load in less than a second, so what are we doing that's causing it to slow down?
> As an alternative or additional enhancement, add "limit" and "offset" functionality to the ContactFindOptions, to retrieve smaller subsets of the contacts more quickly.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CB-1250) Speed up fetching of contacts on Android

Posted by "Simon MacDonald (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CB-1250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13436191#comment-13436191 ] 

Simon MacDonald commented on CB-1250:
-------------------------------------

@Branden,

Dang, it looks like you are running into the same headaches that I found when I wrote this API last year. I wish there was more we could do to speed this up. I wonder if we can do something to reduce the number of GC's. Do you think building up our own String rather than creating a bunch of JSONObject's and JSONArray's would help?
                
> Speed up fetching of contacts on Android
> ----------------------------------------
>
>                 Key: CB-1250
>                 URL: https://issues.apache.org/jira/browse/CB-1250
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Android
>            Reporter: Braden Shepherdson
>            Assignee: Joe Bowser
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> Fetching all contacts on Android takes a long time when the user has many contacts (I have ~1450 and it takes 20-30 seconds). The Contacts app can load in less than a second, so what are we doing that's causing it to slow down?
> As an alternative or additional enhancement, add "limit" and "offset" functionality to the ContactFindOptions, to retrieve smaller subsets of the contacts more quickly.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira