Why is the DAO method so slow in ORMLite?

随声附和 提交于 2019-12-04 13:18:26

问题


I have a method that looks like this

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

when i call getDaoStore it is quite a lengthy process. In my log's i can see that the GC runs after every call to this, so I'm guessing there's a lot going on with this call.

Is there a way to speed this up?


回答1:


A deep examination of Android-land has revealed that because of a gross Method.equals() method, annotations under Android are very slow and extremely GC intensive. We added table configuration files in version 4.26 that bypass this and make ORMLite start much, much faster. See this question and this thread on the mailing list.

We continue to improve annotation speeds. See also: ORMLite poor performance on Android?


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

In 4.16 we added a DaoManager whose job it is to cache the Dao classes and this was improved in version 4.20. You should then 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. A memory audit of ORMLite is probably also in order. It's been a while since I looked at it's consumption.



来源:https://stackoverflow.com/questions/5423899/why-is-the-dao-method-so-slow-in-ormlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!