@@ -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
0 commit comments