https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

Daniel Tam

06/27/2018, 1:20 PM
Let's say I have some complex message protocol that requires wrapping objects inside objects inside objects (e.g. IP headers on tcp headers on http headers on data). Let's say I want to construct an IP message. Does anyone have any idea what will have better performance? (I suspect the first): 1. passing a lambda from the IP layer to the TCP layer, then wrapping it in a lambda and passing it to the HTTP layer, then wrapping it in a lambda and passing it to the layer that generates data. I.e. the data generation layer can just directly invoke the method to construct+send an IP message 2. passing a channel (or using producer/actor) between each layer, then spawning a coroutine for each layer to wrap and forward the data. I.e. the data generation layer creates its data and sends it through a channel to the HTTP layer, which then wraps it and sends it to the TCP layer, etc.
g

gildor

06/30/2018, 5:06 AM
Maybe make sense to try. I suppose channel implementation will be slower, because channel is pretty high level abstraction created for multi-thread usage so with all atomics and CAS
5 Views