Replies: 4 comments 4 replies
-
Differences between Bun and Node.js
|
Beta Was this translation helpful? Give feedback.
-
The readFile(path, ‘utf8’, cb) is the main I/O bottleneck of all bundlers and it should be specifically optimized (possibly the sync one too). Currently it’s incredibly inefficient as it reads all data as buffers, concatenate them, and then convert it to string. This allocates 3x the data of the file to read. Another significant angle to pursue is to use better kernel primitives for file system operations, e.g. finishing libuv/libuv#1947. |
Beta Was this translation helpful? Give feedback.
-
The conat is only done in case the file size can not be determined. That case can be optimized by directly converting the buffer to a string with StringDecoder and to concat those. But that should not be the common case. |
Beta Was this translation helpful? Give feedback.
-
hey here 👋 I started something here about merging |
Beta Was this translation helpful? Give feedback.
-
I'm trying to understand fs.readFile's flow and understand where the bottlenecks are. Since I'm quite new to Node.js (especially on the C++ side), I wanted to create this discussion to receive some feedback about potential improvements that can be made for fs.readFile and fs.readFileSync.
Flow
Suggestions
Beta Was this translation helpful? Give feedback.
All reactions