Recently we did some benchmarks in Kotlin and Java. According to our benchmarks, most encoding and decoding tasks' performance are similar in Kotlin and Java. But there is a special case when using _EncodingMode.DYNAMICMODE and @JsonProperty(required = true) together.
Environment:
jsoniter-0.9.23
javassist-3.27.0-GA
Java 11.0.6 + Kotlin 1.3.30
Windows 10
Test classes:
class KotlinRequest {
var sessionId: String? = null
var token: String? = null
var operatorId: Int? = null
var gameId: Int? = null
var username: String? = null
var isPromotion: Boolean? = null
var transactionKey: String? = null
var debit: Long = 0
var credit: Long = 0
}
class KotlinRequestWithAnnotation {
@JsonProperty(required = true)
var sessionId: String? = null
@JsonProperty(required = true)
var token: String? = null
@JsonProperty(required = true)
var operatorId: Int? = null
@JsonProperty(required = true)
var gameId: Int? = null
@JsonProperty(required = true)
var username: String? = null
@JsonProperty(required = true)
var isPromotion: Boolean? = null
@JsonProperty(required = true)
var transactionKey: String? = null
@JsonProperty(required = true)
var debit: Long = 0
@JsonProperty(required = true)
var credit: Long = 0
}
You can see after using @JsonProperty(required = true) annotation, the encoding speed is about 4x faster in dynamic mode. It is over 9x faster than the default encoding in reflection mode.
I think maybe you will be interested about why Kotlin can speed up the encoding quite a lot in this case.
Recently we did some benchmarks in Kotlin and Java. According to our benchmarks, most encoding and decoding tasks' performance are similar in Kotlin and Java. But there is a special case when using _EncodingMode.DYNAMICMODE and @JsonProperty(required = true) together.
Environment:
Test classes:
Test Data:
Results
Case 1: Using EncodingMode.DYNAMIC_MODE
Case 2: Default REFLECTION_MODE, same performance with Java codes
You can see after using @JsonProperty(required = true) annotation, the encoding speed is about 4x faster in dynamic mode. It is over 9x faster than the default encoding in reflection mode.
I think maybe you will be interested about why Kotlin can speed up the encoding quite a lot in this case.