Commit a94d2da
committed
Fix memory leak in promise loop by breaking the recursion
It turns out that neither bluebird nor the native Promise implementation in v8
actually perform TCO when a promise is returned. This built up a long chain of
promise references in memory while dumping millions of wikipedia articles. The
dump would suceed, but for enwiki at least at the end the dumper would use >1G
of heap.
Since nextTick and its siblings setInterval and setTimeout are all pretty
expensive, we only break the chain occasionally. In local tests this
construct runs 70000000 iterations in constant memory, while the same loop
would exhaust the default 2G heap limit.1 parent d0d074a commit a94d2da
1 file changed
+9
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
149 | 150 | | |
150 | 151 | | |
151 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
152 | 160 | | |
153 | 161 | | |
154 | 162 | | |
| |||
0 commit comments