From dead4b4ab6f0aea37bed5cdb0b9a3b3dcd94698d Mon Sep 17 00:00:00 2001 From: Chris Brody Date: Tue, 9 Jun 2020 19:48:33 -0400 Subject: [PATCH] breaking: reduce combined response cutoff to 16 MB (#987) * breaking: reduce combined response cutoff to 16 MB * rename `MAX_PAYLOAD_SIZE` to `COMBINED_RESPONSE_CUTOFF` * update some comments * cleanup: split `if` statements into multiple lines --- .../cordova/NativeToJsMessageQueue.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java index d17b1c43..311ba444 100755 --- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java +++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java @@ -36,10 +36,11 @@ public class NativeToJsMessageQueue { // exec() is asynchronous. Set this to true when running bridge benchmarks. static final boolean DISABLE_EXEC_CHAINING = false; - // Arbitrarily chosen upper limit for how much data to send to JS in one shot. - // This currently only chops up on message boundaries. It may be useful - // to allow it to break up messages. - private static int MAX_PAYLOAD_SIZE = 50 * 1024 * 10240; + // A hopefully reasonable upper limit of how much combined payload data + // to send to the JavaScript in one shot. + // This currently only chops up on message boundaries. + // It may be useful to split and reassemble response messages someday. + private static int COMBINED_RESPONSE_CUTOFF = 16 * 1024 * 1024; /** * When true, the active listener is not fired upon enqueue. When set to false, @@ -124,7 +125,10 @@ public class NativeToJsMessageQueue { /** * Combines and returns queued messages combined into a single string. - * Combines as many messages as possible, while staying under MAX_PAYLOAD_SIZE. + * + * Combines as many messages as possible, without exceeding + * COMBINED_RESPONSE_CUTOFF in case of multiple response messages. + * * Returns null if the queue is empty. */ public String popAndEncode(boolean fromOnlineEvent) { @@ -140,7 +144,10 @@ public class NativeToJsMessageQueue { int numMessagesToSend = 0; for (JsMessage message : queue) { int messageSize = calculatePackedMessageLength(message); - if (numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE && MAX_PAYLOAD_SIZE > 0) { + if (numMessagesToSend > 0 && + COMBINED_RESPONSE_CUTOFF > 0 && + totalPayloadLen + messageSize > COMBINED_RESPONSE_CUTOFF + ) { break; } totalPayloadLen += messageSize; @@ -175,7 +182,10 @@ public class NativeToJsMessageQueue { int numMessagesToSend = 0; for (JsMessage message : queue) { int messageSize = message.calculateEncodedLength() + 50; // overestimate. - if (numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE && MAX_PAYLOAD_SIZE > 0) { + if (numMessagesToSend > 0 && + COMBINED_RESPONSE_CUTOFF > 0 && + totalPayloadLen + messageSize > COMBINED_RESPONSE_CUTOFF + ) { break; } totalPayloadLen += messageSize;