vasi / positioned-io

Read and write from offsets in Rust.
MIT License
74 stars 18 forks source link

Windows read_at implementation is very slow #6

Closed Dr-Emann closed 5 years ago

Dr-Emann commented 6 years ago

The implementation of ReadAt for windows is very slow. Benchmarks are here, and a violin graph from a run is attached: violin

The memory map based implementation currently used is about an order of magnitude slower than using a refcell. Even faster is to use seek_read (which does change the current offset in the file.

I personally would use the seek_read function, and document that uses of ReadAt may or may not change the current file offset.

niklasf commented 6 years ago

Mhh, yeah ... if there is no other way, like somehow keeping the memory map alive instead of repeated mapping and unmapping, that might be best.

Meanwhile the currently released positioned-io 0.2 still essentially uses seek_read.

Dr-Emann commented 6 years ago

I don't think so, at least not implemented directly on File. It could be done as a wrapper around file which also implements ReadAt, but doesn't move the file pointer.

niklasf commented 5 years ago

I added a wrapper that simply uses seek_read (RandomAccessFile) and released it as positioned-io-preview = "0.3.1". It implements ReadAt but not Read.

It is possible to observe the moving cursor by constructing another File handle with the same file descriptor, but at least the wrapper makes you think twice.