save unnecessary allocations in mmap mode
- Dominant language
- C++
- Stars
- 32.1k
- Forks
- 6.9k
- Avg merge
- 32m
- Merged PRs (30d)
- 1
Description
Currently the RandomAccessFile::Read() API guarantees it'll be provided a scratch buffer large enough to store its result. However that buffer is not needed for `mmap()`-based file readers as those can return slices directly into mapped memory.
Perhaps we can introduce a RandomAccessFile{,Reader}::MappedRead() that does not take the scratch buffer and is tried first when allow_mmap_reads && immortal_table. If it returns NotSupported (the default implementation), we could fall back to allocating and then calling RandomAccessFileReader::Read() as before.
Edit: Note the current behavior involves a call to the allocator only for blocks bigger than kDefaultStackBufferSize (5000) bytes. Otherwise it uses a stack buffer which should not be a problem.
Contributor guide
Assessment
This issue has not been assessed yet.