Cursor.moveToFirst() is taking up a lot of time

by Sublimity Mobile Software » Tue, 19 May 2009 01:32:24 GMT


Sponsored Links
 Hi,

Currently i'm working on a database system for some applications. I
need to do a lot of queries to load data from the database into the
application. After being amazed how much time it took to do these
queries on the database i found out that much time was consumed by
cursor.MoveToFirst(). This functions costs currently ~25% of all my
database action.

Does anyone know why this takes would take so long or does anyone know
a better solution to get to the first position of the cursor?


My code:

Cursor c = db.query(var1, var2, var3 .....);
c.CustomMoveToFirst();

int count = c.getCount();
for(int i = 0; i<count; i++){
        doSomethingWithCursor();
        c.moveToNext();
}


The same problem occurs when i place everything in a while loop and
use only the MoveToNext() function. So i think that the problem must
be in positioning the cursor to the first position.

My code:
Cursor c = db.query(var1, var2, var3 .....);
c.CustomMoveToFirst();

while(c.moveToNext()){
         doSomethingWithCursor();
}

Thanks,
Sublimity Mobile Software

--~--~---------~--~----~------------~-------~--~----~



Cursor.moveToFirst() is taking up a lot of time

by Sublimity Mobile Software » Wed, 20 May 2009 17:17:58 GMT


 Thank you for your reply.

You where right. The getCount() method takes indeed a lot of time. So
i filled another window by using fillWindow() like this:

Cursor c = db.query(var1, var2, var3 .....);
SQLiteCursor liteCursor = (SQLiteCursor) c;
CursorWindow cw = new CursorWindow(true);
liteCursor.fillWindow(0, cw);

And then looping the CursorWindow to get all rows and columns.

I presumed that this would make a performance boost because i thought
that by doing this i will cut back on overhead. But this actually
takes about 40% more time then simply calling getCount() that
eventually loads the data into the cursor

I already optimized the database and the queries so there is nothing
to gain here.

But would you there be another way the get values from a database in a
faster way?




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Cursor.moveToFirst() is taking up a lot of time

by Streets Of Boston » Thu, 21 May 2009 01:59:10 GMT


 In your example, it seems you don't need the getCount() or moveToFirst
() at all.

The snippet below works well without using getCount or moveToFirst().
[code]
Cursor c = db.query(var1, var2, var3 .....);
while (c.moveToNext()) {
   // do something with cursor c
   ...
}
[/code]

On May 18, 10:47am, Sublimity Mobile Software


--~--~---------~--~----~------------~-------~--~----~



Cursor.moveToFirst() is taking up a lot of time

by Streets Of Boston » Thu, 21 May 2009 02:27:29 GMT


 really...? That's surprising.
I thought the moveToNext just fetches the rows lazily, fetches them
when necessary.





--~--~---------~--~----~------------~-------~--~----~



Cursor.moveToFirst() is taking up a lot of time

by Sublimity Mobile Software » Thu, 21 May 2009 05:50:28 GMT


 y current database layer is used to convert query results into bean
objects. I did a test and the results where:

Total time loading queries = 15273ms
Queries executed = 561
Executing All Queries = 3781 ( ~25% of the total time )
GetCount() method uses = 7291ms ( ~48% of the total time )
Loaded Objects = 1120

It uses 7291ms of the total 15273ms loading the data into the cursor
through using the getCount() method. I can not remove any columns from
the query as you suggested because i need those values in my bean
objects.

Any suggestions?


On 20 mei, 17:06, Marco Nelissen <marc...@android.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Android Library project and widget xml referes in AndroidManifest.xml

Hello,
i'm using Android Project Library (http://goo.gl/7vvxI). In Android
docs, it copys all items from android library project
AndroidManifest.xml in application AndroidManifest.xml

like in example, AndroidManifest.xml of library project
<manifest>
  ...
  <application>
    ...
    <activity android:name="GameActivity" />
    ...
  </application>
  ...
</manifest>

so, AndroidManifest.xml of application must be
<manifest>
  ...
  <application>
    ...
    <activity
android:name="com.example.android.tictactoe.library.GameActivity" />
    ...
  </application>
  ...
</manifest>

So, if in library project i've a widget declaration, like below, how i
can refer to widget xml in application AndroidManifest.xml?

In library project

<receiver
android:name="com.example.android.tictactoe.library.MedWidget"
android:label="@string/label_med_widget">
        <meta-data android:name="android.appwidget.provider"
android:resource="@xml/med_provider" />
        <intent-filter>
          <action
android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
      </receiver>

in meta-data i refer to med_provider in xml folder. Do i need to copy
med_provider.xml in xml folder of application?

thanks.

-- 

2. Hoe does EntityDelta perform RawContact aggregations?

Hi folks,

  I want to know how EntityDelta performs RawContact aggregations?

  I am trying to anlyze the thing but i struck up at EntityDelta
class.


  Can any body know about EntityDelta or core concept behind
   Contact updation/insertion from EditContactActivity?

  I have been trying to understand this for a while.
  Please push me forward.

-- 

3. Import Contacts from .vcf file in Android 2.1

4. Spica

5. (WTA) : Market Enabler + Galaxy 550

6. Isilo

7. Foto sisa Palasari (2)