Repository navigation
Commit 4fe400b
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 c5cfdef commit 4fe400b
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 | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | | - | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | | - | |
| 61 | + | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
273 | 276 | | |
274 | 277 | | |
275 | 278 | | |
| |||
514 | 517 | | |
515 | 518 | | |
516 | 519 | | |
517 | | - | |
| 520 | + | |
| 521 | + | |
518 | 522 | | |
519 | 523 | | |
520 | 524 | | |
521 | 525 | | |
| 526 | + | |
522 | 527 | | |
523 | 528 | | |
524 | 529 | | |
| |||
536 | 541 | | |
537 | 542 | | |
538 | 543 | | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
545 | 548 | | |
546 | 549 | | |
547 | 550 | | |
548 | 551 | | |
549 | 552 | | |
550 | | - | |
551 | | - | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
552 | 556 | | |
553 | 557 | | |
554 | 558 | | |
555 | 559 | | |
556 | 560 | | |
557 | 561 | | |
| 562 | + | |
558 | 563 | | |
559 | 564 | | |
560 | 565 | | |
| |||
703 | 708 | | |
704 | 709 | | |
705 | 710 | | |
706 | | - | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
707 | 714 | | |
708 | 715 | | |
709 | 716 | | |
| |||
737 | 744 | | |
738 | 745 | | |
739 | 746 | | |
740 | | - | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
741 | 750 | | |
742 | 751 | | |
743 | 752 | | |
| |||
784 | 793 | | |
785 | 794 | | |
786 | 795 | | |
787 | | - | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
788 | 799 | | |
789 | 800 | | |
790 | 801 | | |
| |||
| 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