-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
readFileSync
is 40% faster than readFile
for large files
#41435
Comments
Since the performance loss can appear huge for reading a file in 512KB chunks, I did spent some time to analyze where it is coming from. This for reading 32MB files. The larger the file, the larger the loss, asymptotically approaching 40%.
So why so many context switches? Reading a 32MB file in 512KB blocks means there will be 64 reads. Where do all those context switches come from? Here are the context switches of one reading cycle (17 is the file, 16 is the eventfd, ie libuv
Two things to note here:
|
I wonder, wouldn't it be possible to continue the reading without waking up the event loop? After all, the event loop is not needed until the final callback? I have the same problem in The problem is that currently one cannot enqueue work from a worker thread - only the event loop can enqueue work. This is definitely fixable. In the case of This requires that an alternative interface is provided where one can pass either a finishing callback which has to run on the main thread, either an intermediary callback which will run in the worker thread. |
@mmomtchev Wonderful research! Any way to get my hands on your testing script(s)? Would be interesting to see if I can replicate your findings. 😃 |
It nothing but reading a large a file over and over in a loop |
Hi, I have one or two questions regarding this:
This works well, as far as we have enough memory, where 1 GB text will require around 2,5 GB RAM. Now lets consider the same, but using javascript.
? No matter how big the file is? |
By some coincidence I was thinking about this earlier this week. The problem with For small files that adds considerable overhead. It's way more efficient to add a C++ (If and when libuv grows io_uring support, that might turn into a deoptimization again, but that's still in the future.) |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
What is the problem this feature will solve?
make
readFile
as fast asreadFileSync
What is the feature you are proposing to solve the problem?
read the whole file in one operation to avoid excessive context switching
What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: