-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Improve efficiency of buffered_reader. #21256
Conversation
Anyway, would be good to get some benchmarks/ |
Cool, thanks for the suggestion. Traces were obtained with Microsoft's Process Monitor, with the following filters:
My application is a medical image viewing program which, conveniently, only uses
For the large buffer, my code reduced the number of reads by 9.2%. For the small buffer, my code reduced the number of reads by 44.9% |
FYI buffered reader used to be implemented in terms of |
Drive by thoughts:
|
I considered this, the problem is that the next |
I've implemented @matklad's suggestion. The code became beautifully small. My benchmarks with my own program showed no difference in performance in ReleaseFast. |
CI was failing because the tests for the |
The current implementation of buffered_reader always reads from the unbuffered reader into the internal buffer, and then dumps the data onto the destination. This is inefficient, as sometimes it's possible to read directly into the destination. The current strategy generates more memory copies and unbuffered reads than necessary. This PR implements a 3-step algorithm to buffered_reader to resolve these problems.
The tests for the BufferedReader wrongfully expected read to behave like readAll. That is, they didn't expect partial reads.
bb7baa6
to
e4b1e02
Compare
Thank you for the collaboration. @LucasSantos91 could you share your testing methodology as well as your latest performance data points and give me permission to copy that into the future release notes? |
I tested it with my own program, using medical images from real patients. Sadly, I can't share them. |
The previous implementation of buffered_reader always reads from the unbuffered reader into the internal buffer, and then dumps the data onto the destination. This is inefficient, as sometimes it's possible to read directly into the destination. The previous strategy generates more memory copies and unbuffered reads than necessary.
The previous implementation of buffered_reader always reads from the unbuffered reader into the internal buffer, and then dumps the data onto the destination. This is inefficient, as sometimes it's possible to read directly into the destination. The previous strategy generates more memory copies and unbuffered reads than necessary.
The current implementation of buffered_reader always reads from the unbuffered reader into the internal buffer, and then dumps the data onto the destination. This is inefficient, as sometimes it's possible to read directly into the destination. The current strategy generates more memory copies and unbuffered reads than necessary. This PR implements a 3-step algorithm to buffered_reader to resolve these problems.