Skip to content

Make InternalKeyComparator not configurable - #10342

Closed
siying wants to merge 3 commits into
meta:mainfrom
siying:internal_key_name
Closed

siying wants to merge 3 commits into
meta:mainfrom
siying:internal_key_name

Conversation

@siying

@siying siying commented Jul 11, 2022

Copy link
Copy Markdown
Contributor

Summary:
InternalKeyComparator is an internal class which is a simple wrapper of Comparator. #8336 made Comparator customizeable. As a side effect, internal key comparator was made configurable too. This introduces overhead to this simple wrapper. For example, every InternalKeyComparator will have an std::vector attached to it, which consumes memory and possible allocation overhead too.
We remove InternalKeyComparator from being customizable by making InternalKeyComparator not a subclass of Comparator.

Test Plan: Run existing CI tests and make sure it doesn't fail

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@siying has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Comment thread HISTORY.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CPU efficiency (kind of regression)

Comment thread include/rocksdb/comparator.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There should be a comment for why this exists, such as "used internally"

Comment thread table/merging_iterator.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I could see this being a performance regression on large keys where there's a good chance a.size() != b.size().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Potentially yes but now InternalKeyComparator just uses a default implementation of Equal() which does exactly what is done here. Improving efficiency of InternalKeyComparator::Equal() sounds outside the scope of the PR and I don't see a need to mix the two.

@mrambacher

Copy link
Copy Markdown
Contributor

While I agree that it is less-than-ideal to have an unused vector here taking up space, I am wondering if this is the best solution or what problem is being solved here. What is the performance difference with this change?

Many of the methods that are part of the Comparator have not been moved to the ComparatorInterface. Is there a reason these were skipped?

What would happen if instead the std::vector was changed into a std::unique_ptrstd::vector, and constructors (and guards) were added that allowed for this vector to be null? Would the equivalent performance/size gain be accomplished for all classes/implementations that chose to use that new constructor (and not have any options)?

@siying

siying commented Jul 12, 2022

Copy link
Copy Markdown
Contributor Author

While I agree that it is less-than-ideal to have an unused vector here taking up space, I am wondering if this is the best solution or what problem is being solved here. What is the performance difference with this change?

Many of the methods that are part of the Comparator have not been moved to the ComparatorInterface. Is there a reason these were skipped?

What would happen if instead the std::vector was changed into a std::unique_ptrstd::vector, and constructors (and guards) were added that allowed for this vector to be null? Would the equivalent performance/size gain be accomplished for all classes/implementations that chose to use that new constructor (and not have any options)?

We know that BlockIter is quite sensitive to memory size. The reason is that it would usually use memory allocated by ArenaWrappedDBIter. We experienced performance regression at least twice for object size increase in BlockIter. A whole InternalKeyComparator will likely to be put in BlockIter after we fix #9611 for #10340 . Even 8 byte should ideally be removed. Fundamentally, I don't see a point of making a non-configurable class configurable. It is simply confusing and is hard to maintain.

Regarding not putting more functions in CompareInterface. Ideally, Comparator and InternalKeyComparator don't need to share any function. They operate on different things and don't need to share. I am trying to be conscious on what they share and minimize it. It would also make it easy to get ride of CompareInterface in the future.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@siying has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@siying has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Comment thread db/dbformat.h Outdated
Comment on lines 265 to 266

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are these methods still needed/used? If so, can they be renamed so that it is clear they are not the same/related to the ones in Comparator?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These functions are still used index_builder.h. Let me see whether I can move it to clear InternalKeyComparator.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved the functions to IndexBuilder.

Comment thread db/dbformat.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this method still needed? If so, can it be renamed to prevent confusion with the method in Comparator?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me see whether I can delete the function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed it.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@siying has updated the pull request. You must reimport the pull request before landing.

siying added 3 commits July 13, 2022 16:13
Summary:
InternalKeyComparator is an internal class which is a simple wrapper of Comparator. meta#8336 made Comparator customizeable. As a side effect, internal key comparator was made configurable too. This introduces overhead to this simple wrapper. For example, every InternalKeyComparator will have an std::vector attached to it, which consumes memory and possible allocation overhead too.
We remove InternalKeyComparator from being customizable by making InternalKeyComparator not a subclass of Comparator.

Test Plan: Run existing CI tests and make sure it doesn't fail
@siying
siying force-pushed the internal_key_name branch from 1c30c38 to 7342554 Compare July 13, 2022 23:13
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@siying has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@siying has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@mrambacher mrambacher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the changes

Comment thread db/dbformat_test.cc

#include "db/dbformat.h"

#include "table/block_based/index_builder.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: This should probably include compaator.h as well.

Tim-Reed pushed a commit to Tim-Reed/rocksdb that referenced this pull request Oct 1, 2026
Summary:
InternalKeyComparator is an internal class which is a simple wrapper of Comparator. meta#8336 made Comparator customizeable. As a side effect, internal key comparator was made configurable too. This introduces overhead to this simple wrapper. For example, every InternalKeyComparator will have an std::vector attached to it, which consumes memory and possible allocation overhead too.
We remove InternalKeyComparator from being customizable by making InternalKeyComparator not a subclass of Comparator.

Pull Request resolved: meta#10342

Test Plan: Run existing CI tests and make sure it doesn't fail

Reviewed By: riversand963

Differential Revision: D37771351

fbshipit-source-id: 917256ee04b2796ed82974549c734fb6c4d8ccee
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.

4 participants