1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00
Commit graph

406 commits

Author SHA1 Message Date
Bartek Iwańczuk
288774c5ed
chore: forward v1.39.3 to main (#21915)
Co-authored-by: denobot <33910674+denobot@users.noreply.github.com>
Co-authored-by: bartlomieju <bartlomieju@users.noreply.github.com>
2024-01-12 19:13:18 +00:00
Kenta Moriuchi
515a34b4de
refactor: use core.ensureFastOps() (#21888) 2024-01-10 15:37:25 -07:00
Bartek Iwańczuk
cd43d2b877
chore: upgrade deno_core to 0.244.0 (#21859) 2024-01-09 17:25:10 +01:00
Bartek Iwańczuk
aadcd64065
chore: forward v1.39.2 release commit to main (#21793) 2024-01-04 23:52:17 +00:00
Kenta Moriuchi
b2cd254c35
fix: strict type check for cross realms (#21669)
Deno v1.39 introduces `vm.runInNewContext`. This may cause problems when
using `Object.prototype.isPrototypeOf` to check built-in types.

```js
import vm from "node:vm";

const err = new Error();
const crossErr = vm.runInNewContext(`new Error()`);

console.assert( !(crossErr instanceof Error) );
console.assert( Object.getPrototypeOf(err) !== Object.getPrototypeOf(crossErr) );
```

This PR changes to check using internal slots solves them.

---

current: 

```
> import vm from "node:vm";
undefined
> vm.runInNewContext(`new Error("message")`)
Error {}
> vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`)
Date {}
```

this PR:

```
> import vm from "node:vm";
undefined
> vm.runInNewContext(`new Error("message")`)
Error: message
    at <anonymous>:1:1
> vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`)
2018-12-10T02:26:59.002Z
```

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-01-04 09:42:38 +05:30
David Sherret
7e72f3af61
chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00
Matt Mastracci
0efe438f7c
perf: remove opAsync (#21690)
`opAsync` requires a lookup by name on each async call. This is a
mechanical translation of all opAsync calls to ensureFastOps.

The `opAsync` API on Deno.core will be removed at a later time.
2023-12-27 02:30:26 +01:00
Matt Mastracci
92b2e28c64
chore: ensure that each op provided to ensureFastOps is only used once (#21689)
When we migrate to op-import-per-extension, we will want to ensure that
ops have one and only one place where they are imported. This tackles
the ops that are imported via `ensureFastOps`, but does not yet tackle
direct `ops` imports.

Landing ahead of https://github.com/denoland/deno_core/pull/393
2023-12-24 13:04:32 +00:00
Bartek Iwańczuk
760af934d9
chore: forward v1.39.1 commit to main (#21667) (#21671)
Co-authored-by: denobot <33910674+denobot@users.noreply.github.com>
Co-authored-by: bartlomieju <bartlomieju@users.noreply.github.com>
2023-12-21 18:43:52 +00:00
denobot
04ba8df711
1.39.0 (#21560)
Bumped versions for 1.39.0

Please ensure:
- [x] Target branch is correct (`vX.XX` if a patch release, `main` if
minor)
- [x] Crate versions are bumped correctly
- [x] deno_std version is incremented in the code (see
`cli/deno_std.rs`)
- [x] Releases.md is updated correctly (think relevancy and remove
reverts)

To make edits to this PR:
```shell
git fetch upstream release_1_39.0 && git checkout -b release_1_39.0 upstream/release_1_39.0
```

cc @mmastrac

---------

Co-authored-by: mmastrac <mmastrac@users.noreply.github.com>
Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-12-13 13:24:13 -07:00
Bartek Iwańczuk
c1fc7b2cd5
refactor: pull 'core', 'internals', 'primordials' from ES module (#21462)
This commit refactors how we access "core", "internals" and
"primordials" objects coming from `deno_core`, in our internal JavaScript code.

Instead of capturing them from "globalThis.__bootstrap" namespace, we
import them from recently added "ext:core/mod.js" file.
2023-12-07 14:21:01 +01:00
Matt Mastracci
9314928990
chore: bump deno_core and update tests (#21467)
Landing changes required for
https://github.com/denoland/deno_core/pull/359

We needed to update 99_main.js and a whole load of tests.

API changes:

- setPromiseRejectCallback becomes setUnhandledPromiseRejectionHandler.
The function is now called from eventLoopTick.
- The promiseRejectMacrotaskCallback no longer exists, as this is
automatically handled in eventLoopTick.
- ops.op_dispatch_exception now takes a second parameter: in_promise.
The preferred way to call this op is now reportUnhandledException or
reportUnhandledPromiseRejection.
2023-12-06 17:02:52 -07:00
Jamie
8c0fb9003d
feat(ext/web): add ImageData Web API (#21183)
Fixes #19288

Adds the `ImageData` Web API. 

This would be beneficial to projects using `ImageData` as a convenient
transport layer for pixel data. This is common in Web Assembly projects
that manipulate images. Having this global available in Deno would
improve compatibility of existing JS libraries.

**References**
- [MDN ImageData Web
API](https://developer.mozilla.org/en-US/docs/Web/API/ImageData)
- [whatwg HTML Standard Canvas
Spec](https://html.spec.whatwg.org/multipage/canvas.html#pixel-manipulation)
2023-12-06 14:20:28 +01:00
Bartek Iwańczuk
bd7a6bb016
chore: forward v1.38.5 release commit to main (#21472)
Co-authored-by: denobot <33910674+denobot@users.noreply.github.com>
2023-12-06 00:53:16 +00:00
Matt Mastracci
e6e708e46c
refactor: use resourceForReadableStream for fetch (#20217)
Switch `ext/fetch` over to `resourceForReadableStream` to simplify and
unify implementation with `ext/serve`. This allows us to work in Rust
with resources only.

Two additional changes made to `resourceForReadableStream` were
required:

- Add an optional length to `resourceForReadableStream` which translates
to `size_hint`
 - Fix a bug where writing to a closed stream that was full would panic
2023-12-01 08:56:10 -07:00
Bartek Iwańczuk
b69001bb49
chore: forward v1.38.4 release commit to main (#21400)
Co-authored-by: denobot <33910674+denobot@users.noreply.github.com>
2023-11-30 23:06:54 +01:00
Laurence Rowe
8050cbf39e
perf(ext/web): Avoid changing prototype by setting hostObjectBrand directly (#21358) 2023-11-30 14:06:16 -07:00
Leo Kettmeir
6f02fa1abf
feat(streams): ReadableStream.read min option (#20849) 2023-11-24 23:24:41 +01:00
denobot
2941dd7da8
chore: forward v1.38.3 release commit to main (#21320) 2023-11-24 07:09:15 +01:00
Kenta Moriuchi
c806fbdabe
fix(ext,runtime): add missing custom inspections (#21219) 2023-11-19 09:13:38 +01:00
denobot
21e6a76519
chore: forward v1.38.2 release commit to main (#21236)
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
2023-11-17 17:57:25 +09:00
Kenta Moriuchi
39223f709b
feat(ext/web): add AbortSignal.any() (#21087)
Fixes #18944
2023-11-13 01:04:11 +01:00
Florian Schwalm
3a7abe6906
fix(ext/web): Prevent TextDecoderStream resource leak on stream cancellation (#21074)
This PR uses the new `cancel` method of `TransformStream` to properly
clean up the internal `TextDecoder` used in `TextDecoderStream` if the
stream is cancelled.

Fixes #13142

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-11-12 12:47:03 -07:00
denobot
1ece7dfd90
chore: forward v1.38.1 release commit to main (#21144)
This is the release commit being forwarded back to main for 1.38.1

Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Co-authored-by: littledivy <littledivy@users.noreply.github.com>
2023-11-10 18:51:34 +05:30
Matt Mastracci
9010b8df53
perf: remove knowledge of promise IDs from deno (#21132)
We can move all promise ID knowledge to deno_core, allowing us to better
experiment with promise implementation in deno_core.

`{un,}refOpPromise(promise)` is equivalent to
`{un,}refOp(promise[promiseIdSymbol])`
2023-11-09 13:57:26 -07:00
Matt Mastracci
f8d1d84c5a
chore(ext/web): migrate to deno_core typed externals (#21114)
Use our safer typed externals for the external required for resource
streams.
2023-11-08 20:46:13 +01:00
denobot
41877a0b37
1.38.0 (#21051)
Co-authored-by: bartlomieju <bartlomieju@users.noreply.github.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-11-02 01:01:47 +00:00
Luca Casonato
d42f154312
feat: disposable Deno resources (#20845)
This commit implements Symbol.dispose and Symbol.asyncDispose for
the relevant resources.

Closes #20839

---------

Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-11-01 20:26:12 +01:00
Bartek Iwańczuk
96ce9cdb17
refactor: op_sleep uses op2 macro (#20908)
Signed-off-by: Matt Mastracci <matthew@mastracci.com>
Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-10-26 14:16:41 -06:00
Bartek Iwańczuk
093b3eee58
chore: update deno_core and port all remaining ops to op2 (#20954)
Signed-off-by: Matt Mastracci <matthew@mastracci.com>
Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-10-25 13:43:38 +02:00
Jérôme Benoit
9df36b33c6
docs(event): fixlets to code comments (#20944) 2023-10-23 14:34:37 +02:00
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
denobot
5da1bd802c
chore: forward v1.37.2 release commit to main (#20897)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-10-13 03:12:06 +00:00
Luca Casonato
6450334f5b
feat(ext/web): cancel support for TransformStream (#20815) 2023-10-10 18:42:31 +09:00
Luca Casonato
2665ca103e
fix(ext/web): writability of ReadableStream.from (#20836)
Fixes a WPT in `URL` and `ReadableStream`.

Some unrelated WPT expectation changes due to WPT update.
2023-10-10 05:01:01 +02:00
Bartek Iwańczuk
2167a52d69
refactor: remove TimersPermissions::check_unstable (#20831)
This is dead code that was not used in any way.

Ref https://github.com/denoland/deno/pull/20797
2023-10-09 02:08:10 +02:00
Marcos Casagrande
ceecd8c495
perf(ext/web): optimize structuredClone without transferables (#20730)
This PR optimizes `structuredClone` when it's called without
transferables.

### Benchmarks

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

benchmark                          time (avg)        iter/s             (min … max)       p75       p99      p995
----------------------------------------------------------------------------------- -----------------------------
structuredClone object              1.64 µs/iter     611,086.0     (1.58 µs … 1.84 µs)   1.66 µs   1.84 µs   1.84 µs
structuredClone transferables       2.82 µs/iter     354,281.4     (2.78 µs … 2.92 µs)   2.84 µs   2.92 µs   2.92 µs
```

**this PR**

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

structuredClone object                 1 µs/iter     998,383.5    (971.28 ns … 1.2 µs)      1 µs    1.2 µs    1.2 µs
structuredClone transferables       2.82 µs/iter     355,087.5      (2.7 µs … 3.07 µs)   2.83 µs   3.07 µs   3.07 µs
```

```js
Deno.bench("structuredClone object", () => {
  structuredClone({ foo: "bar" });
});

Deno.bench("structuredClone transferables", () => {
  const buf = new Uint8Array([97]);
  structuredClone(buf, {
    transfer: [buf.buffer],
  });
});
```
2023-10-06 23:21:48 +02:00
Bartek Iwańczuk
5d98a544b4
refactor: rewrite several extension ops to op2 (#20457)
Rewrites following extensions:
- `ext/web`
- `ext/url`
- `ext/webstorage`
- `ext/io`

---------

Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-10-05 14:34:38 +02:00
Marcos Casagrande
de25c81fd0
perf(ext/web): optimize DOMException (#20715)
This PR optimizes `DOMException` constructor increasing performance of
all Web APIs that throw a `DOMException` (ie: `AbortSignal`)

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

new DOMException()            9.66 µs/iter     103,476.8   (8.47 µs … 942.71 µs)   9.62 µs  11.29 µs  14.04 µs
abort writeTextFileSync      16.45 µs/iter      60,775.5    (13.65 µs … 1.33 ms)  16.39 µs  20.59 µs  24.12 µs
abort readFile               16.25 µs/iter      61,542.2  (15.12 µs … 621.14 µs)  16.18 µs  19.59 µs  22.33 µs
```

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

benchmark                    time (avg)        iter/s             (min … max)       p75       p99      p995
----------------------------------------------------------------------------- -----------------------------
new DOMException()            2.37 µs/iter     421,657.0     (2.33 µs … 2.58 µs)   2.37 µs   2.58 µs   2.58 µs
abort writeTextFileSync        7.1 µs/iter     140,760.1     (6.94 µs … 7.68 µs)   7.13 µs   7.68 µs   7.68 µs
abort readFile                5.48 µs/iter     182,648.2      (5.3 µs … 5.69 µs)   5.56 µs   5.69 µs   5.69 µ
```

```js
Deno.bench("new DOMException()", () => {
  new DOMException();
});

Deno.bench("abort writeTextFileSync", () => {
  const ac = new AbortController();
  ac.abort();
  try {
    Deno.writeTextFileSync("/tmp/out", "x", { signal: ac.signal });
  } catch {}
});

Deno.bench("abort readFile", async () => {
  const ac = new AbortController();
  ac.abort();
  try {
    await Deno.readFile("/tmp/out", { signal: ac.signal });
  } catch {}
});
```
2023-10-02 02:18:34 +02:00
denobot
3b78981ffe
chore: forward v1.37.1 release commit to main (#20706)
This is the release commit being forwarded back to main for 1.37.1

Co-authored-by: littledivy <littledivy@users.noreply.github.com>
2023-09-27 09:13:48 +00:00
Matt Mastracci
a27ee8f368
fix(ext/http): ensure that resources are closed when request is cancelled (#20641)
Builds on top of #20622 to fix #10854
2023-09-25 17:23:55 +02:00
Matt Mastracci
06297d952d
feat(ext/web): use readableStreamDefaultReaderRead in resourceForReadableStream (#20622)
We can go one level down in abstraction and avoid using the public
`ReadableStream` APIs.

This patch ~5% perf boost on small ReadableStream:

```
Running 10s test @ http://localhost:8080/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   148.32us  108.95us   3.88ms   95.71%
    Req/Sec    33.24k     2.68k   37.94k    73.76%
  668188 requests in 10.10s, 77.74MB read
Requests/sec:  66162.91
Transfer/sec:      7.70MB
```

main:

```
Running 10s test @ http://localhost:8080/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   150.23us   67.61us   4.39ms   94.80%
    Req/Sec    31.81k     1.55k   35.56k    83.17%
  639078 requests in 10.10s, 74.36MB read
Requests/sec:  63273.72
Transfer/sec:      7.36MB
```
2023-09-23 14:55:28 +00:00
Matt Mastracci
0981aefbdc
fix(ext/web): Aggregate small packets for Resource implementation of ReadableStream (#20570)
Fixes: #20569 by introducing a custom replacement for the tokio mpsc
channel that is byte-size backpressure-aware.

Using the testcase in the linked bug, we see all the small writes
aggregated into a single packet and HTTP frame.

```
10:39 $ nc localhost 8000
GET / HTTP/1.1

HTTP/1.1 200 OK
content-type: text/plain
vary: Accept-Encoding
transfer-encoding: chunked
date: Tue, 19 Sep 2023 16:39:13 GMT

A
0
1
2
3
4
```

This patch:

```
Running 10s test @ http://localhost:8080/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   157.47us  194.89us   9.53ms   98.97%
    Req/Sec    31.37k     1.56k   34.73k    85.15%
  630407 requests in 10.10s, 73.35MB read
Requests/sec:  62428.12
Transfer/sec:      7.26MB
```

main:

```
Running 10s test @ http://localhost:8080/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   343.75us  200.48us  10.41ms   98.25%
    Req/Sec    14.64k   806.52    16.98k    84.65%
  294018 requests in 10.10s, 39.82MB read
Requests/sec:  29109.91
Transfer/sec:      3.94MB
```

---------

Co-authored-by: Bert Belder <bertbelder@gmail.com>
2023-09-20 11:23:58 -06:00
denobot
997aa604df
1.37.0 (#20574)
Co-authored-by: David Sherret <dsherret@gmail.com>
2023-09-19 20:29:17 +00:00
Marcos Casagrande
4960b6659c
perf(ext/streams): optimize async iterator (#20541)
This PR optimizes `ReadableStream` async iterator

### Benchmarks

```js
Deno.bench("Stream - iterator", async () => {
  const stream = new ReadableStream({
    start(controller) {
      controller.enqueue(new Uint8Array([97]));
      controller.enqueue(new Uint8Array([97]));
      controller.close();
    },
  });

  for await (const chunk of stream) {}
});
```

**main**

`2 chunks`
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.4 (x86_64-unknown-linux-gnu)

benchmark              time (avg)        iter/s             (min … max)       p75       p99      p995
----------------------------------------------------------------------- -----------------------------
Stream - iterator      12.45 µs/iter      80,295.5   (10.5 µs … 281.12 µs)  12.13 µs  26.71 µs  33.63 µs
```
`20 chunks`

```
benchmark              time (avg)        iter/s             (min … max)       p75       p99      p995
----------------------------------------------------------------------- -----------------------------
Stream - iterator      32.99 µs/iter      30,312.2    (28.13 µs … 1.21 ms)   31.8 µs  81.82 µs 179.93 µs
```
---

**this PR**

`2 chunks`
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.36.4 (x86_64-unknown-linux-gnu)

benchmark              time (avg)        iter/s             (min … max)       p75       p99      p995
----------------------------------------------------------------------- -----------------------------
Stream - iterator       9.37 µs/iter     106,700.8   (8.35 µs … 730.71 µs)   9.15 µs  13.12 µs  18.17 µs
```
`20 chunks`
```
benchmark              time (avg)        iter/s             (min … max)       p75       p99      p995
----------------------------------------------------------------------- -----------------------------
Stream - iterator      16.59 µs/iter      60,270.0    (12.08 µs … 1.37 ms)  15.06 µs  83.03 µs 123.52 µs
```
2023-09-17 15:54:40 +00:00
Bartek Iwańczuk
5e7435fb80
refactor: rewrite more ops to op2 macro (#20478) 2023-09-14 23:05:18 +02:00
lionel-rowe
2046aeed70
feat(ext/web): Add name to Deno.customInspect of File objects (#20415)
Fixes https://github.com/denoland/deno/issues/20414
2023-09-14 07:06:58 +02:00
Matt Mastracci
bfd230fd78
chore: update inner #\![allow] to #[allow] (#20463)
Functions should generally be annotated with `#[allow]` blocks rather
than using inner `#![allow]` annotations.
2023-09-11 17:12:33 -06:00
Aapo Alasuutari
9d6584c16f
perf(ext/node): Optimise Buffer string operations (#20158)
Extracted from https://github.com/denoland/deno/pull/17815

Optimise Buffer's string operations, most significantly when dealing
with ASCII and UTF-16. Base64 and HEX encodings are affected to much
lesser degrees.

## Performance

### String length 15
With very small strings we're at break-even or sometimes even lose a tad
bit of performance from creating a `DataView` that ends up not paying
for itself.

**This PR:**
```
benchmark                                                     time (avg)        iter/s             (min … max)       p75       p99      p995
-------------------------------------------------------------------------------------------------------------- -----------------------------
Buffer.from ascii string                                       1.15 µs/iter     871,388.6   (728.78 ns … 1.56 µs)   1.23 µs   1.56 µs   1.56 µs
Buffer.from base64 string                                      1.63 µs/iter     612,790.9     (1.31 µs … 1.96 µs)   1.77 µs   1.96 µs   1.96 µs
Buffer.from utf16 string                                       1.41 µs/iter     707,396.3   (915.24 ns … 1.93 µs)   1.61 µs   1.93 µs   1.93 µs
Buffer.from hex string                                         1.87 µs/iter     535,357.9     (1.56 µs … 2.19 µs)      2 µs   2.19 µs   2.19 µs
Buffer.toString ascii string                                 154.58 ns/iter   6,469,162.8    (149.69 ns … 198 ns) 154.51 ns 182.89 ns 191.91 ns
Buffer.toString base64 string                                161.65 ns/iter   6,186,189.6 (150.91 ns … 181.15 ns) 165.18 ns 171.87 ns 174.94 ns
Buffer.toString utf16 string                                 292.74 ns/iter   3,415,959.8 (285.43 ns … 312.47 ns) 295.25 ns 310.47 ns 312.47 ns
Buffer.toString hex string                                    89.61 ns/iter  11,159,315.6  (81.09 ns … 123.77 ns)  91.09 ns 113.62 ns 119.28 ns
```

**Main:**
```
benchmark                                                     time (avg)        iter/s             (min … max)       p75       p99      p995
-------------------------------------------------------------------------------------------------------------- -----------------------------
Buffer.from ascii string                                       1.26 µs/iter     794,875.8     (1.07 µs … 1.46 µs)   1.31 µs   1.46 µs   1.46 µs
Buffer.from base64 string                                      1.65 µs/iter     607,853.3     (1.38 µs … 2.01 µs)   1.69 µs   2.01 µs   2.01 µs
Buffer.from utf16 string                                       1.34 µs/iter     744,894.6     (1.09 µs … 1.55 µs)   1.45 µs   1.55 µs   1.55 µs
Buffer.from hex string                                         2.01 µs/iter     496,345.8      (1.54 µs … 2.6 µs)   2.26 µs    2.6 µs    2.6 µs
Buffer.toString ascii string                                 150.16 ns/iter   6,659,630.5 (144.99 ns … 166.68 ns)  152.4 ns 157.26 ns 159.14 ns
Buffer.toString base64 string                                164.73 ns/iter   6,070,692.0 (158.77 ns … 185.63 ns) 168.48 ns 175.74 ns 176.68 ns
Buffer.toString utf16 string                                 150.61 ns/iter   6,639,864.0  (148.2 ns … 168.29 ns) 150.93 ns 157.21 ns 168.15 ns
Buffer.toString hex string                                    94.21 ns/iter  10,614,972.9   (86.21 ns … 98.75 ns)  95.43 ns  97.99 ns  98.21 ns
```

### String length 1500
With moderate lengths we already see great upsides for `Buffer.from()`
with ASCII and UTF-16.

**This PR:**
```
benchmark                                                     time (avg)        iter/s             (min … max)       p75       p99      p995
-------------------------------------------------------------------------------------------------------------- -----------------------------
Buffer.from ascii string                                       5.79 µs/iter     172,562.6     (4.72 µs … 4.71 ms)   5.04 µs   10.3 µs  11.67 µs
Buffer.from base64 string                                      5.08 µs/iter     196,678.9     (4.97 µs … 5.76 µs)   5.08 µs   5.76 µs   5.76 µs
Buffer.from utf16 string                                       9.68 µs/iter     103,316.5     (7.14 µs … 3.44 ms)  10.32 µs  13.42 µs  15.21 µs
Buffer.from hex string                                         53.7 µs/iter      18,620.2     (49.37 µs … 2.2 ms)  54.74 µs   72.2 µs  81.07 µs
Buffer.toString ascii string                                   6.63 µs/iter     150,761.3     (5.59 µs … 1.11 ms)   6.08 µs  15.68 µs  24.77 µs
Buffer.toString base64 string                                460.57 ns/iter   2,171,224.4 (448.33 ns … 511.73 ns) 465.05 ns 495.54 ns 511.73 ns
Buffer.toString utf16 string                                   6.52 µs/iter     153,287.0     (6.47 µs … 6.66 µs)   6.53 µs   6.66 µs   6.66 µs
Buffer.toString hex string                                     3.68 µs/iter     271,965.4     (3.64 µs … 3.82 µs)   3.68 µs   3.82 µs   3.82 µs
```

**Main:**
```
benchmark                                                     time (avg)        iter/s             (min … max)       p75       p99      p995
-------------------------------------------------------------------------------------------------------------- -----------------------------
Buffer.from ascii string                                      11.46 µs/iter      87,298.1    (8.53 µs … 834.1 µs)   9.61 µs  83.31 µs   87.3 µs
Buffer.from base64 string                                       5.4 µs/iter     185,027.8     (5.07 µs … 7.49 µs)   5.44 µs   7.49 µs   7.49 µs
Buffer.from utf16 string                                       20.3 µs/iter      49,270.8  (13.55 µs … 649.11 µs)   18.8 µs 113.93 µs 125.17 µs
Buffer.from hex string                                        52.03 µs/iter      19,218.9    (48.74 µs … 2.59 ms)  52.84 µs  67.05 µs  73.56 µs
Buffer.toString ascii string                                   6.46 µs/iter     154,822.5     (6.32 µs … 6.69 µs)   6.52 µs   6.69 µs   6.69 µs
Buffer.toString base64 string                                440.19 ns/iter   2,271,764.6    (427 ns … 490.77 ns) 444.74 ns 484.64 ns 490.77 ns
Buffer.toString utf16 string                                   6.89 µs/iter     145,106.7     (6.81 µs … 7.24 µs)   6.91 µs   7.24 µs   7.24 µs
Buffer.toString hex string                                     3.66 µs/iter     273,456.5      (3.6 µs … 4.02 µs)   3.64 µs   4.02 µs   4.02 µs
```

### String length 2^20
With massive lengths we the difference in ASCII and UTF-16 parsing
performance is enormous.

**This PR:**
```
benchmark                                                           time (avg)        iter/s             (min … max)       p75       p99      p995
-------------------------------------------------------------------------------------------------------------------- -----------------------------
Buffer.from ascii string                                              4.1 ms/iter         243.7     (2.64 ms … 6.74 ms)   4.43 ms   6.26 ms   6.74 ms
Buffer.from base64 string                                            3.74 ms/iter         267.6     (2.91 ms … 4.92 ms)   3.96 ms   4.31 ms   4.92 ms
Buffer.from utf16 string                                             7.72 ms/iter         129.5    (5.91 ms … 11.03 ms)   7.97 ms  11.03 ms  11.03 ms
Buffer.from hex string                                              35.72 ms/iter          28.0   (34.71 ms … 38.42 ms)  35.93 ms  38.42 ms  38.42 ms
Buffer.toString ascii string                                        78.92 ms/iter          12.7   (42.72 ms … 94.13 ms)  91.64 ms  94.13 ms  94.13 ms
Buffer.toString base64 string                                      833.62 µs/iter       1,199.6   (638.05 µs … 5.97 ms) 826.86 µs   2.45 ms   2.48 ms
Buffer.toString utf16 string                                        79.35 ms/iter          12.6    (69.72 ms … 88.9 ms)  86.66 ms   88.9 ms   88.9 ms
Buffer.toString hex string                                          31.04 ms/iter          32.2      (4.3 ms … 46.9 ms)  37.21 ms   46.9 ms   46.9 ms
```

**Main:**
```
benchmark                                                           time (avg)        iter/s             (min … max)       p75       p99      p995
-------------------------------------------------------------------------------------------------------------------- -----------------------------
Buffer.from ascii string                                            18.66 ms/iter          53.6   (15.61 ms … 23.26 ms)  20.62 ms  23.26 ms  23.26 ms
Buffer.from base64 string                                             4.7 ms/iter         212.9     (2.94 ms … 9.07 ms)   4.65 ms   9.06 ms   9.07 ms
Buffer.from utf16 string                                            33.49 ms/iter          29.9   (31.24 ms … 35.67 ms)  34.08 ms  35.67 ms  35.67 ms
Buffer.from hex string                                              39.38 ms/iter          25.4   (38.66 ms … 42.36 ms)  39.58 ms  42.36 ms  42.36 ms
Buffer.toString ascii string                                        77.68 ms/iter          12.9   (67.46 ms … 95.68 ms)  84.71 ms  95.68 ms  95.68 ms
Buffer.toString base64 string                                      825.53 µs/iter       1,211.3   (655.38 µs … 6.69 ms) 816.62 µs   3.07 ms   3.13 ms
Buffer.toString utf16 string                                        76.54 ms/iter          13.1    (66.9 ms … 85.26 ms)  83.63 ms  85.26 ms  85.26 ms
Buffer.toString hex string                                          38.56 ms/iter          25.9   (33.83 ms … 46.56 ms)  45.33 ms  46.56 ms  46.56 ms
```
2023-09-07 14:41:16 -06:00
David Sherret
3fc19dab47
feat: support import attributes (#20342) 2023-09-07 09:09:16 -04:00