Skip to content
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

Thoughts on using ByteBuffer instead of UNSAFE in zstd? #146

Closed
dlazerka opened this issue Jun 17, 2022 · 1 comment
Closed

Thoughts on using ByteBuffer instead of UNSAFE in zstd? #146

dlazerka opened this issue Jun 17, 2022 · 1 comment

Comments

@dlazerka
Copy link

Hi,
Thanks for the tool!

I'm wondering if there are any pitfalls or other considerations in trying to implement the same thing, but instead of UNSAFE.* family of functions -- using standard ByteBuffers? Seems like a straightforward change, but maybe I'm missing something.

Pros would be:

  1. No dependency on sun.misc.* which prevents using modern JDK --release for modern versions (sun.misc is unavailable).
  2. Potentially easier on AOT compilation.
  3. In some sense it would be more "pure java".
  4. Would support sliced heap byte buffers (with .arrayOffset > 0).

The code of course supports ByteBuffers, but only with zero arrayOffset, and internally it just uses them just as a byte[].

@martint
Copy link
Member

martint commented Jun 17, 2022

It's mostly due to performance. It's currently hard (impossible?) to get the same performance as Unsafe when accessing ByteBuffers via their public APIs.

Once the Foreign Memory APIs (https://openjdk.org/jeps/393) stabilize and we update this library to a more recent version of the JDK, we may be able to rewrite it against those APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants