-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs: remove chunk by chunk file read #44276
Conversation
It seems this is not improving things in all cases, so maybe there is more work to do on this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The upper bound is there for partitioning the reads. For further information check #25741 and #17054.
We should not remove that.
Please also check the comment right above the upper bound: https://github.com/nodejs/node/pull/44276/files#diff-5cd422a9a64bc2c1275d70ba5dcafbc5ea55274432fffc5e4159126007dc4894L137-L138
Thanks @BridgeAR for the links. It was really helpful towards the decisions that lead to this discussion. So, removing chunks blocks the IO. Not-removing chunks increase execution speed. Since we don't want to do that, but we also have to reduce the number of calls between JS and C++, there are not many options here. If we're going to leave the chunks with 512kb, the only optimization we can do at this point is to move open, fstat, close functionality inside fs/read c++ implementation to reduce the communication. Even after that, the number of calls between JS and C++ will be directly correlated by file_size / 512. I'll be happy to dive into the correct path here if anyone would be kind to help, but afaik if we want to improve the performance, we need to pick our battles. Here's my review of the current flow for fs.readFile: #44239 |
I think the use case to optimize is reading
I think you can move the accumulation of bytes in C++ and avoid calling JS at all. |
I'm still investigating why the performance is down by 20% for certain cases, but 68% performance looks like a good start.
I left the chunk-by-chunk implementation to support edge cases where the file size is unknown before reading it, where fstat returns 0.