diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2022-11-15 14:06:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-15 14:06:52 +0100 |
commit | 0832ba1deb9eb43c0a724112eed3f2d7d9a0819b (patch) | |
tree | 8dd6b7bc5968635c88d92830d0b8e46adf7f7dcf /runtime/js/40_spawn.js | |
parent | f2bf40d157879cf05a9334d9a4676562bdf1b1c1 (diff) |
perf(runtime/spawn): collect output using `op_read_all` (#16596)
**This patch**
```
benchmark time (avg) (min … max) p75 p99 p995
------------------------------------------------- -----------------------------
echo deno 23.99 ms/iter (22.51 ms … 33.61 ms) 23.97 ms 33.61 ms 33.61 ms
cat 16kb 24.27 ms/iter (22.5 ms … 35.21 ms) 24.2 ms 35.21 ms 35.21 ms
cat 1mb 25.88 ms/iter (25.04 ms … 30.28 ms) 26.12 ms 30.28 ms 30.28 ms
cat 15mb 38.41 ms/iter (35.7 ms … 50 ms) 38.31 ms 50 ms 50 ms
```
**main**
```
benchmark time (avg) (min … max) p75 p99 p995
------------------------------------------------- -----------------------------
echo deno 35.66 ms/iter (34.53 ms … 41.84 ms) 35.79 ms 41.84 ms 41.84 ms
cat 16kb 35.99 ms/iter (34.52 ms … 44.94 ms) 36.05 ms 44.94 ms 44.94 ms
cat 1mb 38.68 ms/iter (36.67 ms … 50.44 ms) 37.95 ms 50.44 ms 50.44 ms
cat 15mb 48.4 ms/iter (46.19 ms … 58.41 ms) 49.16 ms 58.41 ms 58.41 ms
```
Diffstat (limited to 'runtime/js/40_spawn.js')
-rw-r--r-- | runtime/js/40_spawn.js | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/runtime/js/40_spawn.js b/runtime/js/40_spawn.js index e262a1325..8f44c8929 100644 --- a/runtime/js/40_spawn.js +++ b/runtime/js/40_spawn.js @@ -12,12 +12,12 @@ ObjectEntries, String, TypeError, - Uint8Array, PromisePrototypeThen, SafePromiseAll, SymbolFor, } = window.__bootstrap.primordials; const { + readableStreamCollectIntoUint8Array, readableStreamForRidUnrefable, readableStreamForRidUnrefableRef, readableStreamForRidUnrefableUnref, @@ -64,26 +64,12 @@ }; } - async function collectOutput(readableStream) { + function collectOutput(readableStream) { if (!(readableStream instanceof ReadableStream)) { return null; } - const bufs = []; - let size = 0; - for await (const chunk of readableStream) { - bufs.push(chunk); - size += chunk.byteLength; - } - - const buffer = new Uint8Array(size); - let offset = 0; - for (const chunk of bufs) { - buffer.set(chunk, offset); - offset += chunk.byteLength; - } - - return buffer; + return readableStreamCollectIntoUint8Array(readableStream); } class Child { |