1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-27 16:10:57 -05:00
denoland-deno/ext/web
Marcos Casagrande 7599990a4f
perf(ext/streams): optimize streams (#20649)
This PR introduces several optimizations to streams

### Highlights:
- `ReadableStream` constructor: +20% iter/s.
- `WritableStream` constructor: +50% iter/s.
- `TransformStream` constructor: +30% iter/s.
- `ReadableStream` iterator (both 2 and 20 chunks): +42% and +25%
iter/s.
- `ReadableByteStream` iterator (both 2 and 20 chunks): +39% and +20%
iter/s.

### Benchmarks
**main**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.37.0 (x86_64-unknown-linux-gnu)

benchmark                                      time (avg)        iter/s             (min … max)       p75       p99      p995
----------------------------------------------------------------------------------------------- -----------------------------
ReadableStream constructor                    294.52 ns/iter   3,395,392.9 (277.92 ns … 618.26 ns) 292.66 ns 353.87 ns 618.26 ns
WritableStream constructor                    235.51 ns/iter   4,246,065.3 (213.04 ns … 306.35 ns) 236.77 ns 279.08 ns 281.32 ns
TransformStream constructor                   672.52 ns/iter   1,486,938.7 (652.15 ns … 880.74 ns) 670.11 ns 880.74 ns 880.74 ns
ReadableStream - iterator (2 chunks)           10.44 µs/iter      95,757.9   (8.97 µs … 830.91 µs)  10.22 µs  14.74 µs  18.93 µs
ReadableStream - iterator (20 chunks)          21.93 µs/iter      45,593.4   (18.8 µs … 864.97 µs)  20.57 µs  57.15 µs 137.16 µs
ReadableStream - reader (2 chunks)              7.09 µs/iter     140,987.2     (7.03 µs … 7.18 µs)   7.13 µs   7.18 µs   7.18 µs
ReadableStream - reader (20 chunks)            18.41 µs/iter      54,324.2    (15.7 µs … 252.7 µs)  17.14 µs  68.88 µs  94.08 µs
ReadableByteStream - iterator (2 chunks)       11.06 µs/iter      90,375.1   (9.75 µs … 404.69 µs)  10.88 µs   16.6 µs  29.69 µs
ReadableByteStream - iterator (20 chunks)      26.71 µs/iter      37,435.0  (22.98 µs … 508.34 µs)  25.25 µs  85.28 µs 155.65 µs
ReadableByteStream - reader (2 chunks)          7.99 µs/iter     125,131.1     (7.92 µs … 8.13 µs)   8.01 µs   8.13 µs   8.13 µs
ReadableByteStream - reader (20 chunks)        23.46 µs/iter      42,618.5  (20.28 µs … 414.66 µs)  21.94 µs  90.52 µs 147.38 µs
```

**this PR**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.37.0 (x86_64-unknown-linux-gnu)

benchmark                                      time (avg)        iter/s             (min … max)       p75       p99      p995
----------------------------------------------------------------------------------------------- -----------------------------
ReadableStream constructor                    235.48 ns/iter   4,246,584.3 (223.12 ns … 504.65 ns)  234.3 ns 290.84 ns 311.12 ns
WritableStream constructor                    156.31 ns/iter   6,397,537.3 (148.54 ns … 211.13 ns) 157.49 ns 199.82 ns 208.23 ns
TransformStream constructor                   471.29 ns/iter   2,121,815.3 (452.53 ns … 791.41 ns) 468.62 ns 540.36 ns 791.41 ns
ReadableStream - iterator (2 chunks)            7.32 µs/iter     136,705.4   (6.35 µs … 639.97 µs)    7.1 µs  12.12 µs  20.98 µs
ReadableStream - iterator (20 chunks)          17.48 µs/iter      57,195.1  (14.48 µs … 289.06 µs)  16.06 µs  76.98 µs 114.61 µs
ReadableStream - reader (2 chunks)              6.86 µs/iter     145,847.9      (6.8 µs … 6.97 µs)   6.88 µs   6.97 µs   6.97 µs
ReadableStream - reader (20 chunks)            16.88 µs/iter      59,227.7  (14.04 µs … 311.29 µs)  15.39 µs  74.95 µs  97.45 µs
ReadableByteStream - iterator (2 chunks)        7.94 µs/iter     125,881.2   (6.86 µs … 811.16 µs)   7.69 µs  11.43 µs   16.6 µs
ReadableByteStream - iterator (20 chunks)      22.23 µs/iter      44,978.2  (18.98 µs … 590.11 µs)  20.73 µs  45.13 µs  159.8 µs
ReadableByteStream - reader (2 chunks)           7.4 µs/iter     135,206.9     (7.36 µs … 7.42 µs)    7.4 µs   7.42 µs   7.42 µs
ReadableByteStream - reader (20 chunks)        21.03 µs/iter      47,555.6  (17.75 µs … 357.66 µs)  19.52 µs  98.69 µs  146.5 µs
```

---------

Co-authored-by: Luca Casonato <hello@lcas.dev>
2023-10-13 14:30:09 +02:00
..
benches refactor: remove TimersPermissions::check_unstable (#20831) 2023-10-09 02:08:10 +02:00
00_infra.js fix(core): Use safe primordials wrappers (#18687) 2023-04-14 22:23:28 +02:00
01_dom_exception.js fix(ext/web): writability of ReadableStream.from (#20836) 2023-10-10 05:01:01 +02:00
01_mimesniff.js perf: optimize RegExp usage in JS (#19364) 2023-06-05 10:52:40 +02:00
02_event.js fix(ext/web): writability of ReadableStream.from (#20836) 2023-10-10 05:01:01 +02:00
02_structured_clone.js fix(core): Use safe primordials wrappers (#18687) 2023-04-14 22:23:28 +02:00
02_timers.js feat: support import attributes (#20342) 2023-09-07 09:09:16 -04:00
03_abort_signal.js fix(ext/web): writability of ReadableStream.from (#20836) 2023-10-10 05:01:01 +02:00
04_global_interfaces.js refactor: rename InternalModuleLoader to ExtModuleLoader, use ext: scheme for snapshotted modules (#18041) 2023-03-08 12:44:54 +01:00
05_base64.js refactor(webidl): move prefix & context out of converters options bag (#18931) 2023-05-01 10:47:13 +00:00
06_streams.js perf(ext/streams): optimize streams (#20649) 2023-10-13 14:30:09 +02:00
06_streams_types.d.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
08_text_encoding.js fix(ext/web): writability of ReadableStream.from (#20836) 2023-10-10 05:01:01 +02:00
09_file.js fix(ext/web): writability of ReadableStream.from (#20836) 2023-10-10 05:01:01 +02:00
10_filereader.js fix(ext/web): writability of ReadableStream.from (#20836) 2023-10-10 05:01:01 +02:00
12_location.js chore: fix typos (#19572) 2023-06-26 09:10:27 -04:00
13_message_port.js fix(ext/web): writability of ReadableStream.from (#20836) 2023-10-10 05:01:01 +02:00
14_compression.js fix(ext/web): writability of ReadableStream.from (#20836) 2023-10-10 05:01:01 +02:00
15_performance.js fix(ext/web): writability of ReadableStream.from (#20836) 2023-10-10 05:01:01 +02:00
blob.rs refactor: rewrite several extension ops to op2 (#20457) 2023-10-05 14:34:38 +02:00
Cargo.toml chore: forward v1.37.2 release commit to main (#20897) 2023-10-13 03:12:06 +00:00
compression.rs refactor: rewrite several extension ops to op2 (#20457) 2023-10-05 14:34:38 +02:00
hr_timer_lock.rs chore: update to Rust 1.71 (#19822) 2023-07-13 15:16:24 -06:00
internal.d.ts perf(ext/node): Optimise Buffer string operations (#20158) 2023-09-07 14:41:16 -06:00
lib.deno_web.d.ts feat(ext/web): cancel support for TransformStream (#20815) 2023-10-10 18:42:31 +09:00
lib.rs refactor: rewrite several extension ops to op2 (#20457) 2023-10-05 14:34:38 +02:00
message_port.rs refactor: rewrite more ops to op2 macro (#20478) 2023-09-14 23:05:18 +02:00
README.md Rename extensions/ directory to ext/ (#11643) 2021-08-11 12:27:05 +02:00
stream_resource.rs fix(ext/http): ensure that resources are closed when request is cancelled (#20641) 2023-09-25 17:23:55 +02:00
timers.rs refactor: remove TimersPermissions::check_unstable (#20831) 2023-10-09 02:08:10 +02:00

deno web

Op crate that implements Event, TextEncoder, TextDecoder and File API (https://w3c.github.io/FileAPI).

Testing for text encoding is done via WPT in cli/.