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

Micro-optimizations in ContentKey + TypeMapping #6975

Merged
merged 2 commits into from
Jun 5, 2023

Conversation

snazy
Copy link
Member

@snazy snazy commented Jun 3, 2023

No description provided.

}
if (e.isEmpty()) {
int l = e.length();
sum += l;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are micro-optimizing, this statement could be moved to line 189.

Copy link
Member Author

Choose a reason for hiding this comment

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

That would optimize for the bad case though.

if (sum > MAX_LENGTH) {
throw new IllegalStateException("Key too long, max allowed length: " + MAX_LENGTH);
}
if (elements.size() > MAX_ELEMENTS) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This if block could be moved to line 169: there is no point in iterating over the elements, if we know that there are too many elements.

Copy link
Member Author

Choose a reason for hiding this comment

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

That would optimize for the bad case though.

@@ -196,7 +196,11 @@ private static StringBuilder keyToStoreKeyPrepare(
// Note: the relative values of outer and inner (key elements) separators affect the correctness
// of StoreKey comparisons WRT to ContentKey comparisons. The inner separator must be greater
// than the outer separator because longer ContentKeys are greater than shorter ContentKeys.
StringBuilder sb = new StringBuilder();
int len = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 4?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added comment

@snazy snazy merged commit 4e4681b into projectnessie:main Jun 5, 2023
22 checks passed
@snazy snazy deleted the micro-opt-ck-tm branch June 5, 2023 14:35
snazy added a commit to snazy/nessie that referenced this pull request Jun 5, 2023
snazy added a commit to snazy/nessie that referenced this pull request Jun 5, 2023
snazy added a commit that referenced this pull request Jun 5, 2023
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.

None yet

2 participants