为什么ORMLite中的DAO方法这么慢?
我有一个看起来像这样的方法,
public Dao<ModelStore, Integer> getDaoStore() throws SQLException {
return BaseDaoImpl.createDao(getConnectionSource(), ModelStore.class);
}
当我调用 getDaoStore 时, 这是一个相当漫长的过程。在我的日志中,我可以看到 GC 在每次调用后都会运行,所以我猜这个调用发生了很多事情。
有没有办法加快这个速度?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对 Android 领域的深入研究表明,由于
Method.equals()
方法的存在,Android 下的注释非常缓慢且极其 GC 密集型。我们在 4.26 版本中添加了表配置文件,绕过了这个问题并使 ORMLite 启动速度更快。请参阅此问题和邮件列表上的此帖子。我们不断提高注释速度。另请参阅:ORMLite 在 Android 上性能不佳?
DAO 创建是一个相对昂贵的过程。 ORMLite 创建类和类中字段的数据表示,并构建许多其他实用程序类来帮助实现各种 DAO 功能。您应该确保每次调用时调用
createDao
方法一次。我认为这是在 Android @Pzanno 下?在 4.16 中,我们添加了一个
DaoManager
,其作用是缓存 Dao 类,这在 4.20 版本中得到了改进。然后您应该始终使用它来创建您的 Daos。建议使用类似以下代码的内容:希望这会有所帮助。 ORMLite 的内存审计也可能是有序的。我已经有一段时间没有查看它的消耗了。
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: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.