Skip to content

Serializing object classes is 10x slower than data classes #2003

Closed
@chrisbanes

Description

@chrisbanes

Copying over my Android Microbenchmarks results (ran on Google Pixel 3):

Benchmark Time (ns) Allocations
object_reflection_serializer 56,077 27
object_reflection_json 69,069 40
object_intrinsic_serializer 56,211 30
object_intrinsic_json 118,768 73
dataclass_reflection_serializer 2,450 8
dataclass_reflection_json 6,462 28
dataclass_intrinsic_serializer 2,687 11
dataclass_intrinsic_json 9,927 42

Also interesting is that the intrinsic is usually (marginally) slower than using reflection.

To Reproduce
All benchmarks are here: https://github.com/chrisbanes/kotlin-serialization-object-perf

Expected behavior
I'd expect objects to be faster than data classes (or at least similar).

Environment

  • Kotlin version: 1.7.0
  • Library version: 1.3.3 (1.4-RC is very similar numbers though)
  • Kotlin platforms: JVM/Android

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions