Commit 6e61496
authored
Pre-allocate IO.select result arrays based on input size (ruby#15850)
io.c: pre-allocate IO.select result arrays based on input size
The ternary (rp?rb_ary_new():rb_ary_new2(0)) became pointless after
commit a51f30c (Variable Width Allocation, Mar 2022) made both
rb_ary_new() and rb_ary_new2(0) equivalent.
Instead of just removing the dead code, improve on the original intent
by pre-allocating based on the actual input array size. This avoids
reallocations when many FDs are ready.
Benchmark (100 ready FDs): ~8% improvement (5.59 -> 5.11 us/op)1 parent 65a4845 commit 6e61496
1 file changed
+3
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10758 | 10758 | | |
10759 | 10759 | | |
10760 | 10760 | | |
10761 | | - | |
10762 | | - | |
10763 | | - | |
| 10761 | + | |
| 10762 | + | |
| 10763 | + | |
10764 | 10764 | | |
10765 | 10765 | | |
10766 | 10766 | | |
| |||
0 commit comments