-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Document that File does not buffer reads/writes #119319
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
library/std/src/fs.rs
Outdated
@@ -31,6 +31,11 @@ use crate::time::SystemTime; | |||
/// on closing are ignored by the implementation of `Drop`. Use the method | |||
/// [`sync_all`] if these errors must be manually handled. | |||
/// | |||
/// `File` objects do not buffer reads and writes by default. For efficiency, | |||
/// consider wrapping the file in a [`BufReader`] or [`BufWriter`] when performing | |||
/// multiple [`read`] or [`write`] calls, unless unbuffered reads and writes |
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.
It should say small reads and writes. You won't get any speedup if you're performing multiple large operations that exceed the buffer size.
library/std/src/fs.rs
Outdated
@@ -31,6 +31,11 @@ use crate::time::SystemTime; | |||
/// on closing are ignored by the implementation of `Drop`. Use the method | |||
/// [`sync_all`] if these errors must be manually handled. | |||
/// | |||
/// `File` objects do not buffer reads and writes by default. For efficiency, |
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.
/// `File` objects do not buffer reads and writes by default. For efficiency, | |
/// `File` does not buffer reads and writes. For efficiency, |
The "by default" doesn't add anything, it can't be changed. And wrapping it in a buffer makes it a different type.
50bf8ea
to
1245178
Compare
(It seems like you pushed a new commit but it didn't actually contain any changes according to GitHub? Maybe you forgot to add the changes to the commit) |
1245178
to
5cbe41a
Compare
Yes, sorry, you're exactly right. The requested changes are now pushed. |
@bors r+ rollup=always |
…e8472 Document that File does not buffer reads/writes ...and refer to `BufReader`/`BufWriter`. This is a common source of efficiency issues in Rust programs written naively. Including this information with the `File` docs, and adding a link to the wrapper types, will help discoverability.
…e8472 Document that File does not buffer reads/writes ...and refer to `BufReader`/`BufWriter`. This is a common source of efficiency issues in Rust programs written naively. Including this information with the `File` docs, and adding a link to the wrapper types, will help discoverability.
Rollup of 21 pull requests Successful merges: - rust-lang#119086 (Query panic!() to useful diagnostic) - rust-lang#119239 (Remove unnecessary arm in `check_expr_yield`) - rust-lang#119298 (suppress change-tracker warnings in CI containers) - rust-lang#119319 (Document that File does not buffer reads/writes) - rust-lang#119434 (rc: Take *const T in is_dangling) - rust-lang#119444 (Rename `TyCtxt::is_closure` to `TyCtxt::is_closure_or_coroutine`) - rust-lang#119474 (Update tracking issue of naked_functions) - rust-lang#119476 (Pretty-print always-const trait predicates correctly) - rust-lang#119477 (rustdoc ui: adjust tooltip z-index to be above sidebar) - rust-lang#119479 (Remove two unused feature gates from rustc_query_impl) - rust-lang#119487 (Minor improvements in comment on `freshen.rs`) - rust-lang#119492 (Update books) - rust-lang#119494 (Deny defaults for higher-ranked generic parameters) - rust-lang#119498 (Update deadlinks of `strict_provenance` lints) - rust-lang#119505 (Don't synthesize host effect params for trait associated functions marked const) - rust-lang#119510 (Report I/O errors from rmeta encoding with emit_fatal) - rust-lang#119512 (Mark myself as back from leave) - rust-lang#119514 (coverage: Avoid a query stability hazard in `function_coverage_map`) - rust-lang#119523 (llvm: Allow `noundef` in codegen tests) - rust-lang#119534 (Update `thread_local` examples to use `local_key_cell_methods`) - rust-lang#119544 (Fix: Properly set vendor in i686-win7-windows-msvc target) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#119319 - chfogelman:buffered-file-doc, r=the8472 Document that File does not buffer reads/writes ...and refer to `BufReader`/`BufWriter`. This is a common source of efficiency issues in Rust programs written naively. Including this information with the `File` docs, and adding a link to the wrapper types, will help discoverability.
...and refer to
BufReader
/BufWriter
.This is a common source of efficiency issues in Rust programs written naively. Including this information with the
File
docs, and adding a link to the wrapper types, will help discoverability.