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

nodejs里内存占用巨大 #19

Closed
wanming opened this issue Aug 25, 2014 · 5 comments
Closed

nodejs里内存占用巨大 #19

wanming opened this issue Aug 25, 2014 · 5 comments
Milestone

Comments

@wanming
Copy link

wanming commented Aug 25, 2014

qq20140825-1
如图,在nodeJS里引入拼音库后node进程内存使用200M,去掉后变成100M,heap里显示占内存(图片里显示占用60M)的主要是一些常用的成语、pinyin里的node_modules里的object,请问有没有什么可以优化的办法?

@hotoo
Copy link
Owner

hotoo commented Aug 25, 2014

pinyin 本身的字库(1.3M)和词库(1.8M),另外依赖了分词程序,其词典大约 10M,这是文件存储本身的大小,运行时的内存可能比这些更大些。

最早的时候,这个模块仅实现了 Web 版,提供了有限的常用字,并且不提供分词和词语功能。
同时为了追求算法上的极速,将整个字典装入内存,使用空间换得时间。

现在支持 Node 版,增加了分词和词组,用以提升同音字的拼音准确率,并提供了较为完整的拼音字库。

理论上,一次装载后,内存就基本稳定了(如果有内存泄漏请告知)

目前还没有找到非常有效的平衡性能和内存资源的方法。如有你有好的想法,请不吝赐教 :)

@wanming
Copy link
Author

wanming commented Aug 25, 2014

怎样在NodeJS里使用Web版?我用的NodeJS里的cluster,共享内存有点麻烦,我在index.js里将if(isNode)换成if(false)后提示错误。BTW,使用Web版本和Node版有哪些区别?我只用多音字、不用几声,转换的都是比较常用的汉字或词。

@hotoo
Copy link
Owner

hotoo commented Aug 25, 2014

要分词处理多音字就不好精简了,否则可以考虑提供一个 Node 精简版,只提供单字拼音转换。

@wanming
Copy link
Author

wanming commented Aug 25, 2014

好吧,我先这样用着吧。麻烦了

@wanming wanming closed this as completed Aug 25, 2014
This was referenced Sep 18, 2014
@TooBug
Copy link

TooBug commented Dec 12, 2014

同需要精简版,不需要考虑词组的问题,可否提供一下是否使用词组的选项,选项启用后再引入词组。试着优化了一下,去掉词组的话,取“你好”的拼音,本机(2013年Macbook Pro,8G内存)可以从1100+ms降到150ms左右,内存应该也会降一半以上。

P.S.之所以研究这个,是因为用微信开发了一个查通讯录的功能,服务器配置很低,查询词组耗时很大,经常导致超过微信5s响应时间。

@hotoo hotoo added this to the 2.5.0 milestone Jun 18, 2015
luzhen328 pushed a commit to luzhen328/pinyin.js that referenced this issue May 5, 2019
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

3 participants