领域惰性查询-它们比OrmLite快吗? [英] Realm lazy queries - are they faster than OrmLite?

查看:93
本文介绍了领域惰性查询-它们比OrmLite快吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近阅读了Realm数据库的内部文档,他们所有的查询都是惰性的,我不确定,如果我正确理解了这可能导致的含义.

I have recently read inside documentation for Realm database that all of their queries are lazy and I am not sure, if I understand correctly the implications which this may cause.

让我解释一下我的理解,如果我错了,请随时纠正我.我看到的方式是,每当执行这样的命令mRealm.where(Customer.class).equalTo(Customer.ID, "someId").findFirst();时,我都不会获得具有所有已填充数据的Java对象,该对象包含在该客户的db中.取而代之的是,每当我尝试访问此访存"对象的某些字段时,都会进行查询.因此,我想知道是否比OrmLite更快,是否要访问给定类的所有字段?

Let me explain how I understand it and please feel free to correct me if I'm wrong. The way I see it is that, whenever I am making such command mRealm.where(Customer.class).equalTo(Customer.ID, "someId").findFirst(); I do not get Java object with all filled data, that is contained in db for this customer. Instead queries are made whenever I try to access some fields of this "fetched" object. Therefore I am wondering, if that is faster than OrmLite, if I want to access all of the fields of given class?

与此相关的另一个问题.对要在ListViewRecyclerView中显示的项目使用Realm db是个好主意吗?如果在滚动列表期间不断进行查询,这是否会对性能产生严重影响?

Another question related to it. Is it good idea to use Realm db for items which would be displayed in ListView or RecyclerView? If queries are constantly made during scrolling of the list, wouldn't it have serious impact on the performance?

如果有人可以向我详细解释这一点,我将非常高兴.

I would be really glad, if someone could explain this to me in more detail.

推荐答案

RealmResults正在将视图自动更新为基础数据.您可以将它们视为类型安全的游标,并且它们具有一些相同的折衷,但是与Cursors不同,我们不会将数据复制到CursorWindow中,因此没有分页效果.您可以访问整个对象图,而不必担心达到CursorWindow限制.

RealmResults, which are created by our queries, are auto-updating views into the underlying data. You can think of them as type-safe cursors and they have some of the same trade-offs, but unlike Cursors we don't copy data into a CursorWindow so there is no pagination effect. You can access the entire object graph without being worried about reaching a CursorWindow limit.

大多数ORM将所有数据复制到Java堆内存中.无论是在时间上还是在内存方面,这都可能是一个非常昂贵的操作,而且您可能甚至不需要很多额外的数据.这样做的好处是您只需执行一次,然后访问数据确实非常快.

Most ORM's copy all data into Java heap memory. This can be a potentially very costly operation both time- and memory-wise + you might have a lot of additional data you don't even need. The upside to this is that you do it once, then it is really fast to access the data.

领域仅加载您实际需要的数据.这也包括单个字段.因此,如果您有一个ListView显示10个项目中的1个字段,我们将仅像CursorAdapter一样加载这10个字段.它必须从本机内存中加载数据,尽管这比从Java堆中读取数据要昂贵.

Realm on the other hand, only load the data you actually need. This includes individual fields as well. So if you have a ListView showing 1 field from 10 items we will only load those 10 fields just like an CursorAdapter. It has to load that data from native memory though which is more expensive than reading it from the Java heap.

所以回答您的问题.是的,Realm与ListView完美配合.

So to answer you question. Yes, Realm works perfectly fine with ListView.

这篇关于领域惰性查询-它们比OrmLite快吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆