Skip to content

Commit

Permalink
Don't allocate via the pool if we not really interested in the sequen…
Browse files Browse the repository at this point in the history
…ce (#627)

Motivation:

Let's just allocate the memory on the stack and not use the pool if we
never use the actual value

Modifications:

Just allocate on the stack

Result:

Reduce pool usage if not needed.
  • Loading branch information
normanmaurer authored Nov 28, 2023
1 parent 0b97e81 commit d45c962
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -916,11 +916,9 @@ List<ByteBuffer> newSourceConnectionIds(
boolean sendAndFlush = false;
ByteBuffer key = localIdAdrr.connId.duplicate();
ByteBuf connIdBuffer = alloc().directBuffer(key.remaining());
ByteBuf seqBuffer = alloc().directBuffer(Long.BYTES);

byte[] resetTokenArray = new byte[Quic.RESET_TOKEN_LEN];
try {
long seqAddress = Quiche.memoryAddress(seqBuffer, 0, seqBuffer.capacity());
do {
ByteBuffer srcId = connectionIdGenerator.newId(key, key.remaining());
connIdBuffer.clear();
Expand All @@ -929,7 +927,7 @@ List<ByteBuffer> newSourceConnectionIds(
resetToken.get(resetTokenArray);
long result = Quiche.quiche_conn_new_scid(
connAddr, Quiche.memoryAddress(connIdBuffer, 0, connIdBuffer.readableBytes()),
connIdBuffer.readableBytes(), resetTokenArray, false, seqAddress);
connIdBuffer.readableBytes(), resetTokenArray, false, -1);
if (result < 0) {
break;
}
Expand All @@ -939,7 +937,6 @@ List<ByteBuffer> newSourceConnectionIds(
} while (--left > 0);
} finally {
connIdBuffer.release();
seqBuffer.release();
}

if (sendAndFlush) {
Expand Down
12 changes: 10 additions & 2 deletions codec-native-quic/src/main/c/netty_quic_quiche.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,17 @@ static jint netty_quiche_conn_scids_left(JNIEnv* env, jclass clazz, jlong conn)
return (jint) quiche_conn_scids_left((quiche_conn *) conn);
}

static jlong netty_quiche_conn_new_scid(JNIEnv* env, jclass clazz, jlong conn, jlong scid, jint scid_len, jbyteArray reset_token, jboolean retire_if_needed, jlong seq) {
static jlong netty_quiche_conn_new_scid(JNIEnv* env, jclass clazz, jlong conn, jlong scid, jint scid_len, jbyteArray reset_token, jboolean retire_if_needed, jlong sequenceAddr) {
uint8_t* buf = (uint8_t*) (*env)->GetByteArrayElements(env, reset_token, 0);
jlong ret = quiche_conn_new_scid((quiche_conn *) conn, (const uint8_t *) scid, scid_len, buf, retire_if_needed == JNI_TRUE ? true : false, (uint64_t*) seq);

uint64_t* seq;
if (sequenceAddr < 0) {
uint64_t tmp;
seq = &tmp;
} else {
seq = (uint64_t *) sequenceAddr;
}
jlong ret = quiche_conn_new_scid((quiche_conn *) conn, (const uint8_t *) scid, scid_len, buf, retire_if_needed == JNI_TRUE ? true : false, seq);
(*env)->ReleaseByteArrayElements(env, reset_token, (jbyte*)buf, JNI_ABORT);
return ret;
}
Expand Down

0 comments on commit d45c962

Please sign in to comment.