rust/library/std/src
bors 50166d5e5e Auto merge of #98748 - saethlin:optimize-bufreader, r=Mark-Simulacrum
Remove some redundant checks from BufReader

The implementation of BufReader contains a lot of redundant checks. While any one of these checks is not particularly expensive to execute, especially when taken together they dramatically inhibit LLVM's ability to make subsequent optimizations by confusing data flow increasing the code size of anything that uses BufReader.

In particular, these changes have a ~2x increase on the benchmark that this adds a `black_box` to. I'm adding that `black_box` here just in case LLVM gets clever enough to remove the reads entirely. Right now it can't, but these optimizations are really setting it up to do so.

We get this optimization by factoring all the actual buffer management and bounds-checking logic into a new module inside `bufreader` with a new `Buffer` type. This makes it much easier to ensure that we have correctly encapsulated the management of the region of the buffer that we have read bytes into, and it lets us provide a new faster way to do small reads. `Buffer::consume_with` lets a caller do a read from the buffer with a single bounds check, instead of the double-check that's required to use `buffer` + `consume`.

Unfortunately I'm not aware of a lot of open-source usage of `BufReader` in perf-critical environments. Some time ago I tweaked this code because I saw `BufReader` in a profile at work, and I contributed some benchmarks to the `bincode` crate which exercise `BufReader::buffer`. These changes appear to help those benchmarks at little, but all these sorts of benchmarks are kind of fragile so I'm wary of quoting anything specific.
2022-07-27 09:49:06 +00:00
..
backtrace Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
collections Rollup merge of #96173 - jmaargh:jmaargh/with-capacity-doc-fix, r=Dylan-DPC 2022-06-23 14:39:05 -07:00
env std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
error Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
f32 Implement IEEE 754-2019 minimun and maximum functions for f32/f64 2021-11-20 10:14:03 +01:00
f64 Remove fNN::lerp - consensus unlikely 2021-10-25 22:44:41 -05:00
ffi Rollup merge of #97915 - tbu-:pr_os_string_fmt_write, r=joshtriplett 2022-07-17 13:08:48 +09:00
fs Ignore hiberfil_sys test in CI 2022-07-18 15:06:07 +01:00
io Auto merge of #98748 - saethlin:optimize-bufreader, r=Mark-Simulacrum 2022-07-27 09:49:06 +00:00
net Rollup merge of #97300 - ChayimFriedman2:patch-1, r=dtolnay 2022-07-05 10:42:52 +05:30
num rustc_expand: Mark inner #![test] attributes as soft-unstable 2020-11-20 19:35:03 +03:00
os Rollup merge of #98583 - joshtriplett:stabilize-windows-symlink-types, r=thomcc 2022-07-27 11:52:52 +09:00
panic review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
path Allow unused_macro_rules in path tests 2022-05-16 08:55:05 +02:00
prelude Finish bumping stage0 2022-05-27 07:36:17 -04:00
process Add test for issue #95178 2022-03-23 05:33:44 +00:00
sync Rollup merge of #97629 - guswynn:exclusive_struct, r=m-ou-se 2022-06-30 19:55:50 +02:00
sys Rollup merge of #98211 - devnexen:get_path_freebsd, r=Mark-Simulacrum 2022-07-26 13:12:18 +09:00
sys_common Rollup merge of #98101 - vladimir-ea:stdlib_watch_os, r=thomcc 2022-07-20 16:17:17 +05:30
thread Auto merge of #97925 - the8472:cgroupv1, r=joshtriplett 2022-07-23 13:33:56 +00:00
time Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
alloc.rs Update std::alloc::System docs 2022-06-26 16:31:29 +02:00
ascii.rs Remove use of #[rustc_deprecated] 2022-04-14 01:33:13 -04:00
backtrace.rs revert changes that cast functions to raw pointers, portability hazard 2022-03-29 20:18:27 -04:00
env.rs add aliases for current_dir 2022-05-24 19:41:40 -07:00
error.rs add tracking issue to generic member access APIs 2022-07-15 22:13:43 +00:00
f32.rs Rollup merge of #95483 - golddranks:improve_float_docs, r=joshtriplett 2022-05-09 18:45:35 +02:00
f64.rs Rollup merge of #95483 - golddranks:improve_float_docs, r=joshtriplett 2022-05-09 18:45:35 +02:00
fs.rs Add std::fs::write documentation precision 2022-07-11 09:48:47 +02:00
keyword_docs.rs Rollup merge of #98169 - pierwill:dyn-disp, r=JohnTitor 2022-06-17 07:16:58 +09:00
lazy.rs Move/rename lazy::Sync{OnceCell,Lazy} to sync::{Once,Lazy}Lock 2022-06-16 19:54:42 +04:00
lib.rs Auto merge of #97925 - the8472:cgroupv1, r=joshtriplett 2022-07-23 13:33:56 +00:00
macros.rs Make write/print macros eagerly drop temporaries 2022-05-22 16:11:08 -07:00
num.rs Add Saturating type (based on Wrapping type) 2021-08-10 19:27:01 +02:00
panic.rs Support unstable moves via stable in unstable items 2022-07-08 21:18:13 +00:00
panicking.rs Auto merge of #92461 - rust-lang:const_tls_local_panic_count, r=Mark-Simulacrum 2022-05-23 13:04:59 +00:00
path.rs Rollup merge of #97912 - Kixunil:stabilize_path_try_exists, r=dtolnay 2022-06-20 07:37:41 +09:00
primitive_docs.rs Improve the function pointer docs 2022-07-19 08:52:24 -07:00
process.rs Rollup merge of #97917 - AronParker:master, r=ChrisDenton 2022-07-07 20:33:23 +02:00
rt.rs Change Termination::report return type to ExitCode 2022-01-28 12:53:36 -08:00
time.rs std::time : fix doc variable name 2022-05-23 00:02:09 +02:00