-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Read::bytes() is a performance trap #28073
Comments
Do you think it's a trap even with the BufReader? It's surprisingly good. |
The performance with BufReader seems fine... the problem is really the performance without BufReader. Actually, hmm... maybe the implementation of bytes() for File should build a BufReader? That seems a little awkward, but I guess it's potentially workable. |
I can see where several The easiest fix would be to document this on the
Another solution could be to let pub struct Bytes<R> {
inner: BytesInner<R>,
}
enum BytesInner<R> {
Raw(R),
Buffered(BufReader<R>),
} Then the |
@cybergeek94 BytesInner sounds good, but I'm not sure if we can actually do it. The problem is that it's a hidden buffer that the user can't recover -- think of the case It's not just about
|
The best solution with the least commitment is to educate the user better about buffers and when to use them. |
Filing as a doc bug. We talk about this in BufReader, but not Read. Seems bad. |
On my computer, this takes about 0.011s to run. If you comment out the line to create the BufReader, the code still compiles... but it takes roughly 0m0.209s to run.
It seems like Rust should try to prevent people from shooting themselves in the foot, although I'm not exactly sure what could be done short of deprecating it.
The text was updated successfully, but these errors were encountered: