Replies: 0 comments 8 replies
|
Differences between Bun and Node.js
|
|
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. |
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. |
|
hey here 👋 I started something here about merging |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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
All reactions