Is it expected that the first deserialization from a
Json
instance will be slow? Parsing a small JSON text in some unit tests. The first test takes 167 ms (longer on build machine) just in the parsing. All the other tests take about one millisecond to parse the same amount of JSON.
This is on the JVM with Kotlin 1.6.10 and Serialization 1.3.2.
b
Big Chungus
03/02/2022, 3:09 PM
This is JVM JIT in action. Any big operation is expected to be much slower the first time it's executed.
m
mkrussel
03/02/2022, 3:11 PM
I would have expected JIT to take longer to improve, but that does make sense
e
ephemient
03/02/2022, 3:41 PM
also note that if you're using the reified helpers that don't require a serializer as input, then it (counterintuitively) performs reflection to find the serializer, which will also be slower the first time (and will always be slower than passing the serializer explicitly)
m
mkrussel
03/02/2022, 3:50 PM
I was using the reified version. Changing didn't have much of an impact.
m
mbonnin
03/03/2022, 10:00 AM
In addition to the above reasons, maybe Classloading plays a role there? You could try to warm the classes before deserializing to see if there's any difference