Repository navigation
Commit 4bb015c
stream: yield bounded batches directly in stream/iter from()
When a source value is already a Uint8Array[] batch, from() and
fromSync() yielded it through `yield* yieldBoundedBatch(value)`, which
creates a generator for every batch only to split batches larger than
128 chunks. In the async normalization, yield* of a sync generator
also costs several extra promise ticks per batch.
Yield batches within the bound directly, and delegate to
yieldBoundedBatch() only for larger ones. Empty batches are still
skipped.
With 16-byte chunks, one per batch: pipeTo() from a sync iterable is
about 2x faster and iterating from() over it about 2.8x faster; from an
async generator, pipeTo() is about 1.5x and iteration about 1.7x
faster; pipeToSync() is about 1.4x faster.
Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: #66504
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>1 parent 3db2f0a commit 4bb015c
1 file changed
Lines changed: 18 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
336 | 340 | | |
337 | 341 | | |
338 | 342 | | |
| |||
581 | 585 | | |
582 | 586 | | |
583 | 587 | | |
584 | | - | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
585 | 591 | | |
586 | | - | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
587 | 597 | | |
588 | 598 | | |
589 | 599 | | |
| |||
630 | 640 | | |
631 | 641 | | |
632 | 642 | | |
633 | | - | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
634 | 648 | | |
635 | 649 | | |
636 | 650 | | |
| |||
0 commit comments