我怎样才能提高加载的对象与ORMLite在Android这个方法? [英] How can I improve this method of loading objects with ORMLite on Android?

查看:119
本文介绍了我怎样才能提高加载的对象与ORMLite在Android这个方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android上使用ormlite 4.35装载一组对象(与国外对象)。据16日和19秒之间发生(在模拟器),在下面的 getAllCragsWithLocation()法的时机。

I am loading a set of objects (and their foreign objects) using ormlite 4.35 on Android. It takes (in the emulator) between 16 and 19 seconds for the timing in the getAllCragsWithLocation() method below.

有590峭壁在数据库和40没有一个位置

There are 590 Crags in the database and 40 don't have a location.

有几行未登录的状态,如

There are several lines logged such as

03-19 11:03:54.441: I/dalvikvm(1156): Jit: resizing JitTable from 1024 to 2048
03-19 11:03:55.531: D/dalvikvm(1156): GC_CONCURRENT freed 544K, 37% free 5174K/8199K, external 731K/1109K, paused 6ms+11ms

我应该加载的对象另一种方式?运行在sqlite3的命令行查询各地1/100秒的需要...

Should I be loading the objects another way? Running the query at the sqlite3 command line takes around 100th of a second...

public List<Crag> getAllCragsWithLocation() {
        Log.i(TAG,"beginning db calls");
        long startQuery = System.currentTimeMillis();
        QueryBuilder<Crag,Integer> queryBuilder = helper.getCragDao().queryBuilder();
        List<Crag> results = new ArrayList<Crag>();
        try {
            queryBuilder.where().isNotNull("location_id");
            Log.i(TAG,queryBuilder.prepareStatementString());
            PreparedQuery<Crag> preparedQuery = queryBuilder.prepare();
            results = helper.getCragDao().query(preparedQuery);
        } catch (android.database.SQLException e) {
            Log.e(TAG,e.toString());
        } catch (SQLException e) {
            Log.e(TAG,e.toString());
        }
        Log.i(TAG,"ending query after "+((System.currentTimeMillis()-startQuery)/1000)+" seconds");
        return results;
    }

在岩对象(简体)是:

The crag object (simplified) is:

@DatabaseTable
    public class Crag {
        public Crag() {
            //ormlite requires a no-arg constructor?
            guidebooks = new ArrayList<Guidebook>();
        }

        @DatabaseField(id=true) private int id;
        @ForeignCollectionField(eager = true)
        private Collection<Guidebook> guidebooks;
        @DatabaseField(foreign=true, foreignAutoRefresh = true, index=true)
        private uk.co.bmc.rad.models.Location location;
        @DatabaseField(foreign=true,foreignAutoRefresh=true)
        private SubRegion subRegion;
    }

该异物是简单得多比班岩。出于显示的目的只有位置是必要的对象被加载形成数据库中的点,但平等的比较时,我用异物所以...

The foreign objects are much simpler classes than Crag. For the purposes of display only the location is necessary at the point the objects are loaded form the database but I use the foreign objects when comparing for equality so...

自回归 getAllCragsWithLocation()迭代到prepare为除 MapOverlay 。时序过程比第二占用较少。

The return from the getAllCragsWithLocation() is iterated over to prepare for addition to a MapOverlay. Timing that process takes less than a second.

更新:
我刚换入DB4O进行比较,并通过比较加载所有本质峭壁瞬间,所以我想我会与该走了。

UPDATE: I've just swapped in DB4O to compare and that loads all crags essentially instantly by comparison so I think I'll go with that.

已更新更新:
而不是在DB4O迅速交换我花了更多的时间比较两个。

UPDATED UPDATE: Instead of quickly swapping in DB4O I've spent more time comparing the two.

在一个JUnit 3 AndroidTestCase如果我插入一条记录到数据库中,然后查询它直接再ORMLite和DB4O都需要大约一个第二(总)插入和返回的对象。

In a JUnit 3 AndroidTestCase if I insert a single record into the database and then query for it directly then both ORMLite and DB4O take about a second (total) to insert and return the object.

如果我跑我的过程中插入590对象,则需要ORMLite约24秒,DB40大约需要40。

If I run my process to insert 590 objects then ORMLite takes around 24 seconds and DB40 takes around 40.

这立即插入如果我叫getAllCragsWithLocation(),然后getAllCrags()DB40需要7秒钟,然后0秒将返回峭壁的列表,以便我猜它有加速的第二个查询缓存后

Immediately after that insert if I call getAllCragsWithLocation() and then getAllCrags() DB40 takes 7 seconds and then 0 seconds to return a List of Crags so I'm guessing it has a cache that speeds the second query

虽然ORMLite需要约7秒两个查询。

While ORMLite takes around 7 seconds for both queries.

因此​​,实际上有它很少

So there's actually very little in it

已更新更新升级:
抓住一个变压器总理今天刚跑在1秒内装载的应用程序和峭壁相比,7仿真器。

UPDATED UPDATE UPDATED: Grabbed a Transformer Prime today and just ran the app on that and the crags loaded in 1 second as compared to the 7 on the emulator.

既然我已经成功地已经神交ormlite的查询语法;可以依靠原始的SQL和SQLite表结构更加转让我要坚持ormlite了db4o的。

Since I've managed to grok ormlite's query syntax already; can fall back on raw sql and the sqlite table structure is more transferable I'm going to stick with ormlite over db4o.

推荐答案

我真的很惊讶,它正在采取这么久。

I'm really surprised that it is taking that long.

    @ForeignCollectionField(eager = true)
    private Collection<Guidebook> guidebooks;
    @DatabaseField(foreign=true, foreignAutoRefresh = true, index=true)
    private uk.co.bmc.rad.models.Location location;
    @DatabaseField(foreign=true,foreignAutoRefresh=true)
    private SubRegion subRegion;

每个这些字段,将产生另一个数据库查询,虽然我不会期望秒,将需要时间。 ORMLite不聪明关于使用加入,以满足渴望获取远程对象。

Each of those fields will generate another database query that would take time although I would not expect seconds. ORMLite is not smart about using JOIN to satisfy eager fetched remote objects.

一件事是尝试使用表配置过程中产生的DAO实现的时候来解决Android的狗,狗慢反射的实现。请参阅该文档为:

One thing to try is to use the table-config process to work around Android's dog, dog slow reflection implementation when generating DAO implementations. See the docs for that:

http://ormlite.com/docs/table-config

如果你看着办吧,虽然我明白,如果你需要切换到其它的什么包得到工作,我会好奇。

I would be curious if you figure it out although I understand if you need to switch to some other package to get working.

这篇关于我怎样才能提高加载的对象与ORMLite在Android这个方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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