-
Notifications
You must be signed in to change notification settings - Fork 11
Improve performance 20%-110% #14
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0420d77
Add jmh.
htmldoug d5b6043
Add first benchmark.
htmldoug 05155de
Optimization: 5.735 => 5.489
htmldoug 84b0a8c
VPackBuilder optimizations: 2830 => 1358 ns/op
htmldoug a02010c
Fast path for ASCII 1358 => 946 ns/op
htmldoug cdb7337
985 => 896 ns/op
htmldoug 2b3a5c7
VPackSlice 1000 => 745 ns/op
htmldoug 877c05b
VPackSlice 745 =>> 720 ns/op
htmldoug 2026a85
Revert ASCII-specific optimizations 852 => 1386 ns/op
htmldoug 7372b85
Remove unnecessary "throws VPackBuilderException"
htmldoug e211210
PR comments: avoid unchecked cast for generic array.
htmldoug 9547676
PR comments: Remove spf4j-jmh. Resolve licensing concerns.
htmldoug 47d85af
PR comments: Fix javadoc things.
htmldoug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
/target | ||
/.idea | ||
/*.iml | ||
*.jfr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/arangodb/velocypack/VPackStringSlice.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.arangodb.velocypack; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
/** | ||
* Wrapper around a {@link ValueType#STRING} supporting fast bytewise comparison. | ||
* | ||
* @see <a href="https://github.com/arangodb/velocypack/blob/master/VelocyPack.md#objects">VelocyPack Objects</a> | ||
*/ | ||
public class VPackStringSlice implements Comparable<VPackStringSlice> { | ||
private byte[] vpack; | ||
/** | ||
* Index of the string bytes within {@link vpack}, | ||
* i.e. tag byte and length are somewhere before this index. | ||
*/ | ||
private int start; | ||
private int length; | ||
|
||
public VPackStringSlice(byte[] vpack, int start, int length) { | ||
this.vpack = vpack; | ||
this.start = start; | ||
this.length = length; | ||
} | ||
|
||
@Override | ||
public int compareTo(VPackStringSlice o) { | ||
return compareToBytes(o.vpack, o.start, o.length); | ||
} | ||
|
||
public int compareToBytes(byte[] other) { | ||
return compareToBytes(other, 0, other.length); | ||
} | ||
|
||
public int compareToBytes(byte[] other, int off, int oLen) { | ||
for (int i = 0; i < length && i < oLen; i++) { | ||
int c = (vpack[start + i] & 0xff) - (other[off + i] & 0xff); | ||
if (c != 0) return c; | ||
} | ||
return length - oLen; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new String(vpack, start, length, StandardCharsets.UTF_8); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure about this decision. Starting at the tag byte would make it more similar to
VPackSlice
, but it would add a bit more complexity to thecompareToBytes
operations. Those comparisons are on the hot path for theO(ln n)
path queries and for sorting the offset table while constructing the object.I couldn't think of a good way to make this class private, so it's probably worth giving it some thought before merging so we don't break compatibility later.
@mpv1989 @hkernbach What do you think?