Commit 3001b53
committed
Optimize Channel API for large messages
Add channel_send_owned_binary() that takes ownership of a binary and
directly enqueues it to the IOQueue without an additional copy.
Before: nif_channel_send called enif_term_to_binary (alloc + copy),
then channel_send which called enif_alloc_binary + memcpy (alloc + copy).
This resulted in 2 allocations and 2 copies per message.
After: nif_channel_send calls enif_term_to_binary then passes the binary
directly to channel_send_owned_binary which enqueues without copying.
This results in 1 allocation and 1 copy per message.
For 16KB messages, this eliminates 16KB of unnecessary memory operations
per send, improving speedup vs Reactor from 1.6x to 2.0x.1 parent 2e5447a commit 3001b53
2 files changed
Lines changed: 79 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
160 | 215 | | |
161 | 216 | | |
162 | 217 | | |
| |||
516 | 571 | | |
517 | 572 | | |
518 | 573 | | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
519 | 578 | | |
520 | 579 | | |
521 | 580 | | |
| |||
525 | 584 | | |
526 | 585 | | |
527 | 586 | | |
528 | | - | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
529 | 592 | | |
530 | 593 | | |
531 | 594 | | |
532 | 595 | | |
533 | 596 | | |
534 | | - | |
535 | | - | |
| 597 | + | |
536 | 598 | | |
| 599 | + | |
537 | 600 | | |
538 | 601 | | |
539 | 602 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
207 | 220 | | |
208 | 221 | | |
209 | 222 | | |
| |||
0 commit comments