Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 647
Pzanno Avatar asked Feb 24 '23 17:02

Pzanno


1 Answers

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.

like image 166
Gray Avatar answered Feb 27 '23 06:02

Gray