yanyiwu / cppjieba

"结巴"中文分词的C++版本
MIT License
2.58k stars 691 forks source link

优化内存占用的几个点 #154

Closed rookie-J closed 3 weeks ago

rookie-J commented 3 years ago

我们用jieba分词做了一个文件内容搜索,在处理大批量文本时jieba分词的内存占用是偏高的,因此目前有以下几种优化:

  1. 降低代码中临时变量的中转存储,例如CutToWord中vector wrs的存在就没有必要;
  2. PreFilter转换输入的str到unicode,然后每一个字节都跟部分转义字符比对这样的效率太低了,可以在str输入后先做一遍类似string.repalce操作把转义字符全部转换为0x20或者其他截至符,后面对str分段时只对比是否等于0x20即可;
  3. PreFilter转换输入的str到unicode这个操作是否可以考虑去掉,或者给utf-8单独一个接口;
  4. 使用Darts生成DATrie的方式加载词典确实常驻内存降低了80%左右; 没有太在意与cppjieba之间的代码差异,我的优化大部分都是基于DATrie版本的cppjieba,有其他优化项也可以一起讨论哈!
znsoftm commented 3 years ago

你的优化是pr到这儿了还是另起一个仓库了?

rookie-J commented 3 years ago

没有提pr,改动有点大。最近好像发现了一个bug,DP分词中计算最大路径时CalcDP里根据查找到的结果计算最大weight时用到了其他DAG里的数据,但是find里面并没有给这个数据赋值

github-actions[bot] commented 1 month ago

This issue has not been updated for over 1 year and will be marked as stale. If the issue still exists, please comment or update the issue, otherwise it will be closed after 7 days.

github-actions[bot] commented 3 weeks ago

This issue has been automatically closed due to inactivity. If the issue still exists, please reopen it.