about summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-11-22 01:12:58 +0800
committerGitHub <noreply@github.com>2017-11-22 01:12:58 +0800
commit9b090a026108fab89cfe5f39bfd3492597e76ad4 (patch)
tree3add64bfe94aa4d321ce1785bd30baf48a0ed2c9 /src/rustllvm/RustWrapper.cpp
parentf8b3e7cee95f110525afcae6ed8316f59b00f1b1 (diff)
parent6b1a3bc80af12a509ef8ca37f3dc1d1dc8541041 (diff)
downloadrust-9b090a026108fab89cfe5f39bfd3492597e76ad4.tar.gz
rust-9b090a026108fab89cfe5f39bfd3492597e76ad4.zip
Rollup merge of #46050 - sunfishcode:read_to_end, r=sfackler
Optimize `read_to_end`.

This patch makes `read_to_end` use Vec's memory-growth pattern rather
than using a custom pattern.

This has some interesting effects:

 - If memory is reserved up front, `read_to_end` can be faster, as it
   starts reading at the buffer size, rather than always starting at 32
   bytes. This speeds up file reading by 2x in one of my use cases.

 - It can reduce the number of syscalls when reading large files.
   Previously, `read_to_end` would settle into a sequence of 8192-byte
   reads. With this patch, the read size follows Vec's allocation
   pattern. For example, on a 16MiB file, it can do 21 read syscalls
   instead of 2057. In simple benchmarks of large files though, overall
   speed is still dominated by the actual I/O.

 - A downside is that Read implementations that don't implement
   `initializer()` may see increased memory zeroing overhead.

I benchmarked this on a variety of data sizes, with and without
preallocated buffers. Most benchmarks see no difference, but reading
a small/medium file with a pre-allocated buffer is faster.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions