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

[kv] Use JDK9 Arrays#compare() to check bytes prefix for PrefixLookup #331

Merged
merged 2 commits into from
Feb 1, 2025

Conversation

swuferhong
Copy link
Collaborator

Purpose

Linked issue: #271

Currently, RocksDBKv#isPrefixEquals() very inefficient to compare arrays byte by byte. Java9 provides a more efficient way Arrays.compare(compare(byte[] a, int aFromIndex, int aToIndex, byte[] b, int bFromIndex, int bToIndex)), underlying it leverages SIMD instructions.

As it is only supported since Java9, In this pr, we implement it based on the running jdk env (the method can get the running JDK environment, if Java9 use the support Arrays.compare() method).

Tests

API and Format

Documentation

@wuchong
Copy link
Member

wuchong commented Jan 31, 2025

@swuferhong I adjusted the implementation a bit.

  1. extract the JDK9 compare logic from RocksDBKv into a common util so that it can be reused by others in the future.
  2. Use Arrays.equals(byte[], int, int, byte[], int, int) instead, because we only need to compare the prefix equality.
  3. Avoid to new PrefixComparer for each RocksDBKv instance. In the final, it's just a util method.

Copy link
Member

@wuchong wuchong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wuchong wuchong merged commit d13758d into alibaba:main Feb 1, 2025
2 checks passed
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

Successfully merging this pull request may close these issues.

[Feature] Use JDK9 Arrays.compare to check bytes prefix for PrefixLookup
2 participants