Repository navigation
Commit bf7c279
committed
stream: trim webstreams sink wrappers and BYOB transfers
The close and abort methods of an underlying sink and the flush and
cancel methods of a transformer were each wrapped at construction in an
async closure that the controller kept for the stream's lifetime: two per
WritableStream and two per TransformStream, each with its context. Store
these one-shot methods as-is in the controller state next to the object
they belong to, and call them as that object's methods with the spec's
argument list through a promiseCall helper that keeps the reference
implementation's adoption ticks. The per-chunk methods (write, transform)
keep their closures, which make the method a constant for the optimizing
compiler on the hot paths; so does the source's cancel wrapper, since the
readable stream's construction path is sensitive to any change in its
inlining budget.
In the byte controller, the transfer of a pull-into descriptor's buffer
when it is committed is dropped: nothing can reach that buffer any more,
since it was transferred when the descriptor was created and the BYOB
request that exposed it is only ever invalidated together with a
transfer. The transfer of the first pending descriptor's buffer on
enqueue is likewise only needed while a BYOB request exposes it.
Allocating an ArrayBuffer costs about half a microsecond, so those two
transfers were a large part of a BYOB read.
Bytes allocated per stream with user methods: WritableStream 1040 -> 844,
TransformStream 1816 -> 1720. The microtask ordering of every user
method call is unchanged.
Benchmark results (20 runs, vs. the previous commit):
webstreams/readable-read.js type='byob' n=100000 *** 17.14 % ±1.80%
webstreams/readable-async-iterator.js type='normal' n=100000 3.79 % ±4.49%
webstreams/from.js kind='sync' n=1000000 * -2.18 % ±2.02%
webstreams/js_transfer.js n=10000 payload='TransformStream' * -1.85 % ±1.58%
The other 42 rows are within their confidence intervals; the two rows
at the 5% level are the expected number of false positives for 46
comparisons.
Signed-off-by: Matteo Collina <hello@matteocollina.com>1 parent eb663fe commit bf7c279
5 files changed
Lines changed: 257 additions & 70 deletions
File tree
- lib/internal/webstreams
- test/parallel
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2388 | 2388 | | |
2389 | 2389 | | |
2390 | 2390 | | |
2391 | | - | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
2392 | 2395 | | |
2393 | 2396 | | |
2394 | | - | |
| 2397 | + | |
2395 | 2398 | | |
2396 | 2399 | | |
2397 | | - | |
| 2400 | + | |
2398 | 2401 | | |
2399 | 2402 | | |
2400 | 2403 | | |
| |||
3427 | 3430 | | |
3428 | 3431 | | |
3429 | 3432 | | |
3430 | | - | |
3431 | | - | |
3432 | | - | |
3433 | | - | |
3434 | | - | |
| 3433 | + | |
| 3434 | + | |
| 3435 | + | |
| 3436 | + | |
| 3437 | + | |
| 3438 | + | |
| 3439 | + | |
| 3440 | + | |
| 3441 | + | |
3435 | 3442 | | |
3436 | 3443 | | |
3437 | 3444 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
| 63 | + | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
276 | 279 | | |
277 | 280 | | |
278 | 281 | | |
| |||
517 | 520 | | |
518 | 521 | | |
519 | 522 | | |
520 | | - | |
| 523 | + | |
| 524 | + | |
521 | 525 | | |
522 | 526 | | |
523 | 527 | | |
524 | 528 | | |
| 529 | + | |
525 | 530 | | |
526 | 531 | | |
527 | 532 | | |
| |||
539 | 544 | | |
540 | 545 | | |
541 | 546 | | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
548 | 551 | | |
549 | 552 | | |
550 | 553 | | |
551 | 554 | | |
552 | 555 | | |
553 | | - | |
554 | | - | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
555 | 559 | | |
556 | 560 | | |
557 | 561 | | |
558 | 562 | | |
559 | 563 | | |
560 | 564 | | |
| 565 | + | |
561 | 566 | | |
562 | 567 | | |
563 | 568 | | |
| |||
715 | 720 | | |
716 | 721 | | |
717 | 722 | | |
718 | | - | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
719 | 726 | | |
720 | 727 | | |
721 | 728 | | |
| |||
749 | 756 | | |
750 | 757 | | |
751 | 758 | | |
752 | | - | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
753 | 762 | | |
754 | 763 | | |
755 | 764 | | |
| |||
796 | 805 | | |
797 | 806 | | |
798 | 807 | | |
799 | | - | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
800 | 811 | | |
801 | 812 | | |
802 | 813 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
340 | 334 | | |
341 | 335 | | |
342 | 336 | | |
| |||
347 | 341 | | |
348 | 342 | | |
349 | 343 | | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
350 | 384 | | |
351 | 385 | | |
352 | 386 | | |
| |||
385 | 419 | | |
386 | 420 | | |
387 | 421 | | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | 422 | | |
399 | 423 | | |
400 | 424 | | |
| |||
438 | 462 | | |
439 | 463 | | |
440 | 464 | | |
441 | | - | |
442 | | - | |
443 | 465 | | |
444 | | - | |
| 466 | + | |
| 467 | + | |
445 | 468 | | |
446 | | - | |
| 469 | + | |
447 | 470 | | |
448 | 471 | | |
449 | 472 | | |
| |||
463 | 486 | | |
464 | 487 | | |
465 | 488 | | |
466 | | - | |
467 | 489 | | |
468 | | - | |
469 | 490 | | |
470 | 491 | | |
471 | 492 | | |
| |||
489 | 510 | | |
490 | 511 | | |
491 | 512 | | |
492 | | - | |
493 | | - | |
494 | 513 | | |
| 514 | + | |
| 515 | + | |
495 | 516 | | |
496 | 517 | | |
497 | 518 | | |
| |||
0 commit comments