Very slow Files.newInputStream(...).skip(n)

Simone Bordet simone.bordet at gmail.com
Tue Jul 2 09:01:33 UTC 2019


Hi,

we have moved Jetty to use newer APIs, replacing
java.io.FileInputStream with Files.newInputStream(Path), which
delegates to FileSystemProvider.newInputStream() which eventually
returns a sun.nio.ch.ChannelInputStream.

Unfortunately, ChannelInputStream.skip() implementation is very naive
and very slow for large files.
On the contrary, FileInputStream.skip() goes native and uses "seek"
primitives to be efficient.

The use case is that to read a large file (e.g. a movie) using HTTP's
range requests: the browser sends a request and asks e.g. for the
bytes ranging from 1 GiB to 1 GiB + 128 KiB.

Calling skip(1073741824) in the two cases will have very different performances.

I am a JDK Author and I can open a bug about this if you think it's appropriate.

Thanks!

-- 
Simone Bordet
---
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz


More information about the nio-dev mailing list