New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for direct access to memory mapped files and shared memory #1063
Comments
Speaking about multiplatform:
|
DirectByteBuffers can achieve great performance, but they’re significantly more involved to use because they aren’t dynamically sized and because they don’t participate in garbage collection. If that’s what you want I recommend using a library like Netty that’s built for that. But also note that additional capability might not yield performance gains in practice. |
@swankjesse, is there a way to work with shared memory or memory-mapped files with Okio? |
@snrostov nope! If you use FileHandle it can do random access reads and writes, and I trust the kernel to give you similar performance to memory mapping. |
I'm sure it is not at least for shared memory and files that are cached in kernel memory (because kernel should copy data from kernel to userspace). Will try to show it in benchmarks. |
Sorry, I read the discussion but found that they said that with fix |
Yeah, good point! Okio will always require memory to be copied into an Please don’t write a benchmark if your intention is to convince us to add that functionality though. We’ve made certain tradeoffs in Okio that yield great performance in practice but that also lose to other approaches in benchmarks. For example, although we pay for a copy when reading a file into a Buffer, we save a copy when sending that data in an OkHttp RequestBody, or decoding it as a Wire protocol buffer. |
Ok, fair enough. Thanks for the answer! |
It seems currently OkIo is ByteArray based only.
To achieve native speed for MemoryMapped files (and shared memory), the underlying memory should be accessed via the DirectByteBuffer or other Java API for accessing non-heap memory.
It would be nice to have a way to create such Okio
Buffer
. Otherwise, it is impossible to use Okio in projects where we need no-copy access to native memory.The text was updated successfully, but these errors were encountered: