Why is the DAO method so slow in ORMLite?

I have a method that looks like

public Dao<ModelStore, Integer> getDaoStore() throws SQLException { return BaseDaoImpl.createDao(getConnectionSource(), ModelStore.class); } 

when I call getDaoStore , this is a rather lengthy process. In my log, I see that the GC starts after each call to this, so I guess there is a lot going on with this call.

Is there any way to speed this up?

+4
source share
1 answer

An in-depth study of Android-land showed that due to the crude Method.equals() method, annotations for Android are very slow and extremely intense GCs. We added table configuration files in version 4.26, which circumvented this and launched ORMLite much faster. See this question and this thread on the mailing list.

We continue to improve annotation speeds. See Also: Slow ORMLite Performance on Android?


Creating a DAO is a relatively expensive process. ORMLite creates a presentation of the data of both the class and the fields in the class and creates a number of other utility classes that help with the various DAO functionality. You must make sure that you call the createDao method once per call. I assume this is under Android @Pzanno?

In 4.16, we added DaoManager , whose task is to cache Dao classes, and this has been improved in version 4.20. You should always use it to create your Daos. Something like the following code is recommended:

 private Dao<ModelStore, Integer> modelStoreDao = null; ... public Dao<ModelStore, Integer> getDaoStore() throws SQLException { if (modelStoreDao == null) { modelStoreDao = DaoManager.createDao(getConnectionSource(), ModelStore.class); } return modelStoreDao; } 

Hope this helps. An audit of ORMLite memory is probably also in order. It has been a while since I looked at this consumption.

+8
source

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


All Articles