avro-kotlin / avro4k

Avro format support for Kotlin
Apache License 2.0
198 stars 37 forks source link

Serialized maps weight too much #105

Closed cy6erGn0m closed 3 years ago

cy6erGn0m commented 3 years ago

Serializing maps produces too much bytes comparing to Protobuf and CBOR. Not sure, if it's something with avro itself or schema generation. I believe this is significant because the main and only reason to use binary formats is that they could be compact and safe regardless of the user content (no need to escape anything).

@Serializable
data class X(
    val v: Int,
    val map: Map<String, String>
)

@OptIn(ExperimentalSerializationApi::class)
fun main() {
    val data = X(1, emptyMap())
    ProtoBuf.encodeToByteArray(data).let { println("Protobuf: ${it.size}") }
    Avro.default.encodeToByteArray(data).let { println("Avro: ${it.size}") }
    Cbor.encodeToByteArray(data).let { println("Cbor: ${it.size}") }
}

Produces:

Protobuf: 2
Avro: 221
Cbor: 11
sksamuel commented 3 years ago

Avro includes the schema.

cy6erGn0m commented 3 years ago

Is it required to pass schema with every single message?

thake commented 3 years ago

@cy6erGn0m no it is not. Have a look at the readme.