Hi, is there any way to send kotlin object over kt...
# ktor
a
Hi, is there any way to send kotlin object over ktor http client to ktor server without serialization/deserialization?
a
Do you mean without a network?
a
oh, my question sounds silly. I mean without serialization to text 🙂 I don't want to serialize the object to human readable strings like json, I just need to send my data from JVM ktor http server to JS ktor http client and then use that object on kotlinJS. So json serialization/deserialization have a lot of overhead for this task. It really slow on large objects. https://github.com/Kotlin/kotlinx.serialization/issues/907 I used js v8 JSON.parse to speed up, that helps a little. Now I change serialization to cbor, it converts objects to byte array, it faster. What is the fastest way to send kotlin jvm object to kotlin js?
a
I think it mostly depends on what type of data do you want to send and receive. Maybe you can even implement encoding/decoding by yourself if your data model isn’t complex.
a
Kotlin data classes
a
Do you mean any type of data represented as data classes?
a
Yep
Primitive, collections others data classes
a
You can try Protocol buffers.
a
I thought about it. I am afraid that It will bring a lot of code and libs dependencies to my project
anyway thank you for suggestions
m
Some kind of serialization is needed anyway, be it text or binary, because the object you need lives in the memory space of the JVM running on your server. What you’re saying is only possible if the object is passed inside the same process (JVM) or between processes on the same machine (IPC). So yes, things like cbor or protobuf could be the closest to what you want. You may go even for gRPC, Thrift , Avro, etc. Regarding JSON, the overhead you’re referring to is actually a bug in kotlinx.serialization; if so you may consider using a different library such as Jackson. There are many which are very performant.
a
The problem is that Jackson isn’t multiplatform.
m
I see, I was only thinking about JVM on the server side.
a
yep, anyway jackson is slow 🙂
m
No it isn’t 🙂 It’s always been a performant implementation: https://github.com/cowtowncoder/java-json-performance-benchmarks/wiki Anyway if you’re really concerned about speed I believe this would be the fastest JSON lib on the JVM: https://github.com/ngs-doo/dsl-json
a
oh, thank you, it will helped for other tasks
đź‘Ť 1