-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix: avoid big parent in sliced string #7
Conversation
0d279bf
to
3a5e77f
Compare
window 单测还没有 node 11 的,所以暂时忽略 |
能否加一个可以引起内存泄漏的测试?就是不修改现在的代码,跑这个测试,会出现内存 oom 。 |
这个我试了下,比较难模拟,我理解这个其实不是泄露,而是多占用一些内容,另外 gc 亲和性下降。 不过有一个 demo http://blog.varunajayasiri.com/string_slice.html ,他证明如果不回收资源,sliced string 会比没有 sliced string 先崩溃 |
// https://github.com/nodejs/help/issues/711 | ||
// https://stackoverflow.com/questions/31712808/how-to-force-javascript-to-deep-copy-a-string | ||
const r = str.replace(REG_STR_REPLACER, a => DECODER_REPLACER[a]); | ||
return (' ' + r).slice(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加空字符串 ''
有效么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
或者 String(r)
呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
都没效果,我试过,它居然会判断是否发生变化
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON.parse(JSON.stringify(r))
也加上看看是否性能最差的。
3a5e77f
to
ba0453b
Compare
Codecov Report
@@ Coverage Diff @@
## master #7 +/- ##
=========================================
+ Coverage 97.08% 97.1% +0.01%
=========================================
Files 3 3
Lines 206 207 +1
=========================================
+ Hits 200 201 +1
Misses 6 6
Continue to review full report at Codecov.
|
@gxcsoccer 那现在我们如何判断已经修复了呢? |
dump heap 然后看 parent 是否还是原始的 |
flatstr 无效的话,得去给它提个 issue 或者 pr,不能让它继续误导使用者。 |
@fengmk2 flatstr 他主要不是解决 sliced string 的问题,因为我用 heapdump 是在 node 6 下做的,所以我怀疑 |
https://github.com/davidmarkclements/flatstr/blob/master/index.js |
@gxcsoccer 你来发 |
1.0.3 |
Checklist
npm test
passesAffected core subsystem(s)
Description of change
#6