Ormlite DAO in android becomes very slow when you are querying over several thousand results

Are you having trouble querying data through the Ormlite DAO when there are several thousand results.

code:

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

      

When I want to get a large list of points List<Point> pl

for the current route croute

, I need to wait 40 seconds for 40,000 points.

where Point.class:

@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();
};
... ...
}

      

and Route.class:

@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 am doing wrong?

Thanks, Toni

+2


source to share


1 answer


A few things to try @toni.



  • I'd rather store yours Date

    as DATE_LONG

    instead of string, which will store 40k string and date conversions.
  • @Selvin is right that if there is some way you can iterate through the database it can lower memory requirements and make things faster. See dao.iterator () in ORMLite .
  • I would use the primitives int

    and double

    to omit the GC for each of your objects, although I doubt that would make a big difference.
  • Try loading 1000 points, then 10,000, then 20,000 to see if there is a performance degradation at some point. This will tell you that you are running into memory constraints.
  • Use a utility adb logcat

    to see if you can see the GC time to see if you are simply cheating on the collector. Anything you can do to lower your memory usage will help. Find lines like:
    GC_EXPLICIT freed 4140 objects / 216560 bytes in 114ms
  • While I doubt this is the problem, could you lose the index? Try adding index = true

    to the foreign field route

    .
+2


source







All Articles