Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rookie-J opened this issue May 29, 2021 · 2 comments
Open

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

rookie-J opened this issue May 29, 2021 · 2 comments

Comments

@rookie-J
Copy link

我们用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
Copy link

znsoftm commented Jun 19, 2021

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

@rookie-J
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants