text配置表优化

项目中字符串配置表是最大的一张表,足足有一万多条记录。

我们目前的存储方式是按csv类似格式存为scriptableobject。这张表的解析基本上占用总解析时间的25%~35%,因此优化这张表非常有必要。

查看了下text表中。其中重复内容大概按25%左右。因为表是按key,value键值对存储,计算了下key占用了45%的空间,这里优化的余地非常大。

1、不再存储key,而是将key改为int型的hashcode,这样,可以节省45%的空间

以下是java中的hashcode实现,测试了下,目前没发现有重复。

public int hashCode() {
int h = hash;
if (h == 0 && value.length > 0) {
char val[] = value;

for (int i = 0; i < value.length; i++) {
h = 31 * h + val[i];
}
hash = h;
}
return h;
}

2、针对有重复的value的情况,另存一个Map<hashcode,hashcode>,如果发现在map中存在当前使用的hashcode,则替代为使用map中的对应的value hashcode去查找。这样可以再减少25%的空间。

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>