Ormlite DAO Android中变得非常慢,当查询超过几千个结果 [英] Ormlite DAO in android getting really slow when querying more than few thousand results

查看:673
本文介绍了Ormlite DAO Android中变得非常慢,当查询超过几千个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与通过Ormlite DAO查询数据的时候,有几千年的结果有问题。

Have a problem with querying data via Ormlite DAO, when there are few thousand results.

code:

List<Point> pl = db.getPointsDAO().queryBuilder().where().
            eq("route_id", croute).query();

当我想取分的大名单名单,其中;点&GT; PL 当前路由 croute 我要等待像40秒,40.000分。

When I want to get a large list of points List<Point> pl for current Route croute I have to wait like 40 sec for 40.000 points.

在这里Point.class是:

where Point.class is:

@DatabaseTable(tableName = "points")
public class Point extends BaseEntity {
    @DatabaseField(generatedId = true)
    private Integer point_id;
    @DatabaseField(canBeNull = false)
    ...
    @DatabaseField(canBeNull = false)
    private Double dose;
    @DatabaseField(dataType=DataType.DATE_STRING, format="yyyy-MM-dd HH:mm:ss")
    public Date date;
    @DatabaseField(canBeNull=true,foreign=true)
    private Route route;

public Point() {
    super();
};
... ...
}

和Route.class是:

and Route.class is:

@DatabaseTable(tableName = "routes")
public class Route extends BaseEntity {

    @DatabaseField(generatedId = true)
    private Integer route_id;

    @DatabaseField(canBeNull = true)
    private String name;

    @ForeignCollectionField(eager = false)
    ForeignCollection<Point> points;

    public Route() {
        super();
    }
    ... ...
}

一些想法,我做错了吗?

Some ideas what I'm doing wrong?

谢谢, 托尼

推荐答案

夫妇的事情,试图@toni。

Couple of things to try @toni.

  1. 我会考虑将你的日期作为,而不是一个字符串,它可以节省40K字符串 DATE_LONG /日转换。
  2. @Selvin是正确的,如果有一些方法让你可以通过数据库循环,这可能会降低你的内存需求,并加快速度。请参阅<一href="http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/dao/Dao.html#iterator%28com.j256.ormlite.stmt.$p$pparedQuery%29"相对=nofollow> dao.iterator()在 ORMLite
  3. 我会使用 INT 元,以降低您的GC为每个对象,虽然我对此表示怀疑将会使多大的差别。
  4. 尝试加载在1000点,那么10000,随后20000,看看是否有送机的性能在一些点。这会告诉你,你打了对内存限制。
  5. 使用亚行logcat 工具来看看你是否能看到GC次看到,如果你只是颠簸的收集器。任何东西,你可以做些什么来降低你的内存使用量将有助于然后。寻找线路,如:
  1. I'd consider storing your Date as a DATE_LONG instead of a string which will save 40k string/date conversions.
  2. @Selvin is right that if there is some way for you can iterate through the database, this may lower your memory requirements and speed things up. See dao.iterator() in ORMLite.
  3. I'd use int and double primitives to lower your GC for each of your objects although I doubt it will make much of a difference.
  4. Try loading in 1000 points, then 10000, then 20000 to see if there is a drop off in performance at some point. That will tell you that you are hitting up against memory limits.
  5. Use the adb logcat utility to see if you can see the GC times to see if you are just thrashing the collector. Anything that you can do to lower your memory usage will help then. Look for lines like:
GC_EXPLICIT freed 4140 objects / 216560 bytes in 114ms

  • 虽然我怀疑这是问题,你能会丢失索引?尝试添加指数= TRUE 国外路线字段。
  • Although I doubt it is the issue, could you be missing an index? Try adding a index = true on the foreign route field.
  • 这篇关于Ormlite DAO Android中变得非常慢,当查询超过几千个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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