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

Optimize IterKey #11153

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Optimize IterKey #11153

wants to merge 8 commits into from

Conversation

rockeet
Copy link
Contributor

@rockeet rockeet commented Jan 28, 2023

IterKey is essentially an SSO(short string optimization), it can be optimized more, in this PR:

  1. sizeof(IterKey) is reduce from 72 to 64 and inline buffer size is increased from 32 to 48
  2. key_size_ and buf_size_ changed to uin32 because it is expected never larger than 2G
  3. buf_size_ is also used as a flag to identify inline buffer or outline buffer
  4. buf_ ptr is folded to be shared with space_ by using union
    • add getter func buf() makes the intention clear
  5. is_user_key_ is changed to a bitfield which packed with buf_size_
    • buf_size_ is accessed less frequent than key_size_, use bit field will not harm performance

@ronag
Copy link

ronag commented Jan 28, 2023

Make inline buffer smaller by 3 bytes and remove the nano optimizations (3,4,5) will make the code much more maintainable.

db/dbformat.h Show resolved Hide resolved
@rockeet
Copy link
Contributor Author

rockeet commented Jan 28, 2023

Make inline buffer smaller by 3 bytes and remove the nano optimizations (3,4,5) will make the code much more maintainable.

SSO is really a bit tricky, but it is localized to IterKey internal, and IterKey is used widely in rocksdb, so efficiency should be prefered.

BTW: This code have been running for a long time in hour private branch, I just contribute our patch to the community. Also I have fixed the patch to pass the CI static analysis.

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

Successfully merging this pull request may close these issues.

None yet

3 participants