Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

writeFileSync of a large file on Windows seems to exhibit poor behavior. #5596

@CyrusNajmabadi

Description

@CyrusNajmabadi

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.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions