You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by GitBox <gi...@apache.org> on 2020/02/10 17:30:01 UTC
[GitHub] [qpid-proton-j] franz1981 opened a new pull request #36:
PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
franz1981 opened a new pull request #36: PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
URL: https://github.com/apache/qpid-proton-j/pull/36
The search algorithm chosen is Knuth-Morris-Pratt and could make
use of an additional jump table with certain Symbols
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org
[GitHub] [qpid-proton-j] franz1981 commented on issue #36: PROTON-2178
Implement efficient search of encoded Symbol on ReadableBuffer
Posted by GitBox <gi...@apache.org>.
franz1981 commented on issue #36: PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
URL: https://github.com/apache/qpid-proton-j/pull/36#issuecomment-584507278
I see that I'm not accounting for remaining space to search in to be less then the needle to search for :)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org
[GitHub] [qpid-proton-j] franz1981 commented on issue #36: PROTON-2178
Implement efficient search of encoded Symbol on ReadableBuffer
Posted by GitBox <gi...@apache.org>.
franz1981 commented on issue #36: PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
URL: https://github.com/apache/qpid-proton-j/pull/36#issuecomment-605095230
Hi @gemmellr I can close this and sorry to have made you to review this: I've included this general purpose search method directly on AMQ code base, but still, would be useful (maybe in a new codec) a method to perform a "real" search for a specific property key in some section of AMQP, instead of a greedy approach like this.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org
[GitHub] [qpid-proton-j] gemmellr commented on a change in pull request #36:
PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
Posted by GitBox <gi...@apache.org>.
gemmellr commented on a change in pull request #36: PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
URL: https://github.com/apache/qpid-proton-j/pull/36#discussion_r379357315
##########
File path: proton-j/src/main/java/org/apache/qpid/proton/amqp/Symbol.java
##########
@@ -60,6 +66,82 @@ public CharSequence subSequence(int beginIndex, int endIndex)
return _underlying.subSequence(beginIndex, endIndex);
}
+ /**
+ * https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm jump table
+ */
+ private static int[] createJumpTable(byte[] needle) {
+ final int[] jumpTable = new int[needle.length + 1];
+ int j = 0;
+ for (int i = 1; i < needle.length; i++) {
+ while (j > 0 && needle[j] != needle[i]) {
+ j = jumpTable[j];
+ }
+ if (needle[j] == needle[i]) {
+ j++;
+ }
+ jumpTable[i + 1] = j;
+ }
+ for (int i = 1; i < jumpTable.length; i++) {
+ if (jumpTable[i] != 0) {
+ return jumpTable;
+ }
+ }
+ // optimization over the original algorithm: it would save from accessing any jump table
+ return null;
+ }
+
+ private int[] racyGerOrCreateJumpTable() {
+ int[] jumpTable = this._jumpTable;
+ if (jumpTable == NOT_INITIALIZED_JUMP_TABLE) {
+ jumpTable = createJumpTable(this._underlyingBytes);
+ _jumpTable = jumpTable;
+ }
+ return jumpTable;
+ }
+
+ /**
+ * Returns the index on buffer of the first encoded occurrence of this {@code symbol} within the specified range.<br>
+ * If none is found, then {@code -1} is returned.
+ *
+ * @param buffer the buffer where to search in
+ * @return the index of the first occurrence of this symbol or {@code -1} if it won't occur.
+ * <p>
+ * @throws IllegalArgumentException if any of the indexes of the specified range is negative
+ */
+ public int searchFirst(ReadableBuffer buffer, int from, int to)
+ {
+ Objects.requireNonNull(buffer, "buffer cannot be null");
+ if (from < 0 || to < 0)
+ {
+ throw new IllegalArgumentException("range indexes cannot be negative!");
+ }
+ int j = 0;
+ final int[] jumpTable = racyGerOrCreateJumpTable();
+ final byte[] needle = _underlyingBytes;
+ final long length = to - from;
Review comment:
Given the other checking above, should it perhaps also validate that to <= from?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org
[GitHub] [qpid-proton-j] franz1981 edited a comment on issue #36:
PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
Posted by GitBox <gi...@apache.org>.
franz1981 edited a comment on issue #36: PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
URL: https://github.com/apache/qpid-proton-j/pull/36#issuecomment-584239155
Some benchmark results are on https://github.com/netty/netty/pull/9955
I've yet to decide if it makes sense to provide our own benchmarks, given that the reason of this "feature" is for some specific use cases (see https://github.com/apache/activemq-artemis/pull/2975).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org
[GitHub] [qpid-proton-j] franz1981 closed pull request #36: PROTON-2178
Implement efficient search of encoded Symbol on ReadableBuffer
Posted by GitBox <gi...@apache.org>.
franz1981 closed pull request #36: PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
URL: https://github.com/apache/qpid-proton-j/pull/36
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org
[GitHub] [qpid-proton-j] gemmellr commented on a change in pull request #36:
PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
Posted by GitBox <gi...@apache.org>.
gemmellr commented on a change in pull request #36: PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
URL: https://github.com/apache/qpid-proton-j/pull/36#discussion_r399378171
##########
File path: proton-j/src/main/java/org/apache/qpid/proton/amqp/Symbol.java
##########
@@ -60,6 +66,82 @@ public CharSequence subSequence(int beginIndex, int endIndex)
return _underlying.subSequence(beginIndex, endIndex);
}
+ /**
+ * https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm jump table
+ */
+ private static int[] createJumpTable(byte[] needle) {
+ final int[] jumpTable = new int[needle.length + 1];
+ int j = 0;
+ for (int i = 1; i < needle.length; i++) {
+ while (j > 0 && needle[j] != needle[i]) {
+ j = jumpTable[j];
+ }
+ if (needle[j] == needle[i]) {
+ j++;
+ }
+ jumpTable[i + 1] = j;
+ }
+ for (int i = 1; i < jumpTable.length; i++) {
+ if (jumpTable[i] != 0) {
+ return jumpTable;
+ }
+ }
+ // optimization over the original algorithm: it would save from accessing any jump table
+ return null;
+ }
+
+ private int[] racyGerOrCreateJumpTable() {
+ int[] jumpTable = this._jumpTable;
+ if (jumpTable == NOT_INITIALIZED_JUMP_TABLE) {
+ jumpTable = createJumpTable(this._underlyingBytes);
+ _jumpTable = jumpTable;
+ }
+ return jumpTable;
+ }
+
+ /**
+ * Returns the index on buffer of the first encoded occurrence of this {@code symbol} within the specified range.<br>
+ * If none is found, then {@code -1} is returned.
+ *
+ * @param buffer the buffer where to search in
+ * @return the index of the first occurrence of this symbol or {@code -1} if it won't occur.
+ * <p>
+ * @throws IllegalArgumentException if any of the indexes of the specified range is negative
+ */
+ public int searchFirst(ReadableBuffer buffer, int from, int to)
+ {
+ Objects.requireNonNull(buffer, "buffer cannot be null");
+ if (from < 0 || to < 0)
+ {
+ throw new IllegalArgumentException("range indexes cannot be negative!");
+ }
+ int j = 0;
+ final int[] jumpTable = racyGerOrCreateJumpTable();
+ final byte[] needle = _underlyingBytes;
+ final long length = to - from;
+ final ReadableBuffer haystack = buffer;
Review comment:
Any reason not to just declare the method arg with the desired name + final?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org
[GitHub] [qpid-proton-j] gemmellr commented on a change in pull request #36:
PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
Posted by GitBox <gi...@apache.org>.
gemmellr commented on a change in pull request #36: PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
URL: https://github.com/apache/qpid-proton-j/pull/36#discussion_r379357759
##########
File path: proton-j/src/main/java/org/apache/qpid/proton/amqp/Symbol.java
##########
@@ -60,6 +66,82 @@ public CharSequence subSequence(int beginIndex, int endIndex)
return _underlying.subSequence(beginIndex, endIndex);
}
+ /**
+ * https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm jump table
+ */
+ private static int[] createJumpTable(byte[] needle) {
+ final int[] jumpTable = new int[needle.length + 1];
+ int j = 0;
+ for (int i = 1; i < needle.length; i++) {
+ while (j > 0 && needle[j] != needle[i]) {
+ j = jumpTable[j];
+ }
+ if (needle[j] == needle[i]) {
+ j++;
+ }
+ jumpTable[i + 1] = j;
+ }
+ for (int i = 1; i < jumpTable.length; i++) {
+ if (jumpTable[i] != 0) {
+ return jumpTable;
+ }
+ }
+ // optimization over the original algorithm: it would save from accessing any jump table
+ return null;
+ }
+
+ private int[] racyGerOrCreateJumpTable() {
+ int[] jumpTable = this._jumpTable;
+ if (jumpTable == NOT_INITIALIZED_JUMP_TABLE) {
+ jumpTable = createJumpTable(this._underlyingBytes);
+ _jumpTable = jumpTable;
+ }
+ return jumpTable;
+ }
+
+ /**
+ * Returns the index on buffer of the first encoded occurrence of this {@code symbol} within the specified range.<br>
+ * If none is found, then {@code -1} is returned.
+ *
+ * @param buffer the buffer where to search in
+ * @return the index of the first occurrence of this symbol or {@code -1} if it won't occur.
+ * <p>
+ * @throws IllegalArgumentException if any of the indexes of the specified range is negative
+ */
+ public int searchFirst(ReadableBuffer buffer, int from, int to)
+ {
+ Objects.requireNonNull(buffer, "buffer cannot be null");
+ if (from < 0 || to < 0)
+ {
+ throw new IllegalArgumentException("range indexes cannot be negative!");
+ }
+ int j = 0;
+ final int[] jumpTable = racyGerOrCreateJumpTable();
Review comment:
Not sure what Ger is ;)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org
[GitHub] [qpid-proton-j] gemmellr commented on a change in pull request #36:
PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
Posted by GitBox <gi...@apache.org>.
gemmellr commented on a change in pull request #36: PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
URL: https://github.com/apache/qpid-proton-j/pull/36#discussion_r399379661
##########
File path: proton-j/src/main/java/org/apache/qpid/proton/amqp/Symbol.java
##########
@@ -60,6 +66,82 @@ public CharSequence subSequence(int beginIndex, int endIndex)
return _underlying.subSequence(beginIndex, endIndex);
}
+ /**
+ * https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm jump table
+ */
+ private static int[] createJumpTable(byte[] needle) {
+ final int[] jumpTable = new int[needle.length + 1];
+ int j = 0;
+ for (int i = 1; i < needle.length; i++) {
+ while (j > 0 && needle[j] != needle[i]) {
+ j = jumpTable[j];
+ }
+ if (needle[j] == needle[i]) {
+ j++;
+ }
+ jumpTable[i + 1] = j;
+ }
+ for (int i = 1; i < jumpTable.length; i++) {
+ if (jumpTable[i] != 0) {
+ return jumpTable;
+ }
+ }
+ // optimization over the original algorithm: it would save from accessing any jump table
+ return null;
+ }
+
+ private int[] racyGerOrCreateJumpTable() {
+ int[] jumpTable = this._jumpTable;
+ if (jumpTable == NOT_INITIALIZED_JUMP_TABLE) {
+ jumpTable = createJumpTable(this._underlyingBytes);
+ _jumpTable = jumpTable;
+ }
+ return jumpTable;
+ }
+
+ /**
+ * Returns the index on buffer of the first encoded occurrence of this {@code symbol} within the specified range.<br>
+ * If none is found, then {@code -1} is returned.
+ *
+ * @param buffer the buffer where to search in
+ * @return the index of the first occurrence of this symbol or {@code -1} if it won't occur.
+ * <p>
+ * @throws IllegalArgumentException if any of the indexes of the specified range is negative
+ */
+ public int searchFirst(ReadableBuffer buffer, int from, int to)
+ {
+ Objects.requireNonNull(buffer, "buffer cannot be null");
+ if (from < 0 || to < 0)
+ {
+ throw new IllegalArgumentException("range indexes cannot be negative!");
+ }
+ int j = 0;
+ final int[] jumpTable = racyGerOrCreateJumpTable();
+ final byte[] needle = _underlyingBytes;
+ final long length = to - from;
+ final ReadableBuffer haystack = buffer;
+ final int needleLength = needle.length;
+ for (int i = 0; i < length; i++)
Review comment:
Would initialising i to 'from' rather than 0 simplify things? (Plus other adjustments accordingly, e.g rename i to index, to rather than length)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org
[GitHub] [qpid-proton-j] franz1981 edited a comment on issue #36:
PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
Posted by GitBox <gi...@apache.org>.
franz1981 edited a comment on issue #36: PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
URL: https://github.com/apache/qpid-proton-j/pull/36#issuecomment-584239155
Some benchmark results are on https://github.com/netty/netty/pull/9955
I've yet to decide if it makes sense to provide our own benchmarks, given that the reason of this "feature" is for some specific use cases.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org
[GitHub] [qpid-proton-j] franz1981 commented on issue #36: PROTON-2178
Implement efficient search of encoded Symbol on ReadableBuffer
Posted by GitBox <gi...@apache.org>.
franz1981 commented on issue #36: PROTON-2178 Implement efficient search of encoded Symbol on ReadableBuffer
URL: https://github.com/apache/qpid-proton-j/pull/36#issuecomment-584239155
Some benchmark results are on https://github.com/netty/netty/pull/9955
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org