Commit 7d7fd6d
io: allocate copy buffers from a pool
CopyBuffer allocates a 32k buffer when no buffer is available.
Allocate these buffers from a sync.Pool.
This removes an optimization where the copy buffer size was
reduced when the source is a io.LimitedReader (including the
case of CopyN) with a limit less than the default buffer size.
This change could cause a program which only uses io.Copy
with sources with a small limit to allocate unnecessarily
large buffers. Programs which care about the transient
buffer allocation can avoid this by providing their own buffer.
name old time/op new time/op delta
CopyNSmall-10 165ns ± 7% 117ns ± 7% -29.19% (p=0.001 n=7+7)
CopyNLarge-10 7.33µs ±34% 4.07µs ± 2% -44.52% (p=0.001 n=7+7)
name old alloc/op new alloc/op delta
CopyNSmall-10 2.20kB ±12% 1.20kB ± 4% -45.24% (p=0.000 n=8+7)
CopyNLarge-10 148kB ± 9% 81kB ± 4% -45.26% (p=0.000 n=8+7)
name old allocs/op new allocs/op delta
CopyNSmall-10 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=8+8)
CopyNLarge-10 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=8+8)
For #57202
Change-Id: I2292226da9ba1dc09a2543f5d74fe5da06080d49
Reviewed-on: https://go-review.googlesource.com/c/go/+/456555
TryBot-Result: Gopher Robot <[email protected]>
Run-TryBot: Damien Neil <[email protected]>
Reviewed-by: Thomas Austad <[email protected]>
Auto-Submit: Damien Neil <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>1 parent adc1db2 commit 7d7fd6d
2 files changed
+15
-32
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
403 | 410 | | |
404 | 411 | | |
405 | 412 | | |
| |||
413 | 420 | | |
414 | 421 | | |
415 | 422 | | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
425 | 426 | | |
426 | 427 | | |
427 | 428 | | |
| |||
637 | 638 | | |
638 | 639 | | |
639 | 640 | | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | 641 | | |
648 | | - | |
| 642 | + | |
649 | 643 | | |
650 | 644 | | |
651 | 645 | | |
652 | 646 | | |
653 | 647 | | |
654 | | - | |
| 648 | + | |
655 | 649 | | |
656 | 650 | | |
657 | 651 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
567 | 567 | | |
568 | 568 | | |
569 | 569 | | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | 570 | | |
575 | 571 | | |
576 | 572 | | |
577 | 573 | | |
578 | 574 | | |
579 | | - | |
| 575 | + | |
580 | 576 | | |
581 | 577 | | |
582 | 578 | | |
583 | 579 | | |
584 | 580 | | |
585 | 581 | | |
586 | 582 | | |
587 | | - | |
| 583 | + | |
588 | 584 | | |
589 | 585 | | |
590 | 586 | | |
| |||
602 | 598 | | |
603 | 599 | | |
604 | 600 | | |
605 | | - | |
| 601 | + | |
606 | 602 | | |
607 | 603 | | |
608 | 604 | | |
| |||
799 | 795 | | |
800 | 796 | | |
801 | 797 | | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
806 | | - | |
807 | | - | |
808 | | - | |
809 | 798 | | |
810 | 799 | | |
811 | 800 | | |
| |||
0 commit comments