Repository navigation
Commit 090f00f
committed
stream: snapshot common stream/iter byte views in fewer fields
To detect that a chunk accepted by a writer was resized or detached
before it is read, a ByteViewSnapshot of its buffer, byteLength,
byteOffset and detached state is taken for every chunk written, and
checked when it is read.
A non-empty view of a fixed-length, non-shared ArrayBuffer can only
change by the buffer being detached, which makes its byteLength 0, as
recordChunk() already relies on. Snapshot such views, the common case,
as a FixedByteView of the view and its byteLength, which is all that
needs to be checked.
Writing 16-byte chunks to a push() stream and reading them is about 17%
faster with await write() and 37% faster with writeSync(), and piping
them about 29% and 51%; 64 KiB chunks are about 7-13% faster.
Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>1 parent 7b0e7a2 commit 090f00f
1 file changed
Lines changed: 27 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
379 | 390 | | |
380 | 391 | | |
381 | 392 | | |
| |||
399 | 410 | | |
400 | 411 | | |
401 | 412 | | |
402 | | - | |
403 | | - | |
404 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
405 | 421 | | |
406 | 422 | | |
407 | 423 | | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
408 | 432 | | |
409 | 433 | | |
410 | 434 | | |
| |||
0 commit comments