You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
In our project we often write multi-megabyte strings out to disk UTF8 encoded. We're finding that writeFileSync seems to perform quite poorly here (on the order of a mb/s). Profiling this showed that the creation of the buffer object to store the encoded data was the culprit.
We were able to work around the issue by breaking the string into 4k chunks and manually creating buffer objects for them that we then wrote out. This reduced write time for a large file from 2 seconds to 80ms.
Interestingly, even with the change, the majority of the time (72 of 80ms) is still spent in buffer creation.
It seems unfortunate that writeFileSync should exhibit such poor performance because of its dependence on Buffer's scaling issues. Technically there is no bug here wrt correctness. However, i feel that the performance issue is extreme enough to warrant a fix at the framework level so that it does not affect others.