FlatBuffer性能优化提高offset()方法效率
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;
}
下载地址
用户评论