Skip to content

Commit 97468f3

Browse files
committed
Simplify message size doubling logic
1 parent 05cf60b commit 97468f3

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/ndt7-upload-worker.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ const uploadTest = function(sock, postMessage, now) {
5757
* is used as a speed test, we don't know before the test which strategy we
5858
* will be using, because we don't know the speed before we test it.
5959
* Therefore, we use a strategy where we grow the message exponentially over
60-
* time and maintain the invariant that the message size is always either 8k
61-
* or less than 1/8 of the total number of bytes we have enqueued. In an
62-
* effort to be kind to the memory allocator, we always double the message
63-
* size instead of growing it by e.g. 1.3x.
60+
* time. In an effort to be kind to the memory allocator, we always double
61+
* the message size instead of growing it by e.g. 1.3x.
6462
*
6563
* @param {*} data
6664
* @param {*} start
@@ -83,9 +81,11 @@ const uploadTest = function(sock, postMessage, now) {
8381
const maxMessageSize = 8388608; /* = (1<<23) = 8MB */
8482
const clientMeasurementInterval = 250; // ms
8583

86-
// Message size is doubled every 16 messages, up to maxMessageSize.
87-
if (data.length < maxMessageSize &&
88-
data.length < (total - sock.bufferedAmount) / 16) {
84+
// Message size is doubled after the first 16 messages, and subsequently
85+
// every 8, up to maxMessageSize.
86+
const nextSizeIncrement =
87+
(data.length >= maxMessageSize) ? Infinity : 16 * data.length;
88+
if ((total - sock.bufferedAmount) >= nextSizeIncrement) {
8989
data = new Uint8Array(data.length * 2);
9090
}
9191

src/ndt7-upload-worker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)