开发者

Why is the DAO method so slow in ORMLite?

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 t开发者_运维问答he 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜