Creating Pojo class from Sqlite cursor takes too much time

My request takes <3 milliseconds to execute. But the problem is that I create objects of the pojo class from the cursor obtained from the execution of the request. To create and set values โ€‹โ€‹of objects in fields, it takes too much time more than 140 milliseconds. The Pojo class has about 36 fields. Any suggestion to solve this problem.?

thanks

+5
source share
2 answers

How many objects do you create? 36 fields are not visible too much.

If you have many objects, you can create them in a separate stream. Of course, you will need to set up some kind of callback to find out when everything is loaded.

0
source

I know that the c.getColumnIndex() method takes longer. The best way I know to speed this up is this:

 Cursor c = null; try { c = db.query(......); if(c != null) { int channelIdIndex = c.getColumnIndex(OptimizedMessage.CHANNEL_ID); int clientIdIndex = c.getColumnIndex(OptimizedMessage.CLIENT_ID); while (c.moveToNext()) { OptimizedMessage newMessage = new OptimizedMessage(); newMessage.setChannelId(c.getLong(channelIdIndex)); newMessage.setClientId(c.getLong(clientIdIndex)); messages.add(newMessage); } } } finally { if (c != null) { c.close(); } } 

You can see that the c.getColumnIndex() method is used only once.

0
source

Source: https://habr.com/ru/post/1247497/


All Articles