Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Cursor fetching performance in non UI thread
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
andrew  
View profile  
 More options Jan 5 2012, 1:27 am
From: andrew <avyabo...@gmail.com>
Date: Wed, 4 Jan 2012 22:27:09 -0800 (PST)
Local: Thurs, Jan 5 2012 1:27 am
Subject: Cursor fetching performance in non UI thread
I've got a performance problem while fetching data from a cursor in
AsyncTaskLoader. Testing in android API level 10. For example 2
classes with cursor - TestFragmentUI fetching data in UI thread and
TestFragment fetching data in none UI thread.

public class TestFragment extends Fragment implements
LoaderManager.LoaderCallbacks<Object> {
...

@Override
public void onActivityCreated(Bundle savedInstanceState) {
...
getLoaderManager().initLoader(0, null, this);
...

}

public android.support.v4.content.Loader<Object> onCreateLoader(
            int id, Bundle args) {
    return new Loader(getActivity());

}

class Loader extends AsyncTaskLoader<Object> {

    public Loader(Context context) {
        super(context);
    }
    public Object loadInBackground() {
        ...
        DataBaseHelper helper = new DataBaseHelper(getContext());
        SQLiteDatabase database = helper.getReadableDatabase();
        long start = System.currentTimeMillis();
        Cursor data = database.rawQuery(String.format(SQL_LOAD,
parametr), null);
        while (data.moveToNext()) {
            String number =
data.getString(data.getColumnIndex("number"));
        }
        data.close();
        Log.i(TAG, "load: " + (System.currentTimeMillis() - start));
        ...
    }

}
...
}

and

public class TestFragmentUI extends Fragment {
...

@Override
public void onActivityCreated(Bundle savedInstanceState) {
...
DataBaseHelper helper = new DataBaseHelper(getActivity());
SQLiteDatabase database = helper.getReadableDatabase();
...
long start = System.currentTimeMillis();
Cursor data = database.rawQuery(String.format(SQL_LOAD, parametr),
null);
while (data.moveToNext()) {
String number = data.getString(data.getColumnIndex("number"));

}

data.close();
Log.i(TAG, "load: " + (System.currentTimeMillis() - start));
...

}

...
}

In emulator TestFragment class output time that is 10 times slower
than output TestFragmentUI and visually it is very noticeable. On a
real device (I've got a DHD) 3-fold difference - still very big.

Any ideas?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christopher Tate  
View profile  
 More options Jan 5 2012, 3:28 pm
From: Christopher Tate <ct...@google.com>
Date: Thu, 5 Jan 2012 12:28:04 -0800
Local: Thurs, Jan 5 2012 3:28 pm
Subject: Re: Cursor fetching performance in non UI thread

You're running the operation in an AsyncTask, which by default runs at
background priority.  That's why it takes much longer than when you run it
at normal priority.  Try calling
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT) within your
AsyncTaskLoader implementation.  This will raise that thread's priority to
normal, so it should get more of the CPU to perform the work in question.

Obviously this will potentially affect foreground UI responsiveness while
the operation is running; you'll need to balance that against
time-to-completion.

--
christopher tate
android framework engineer


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
andrew  
View profile  
 More options Jan 6 2012, 1:42 am
From: andrew <avyabo...@gmail.com>
Date: Thu, 5 Jan 2012 22:42:45 -0800 (PST)
Local: Fri, Jan 6 2012 1:42 am
Subject: Re: Cursor fetching performance in non UI thread
Thx a lot.

On 5 янв, 15:28, Christopher Tate <ct...@google.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »