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. RSSI values

Hi,

I trying to make a wifi meter and to get wifi signal strength I'm using the
following code:

WifiManager wifi = (WifiManager)
context.getSystemService(Context.WIFI_SERVICE);
int rssi = wifi.getConnectionInfo().getRssi();

I get values between -40 and -90 when connection is established and -248
when it's not and I'm using a Samsung Galaxy S for testing.

Is -40 and -90 the max and min values for RSSI or will it change in
different terminals? Is -248 also a constant? Are they available on the API?

Thanks,
Pedro Duque

-- 

2. marketbilling project closed?

Hi all,

why the download and source code is not available on page
http://code.google.com/p/marketbilling/ . Is there any changes on the
project?

-- 

3. Renderscript vs WebGL

4. bitmap returning null

5. [OOT] Saingan Xoom tapi tanpa Flash ?

6. Android 3.0.1 update

7. Making Views the Same Width