]> git.ardis.lu - csvio/commitdiff
Increase `highWaterMark` for `CSVWriter`'s queuing strategy
authorArdis Lu <ardisglu@gmail.com>
Fri, 4 Jul 2025 05:02:25 +0000 (22:02 -0700)
committerArdis Lu <ardisglu@gmail.com>
Fri, 4 Jul 2025 05:02:25 +0000 (22:02 -0700)
This change improves the 100MB Write benchmark from ~9s to ~7s.

Bumping `highWaterMark` to >1 also changes the stream's interaction with `AbortController`, so now the chunk processed during an abort is included in the write.

I believe this behavior has to do with the task queue order of the callback for the `AbortSignal`'s `abort` event - so now with multiple chunks in the queue, the last chunk is written before the `abort` event is processed. I was unable to force this writing code to occur after the `abort` event in a deterministic way.

This situation is a rare edge case so letting it through.

examples/data/ex1_7-out.csv
examples/ex1_7.js
src/core.js

index 0e472ca0a2789e65b9014f21c5318fe73014135d..f14cd79ae9976d5ba25b88956f5b2f09d2320756 100644 (file)
@@ -1,3 +1,4 @@
 Header A\r
 abc\r
 def\r
+abort\r
index dd2a64331e687839ceae378d7e15d6395064eb59..abfadd3ccd97cfb1b4382e49f4b0ea05e39595f6 100644 (file)
@@ -1,8 +1,8 @@
 // ## Example 1.7: Abort a transformation
 // 
 // Pass an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to `.pipeTo()` to gracefully
-// abort a transformation. All transformations enqueued up until the row causing the abort (but *not* including the abort
-// row itself) will be saved to disk.
+// abort a transformation. All transformations enqueued up until the row causing the abort (including the abort row
+// itself) will be saved to disk.
 // 
 // Aborting throws an error, so you must also add a `.catch()` to handle the abort.
 
index c76004fbb88fb8eb8862072025fb1d6d3c9e590f..8bbb274ced5600075644b3cf96bd90dc6d7aadca 100644 (file)
@@ -509,7 +509,7 @@ export class CSVWriter extends WritableStream {
       async abort() {
         await this.close();
       }
-    });
+    }, new CountQueuingStrategy({ highWaterMark: 4 })); // "4" picked based on manual benchmarks
 
     this.#status = status;
   }
This page took 0.036364 seconds and 4 git commands to generate.