From 0f939935cdf1a77eedbd2788138d7d17ce8fa0eb Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 2 Jan 2021 13:26:51 +0000 Subject: [PATCH] Skip flush/read calls if no writes are made Signed-off-by: Graham --- .../org/openrs2/archive/cache/Js5ChannelHandler.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/Js5ChannelHandler.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/Js5ChannelHandler.kt index 767dc4ed98..94cc23bf19 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/Js5ChannelHandler.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/Js5ChannelHandler.kt @@ -57,14 +57,20 @@ public class Js5ChannelHandler( } override fun channelReadComplete(ctx: ChannelHandlerContext) { + var flush = false + while (inFlightRequests.size < maxInFlightRequests) { val request = pendingRequests.removeFirstOrNull() ?: break inFlightRequests += request ctx.write(request, ctx.voidPromise()) + + flush = true } - ctx.flush() - ctx.read() + if (flush) { + ctx.flush() + ctx.read() + } } override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) {