We're currently using Serialization (1.3.2, but trying 1.3.3 and 1.4 now) for serializing some very ...
c
We're currently using Serialization (1.3.2, but trying 1.3.3 and 1.4 now) for serializing some very simple objects into JSON (they're basically Android navigation holders). We use these classes a lot. They're used for all navigation calls in our Android app, and get serialized at each
navigate()
, therefore performance is important. Most of these
Args
classes we have are
@Serializable object MyScreenArgs: ArgsInterface
, and some are data classes if they contain some inner values. We've seen that creating a
serializer()
for the
object
classes is extremely slow:
Copy code
7,137ns   benchmarkDataClassContentViewArgsToBundle
69,204ns  benchmarkObjectContentViewArgsToBundle
5,301ns   benchmarkDataClassBundleToContentViewArgs
67,981ns  benchmarkObjectBundleToContentViewArgs
(tests using AndroidX Microbenchmark on a Google Pixel 1) It doesn't matter if we use the reflection or non-reflection versions of
serializer()
, they're both very similar in terms of time. In fact, the generated serializer is usually slightly slower to retrieve for some reason. I've profiled our tests, and 90% of the time is spent retrieving the
serializer()
, the conversion to/from JSON is around 3ms for all benchmarks. Anyone know why the object serializer could be so slow?
👀 4
m
Any chance you can share the benchmarks? I'd be curious to investigate this
My impression based on that issue was that reflection would dominate the parsing time and that non-reflection would be quite faster
c
Raised an issue as there's definitely seems like there is something here: https://github.com/Kotlin/kotlinx.serialization/issues/2003