1. 首页
  2. 考试认证
  3. 其它
  4. FlatBuffer性能优化提高offset()方法效率

FlatBuffer性能优化提高offset()方法效率

上传者: 2024-12-20 22:00:20上传 ZIP文件 2.75KB 热度 5次

FlatBuffer使用优化一。工具语言Python。

一、原因:__offset()方法不够快。为了获得一个变量,可能需要多次调用__offset()方法

三、影响:添加了用于flatbuffer文件的设置方法,添加成员变量缓存(包括数组变量)。

四、经验值起源:


public int top() {

    int o = __offset(4);

    return o != 0 ? bb.getInt(o + bb_pos) : 0;

}

转换成:


public boolean has_top_cache = false;

public int top_cache;

public int top() {

    if (has_top_cache) {

        return top_cache;

    }

    int o = __offset(4);

    top_cache = o != 0 ? bb.getInt(o + bb_pos) : 0;

    has_top_cache = true;

    return top_cache;

}

下载地址
用户评论