Why use stream for warehouse#save()?
segayuu opened this issue · comments
The output by stream is obviously slower than fs.writeFile()
.
Nevertheless, stream is powerful because memory control by highWaterMark
can prevent memory from being consumed too much at once.
However, this can not be realized with just Writable
alone (at least Readable
or Generator
is almost required), you can ignore it, but in that case no memory control will be done and the stream loses its maximum advantage.
Although it is possible to use JSONStream.stringnify()
, it is said that an issue has been posted, "It is 100 times slower than JSON.sringnify()".
How stream performs memory management is described in this official document.
https://nodejs.org/en/docs/guides/backpressuring-in-streams/#how-does-backpressure-resolve-these-issues
Well, after #22, the speed of saving database seems to become 30x slower based on hexojs/hexo#3758 . We should have a look at this.