-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add File
constructors that nudge people toward buffered I/O
#446
Comments
I have a bit of an issue with the motivation / framing. Basically it amounts to "people don't read the docs, so we move the dos into method names". This doesn't scale, so it shouldn't be the policy. Perhaps a better angle is adding a convenience for the thing that's one commonly wants anyway.
We could change |
I think we can combine both angles, "people don't read the docs, so they miss the thing one commonly wants." It's mildly convenient for experienced Rustaceans too, but saving a single
That's enough to make me not want to include |
We can do better than a simple |
True, but then that should also be made possible manually, like |
a duplex buffer could share the buffer between read and write modes, improving memory use by a bit. it could also optionally forward bytes from the write buffer to reads, avoiding extra syscalls in some cases (wrapped types would have to opt-in, e.g. if a File was wrapping a FIFO then it shouldn't forward bytes) |
Hmm, ideally the allocation should happen before the file open, so the filesystem isn't affected yet if it fails. I also imagine any |
We discussed this during today's libs-API meeting and we're on board with adding these methods. |
Add `File` constructors that return files wrapped with a buffer In addition to the light convenience, these are intended to raise visibility that buffering is something you should consider when opening a file, since unbuffered I/O is a common performance footgun to Rust newcomers. ACP: rust-lang/libs-team#446 Tracking Issue: rust-lang#130804
Add `File` constructors that return files wrapped with a buffer In addition to the light convenience, these are intended to raise visibility that buffering is something you should consider when opening a file, since unbuffered I/O is a common performance footgun to Rust newcomers. ACP: rust-lang/libs-team#446 Tracking Issue: #130804
Proposal
Problem statement
Using unbuffered I/O is a common performance footgun which has users asking why their Rust program is so slow.
Motivating examples or use cases
Issue #445 opened this discussion, "Attempt to help users avoid unbuffered small reads":
Solution sketch
Add two
File
constructors that wrap the result in buffers:These are trivial, but the main advantage is that such explicit methods will appear in auto-complete lists. Hopefully that will raise more programmer awareness that the basic
open
andcreate
methods are not buffered, by omission, so they may consider if that's something they want.Users with deeper
OpenOptions
will still need to decide which kind of buffering makes sense in their case. Similarly, if we wantcreate_new_buffered
, we would probably chooseBufWriter
, whereascreate_new
is opened in read-write mode.Alternatives
The status quo is that
File
documents this:We could deem that sufficient.
Attempt to help users avoid unbuffered small reads #445 has several other ideas like debug assertions, new lints, or cargo tooling for performance footguns. Any of those could still be implemented in addition to this proposal.
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: