This is an automated email from the ASF dual-hosted git repository.
tabish121 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git
The following commit(s) were added to refs/heads/main by this push:
new f5925415 PROTON-2955 Improve Symbol lookup performance and buffer
updates
f5925415 is described below
commit f592541584f165594edbd52d4d1d5ac2c0e3c4f0
Author: Timothy Bish <[email protected]>
AuthorDate: Wed Aug 12 18:28:01 2026 -0400
PROTON-2955 Improve Symbol lookup performance and buffer updates
Optimize buffer compare when possible to speed up Symbol cache lookups
and other buffer comparison points
---
.../qpid/protonj2/buffer/ProtonBufferUtils.java | 27 ++++++++++++++++++++--
.../qpid/protonj2/resource/SharedResource.java | 16 ++++++++-----
2 files changed, 35 insertions(+), 8 deletions(-)
diff --git
a/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/ProtonBufferUtils.java
b/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/ProtonBufferUtils.java
index f6266762..960d3a1d 100644
---
a/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/ProtonBufferUtils.java
+++
b/protonj2/src/main/java/org/apache/qpid/protonj2/buffer/ProtonBufferUtils.java
@@ -20,6 +20,7 @@ import java.lang.ref.Cleaner;
import java.lang.ref.Cleaner.Cleanable;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
+import java.util.Arrays;
import java.util.Objects;
/**
@@ -749,6 +750,9 @@ public abstract class ProtonBufferUtils {
* @return true if both buffers are equal.
*/
public static boolean equals(ProtonBuffer left, ProtonBuffer right) {
+ Objects.requireNonNull(left, "The left hand buffer cannot be null");
+ Objects.requireNonNull(right, "The right hand buffer cannot be null");
+
if (left == right) {
return true;
}
@@ -759,8 +763,27 @@ public abstract class ProtonBufferUtils {
return false;
}
- return equalsImpl(left, left.getReadOffset(), right,
right.getReadOffset(), length);
- }
+ if (left.componentCount() == 1 && right.componentCount() == 1) {
+ try (ProtonBufferComponentAccessor leftComponentAccess =
left.componentAccessor();
+ ProtonBufferComponentAccessor rightComponentAccess =
right.componentAccessor()) {
+
+ final ProtonBufferComponent leftComponent =
leftComponentAccess.first();
+ final ProtonBufferComponent rightComponent =
rightComponentAccess.first();
+
+ // We opt for fast path array comparison via JDK APIs that can
use vectorization
+ // to speed up the operation vs linear cross buffer read based
comparisons.
+ if (leftComponent.hasReadbleArray() &&
rightComponent.hasReadbleArray()) {
+ final int leftReadOffset =
leftComponent.getReadableArrayOffset();
+ final int rightReadOffset =
rightComponent.getReadableArrayOffset();
+
+ return Arrays.equals(leftComponent.getReadableArray(),
leftReadOffset, leftReadOffset + length,
+ rightComponent.getReadableArray(),
rightReadOffset, rightReadOffset + length);
+ }
+ }
+ }
+
+ return equalsImpl(left, left.getReadOffset(), right,
right.getReadOffset(), length);
+ }
/**
* Compares two {@link ProtonBuffer} instances for equality.
diff --git
a/protonj2/src/main/java/org/apache/qpid/protonj2/resource/SharedResource.java
b/protonj2/src/main/java/org/apache/qpid/protonj2/resource/SharedResource.java
index 52cedef0..241d3db1 100644
---
a/protonj2/src/main/java/org/apache/qpid/protonj2/resource/SharedResource.java
+++
b/protonj2/src/main/java/org/apache/qpid/protonj2/resource/SharedResource.java
@@ -17,6 +17,8 @@
package org.apache.qpid.protonj2.resource;
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
+
/**
* A referenced resource is one in which a number of objects can claim
reference
* and the resource will not close or free claimed resources until all
references
@@ -26,30 +28,32 @@ package org.apache.qpid.protonj2.resource;
*/
public abstract class SharedResource<T extends Resource<T>> implements
Resource<T>, AutoCloseable {
+ @SuppressWarnings("rawtypes")
+ private static final AtomicIntegerFieldUpdater<SharedResource>
COUNT_UPDATER =
+ AtomicIntegerFieldUpdater.newUpdater(SharedResource.class, "count");
+
private static final int CLOSED = -1;
private static final int TRANSFERRED = -2;
- private int count;
+ private volatile int count;
protected final T acquire() {
if (count < 0) {
throw resourceIsClosedException();
}
- count++; // Now shared and must have multiple closes
+ COUNT_UPDATER.incrementAndGet(this); // Now shared and must have
multiple closes
return self();
}
@Override
public final void close() {
- int current = count;
+ int current = COUNT_UPDATER.getAndDecrement(this);
- if (current-- == 0) {
+ if (current == 0) {
count = CLOSED;
releaseResourceOwnership();
- } else if (current >= 0) {
- --count;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]