# Efficiency of channels?

**URL:** <https://discourse.julialang.org/t/efficiency-of-channels/9952>\
**Category:** General Usage\
**Created:** [March 24, 2018, 10:22pm UTC](https://discourse.julialang.org/t/efficiency-of-channels/9952 "2018-03-24T22:22:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [March 24, 2018, 10:22pm UTC](https://discourse.julialang.org/t/efficiency-of-channels/9952/1 "2018-03-24T22:22:43Z")

</div>

I’ve been attempting to use channels to implement a discrete time simulation and in my simple test code i have found that they seem to incur a lot of overhead.

just moving a single value into the producer channel and out of a consumer channel, 1 value at a time, at 10^5 iterations takes, about 0.3 s. i know this is an arbitrary number, but as a point of comparison the calculation that i would be performing on the accumulated values, adds 0.07s to that run-time.

I had sort of assumed that “under the hood” the channels would simply be some sort of array/buffer and an index, and so there would be very little over head. I’ve read through the documentation, and done the obligatory web search, and haven’t found any documentation pertaining to efficiency.

before i go re-inventing any wheels I’m wondering if there’s  
1 a way to improve the efficiency of the channels  
2 another data type in Julia that would be more suitable for what Im doing

Thanks!

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 24, 2018, 10:59pm UTC](https://discourse.julialang.org/t/efficiency-of-channels/9952/2 "2018-03-24T22:59:52Z")

</div>

Channels are used for asynchronous I/O etcetera, and so they have to go through libuv’s event loop. This adds a lot of overhead.

You shouldn’t normally use channels if you just want to pass data from one function to another. Just compose the functions directly.

---

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [March 24, 2018, 11:07pm UTC](https://discourse.julialang.org/t/efficiency-of-channels/9952/3 "2018-03-24T23:07:54Z")

</div>

ok.

the reason i was attempting to use channels was because eventually i’ll be operating on data coming in over UDP.

the idea was that the processing could stall until data was available.

however it occurs to me that i’m much better of handling that by having something that simply kicks off the calculations when enough data is present.

then i just have the one async interface point and the rest of the calculation can just proceed as normal.

thanks.

---

<div class="post-metadata">

**Author:** ![pasha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pasha/32/3319_2.png) [@pasha](https://discourse.julialang.org/u/pasha)\
**Post date:** [March 25, 2018, 2:38am UTC](https://discourse.julialang.org/t/efficiency-of-channels/9952/4 "2018-03-25T02:38:27Z")

</div>

Right, or you could either `@schedule` a task to listen for UDP, blocking when there are no packets (though actually on the same worker process), or you could set up a separate parallel worker if you wanted to do the listening on a separate worker.
