kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

[DRAFT] Serializers cache

Open qwwdfsad opened this issue 2 years ago • 2 comments

Attempt to somehow address #2003

qwwdfsad avatar Aug 02 '22 15:08 qwwdfsad

Preliminary data

Benchmark                                Mode  Cnt   Score   Error   Units
LookupOverheadBenchmark.dataPlain       thrpt   14   9.831 ± 0.457  ops/us
LookupOverheadBenchmark.dataReified     thrpt   14   3.326 ± 0.084  ops/us
LookupOverheadBenchmark.genericPlain    thrpt   14   5.473 ± 0.565  ops/us
LookupOverheadBenchmark.genericReified  thrpt   14   0.164 ± 0.008  ops/us
LookupOverheadBenchmark.objectPlain     thrpt   14  27.828 ± 2.141  ops/us
LookupOverheadBenchmark.objectReified   thrpt   14   5.221 ± 0.101  ops/us

qwwdfsad avatar Aug 02 '22 15:08 qwwdfsad

The following best-case approximation of caching:

@Benchmark                                                             
fun objectApprox(): Object {                                           
    typeOf<Object>()                                                   
    return Json.decodeFromString(Object.serializer(), "{}")            
}                                                                      

gives

LookupOverheadBenchmark.objectApprox  thrpt   14  13.181 ± 0.821  ops/us

which is much better for the benchmark that stresses empty string

qwwdfsad avatar Aug 02 '22 15:08 qwwdfsad

Continuing in https://github.com/Kotlin/kotlinx.serialization/issues/2003

qwwdfsad avatar Aug 25 '22 14:08 qwwdfsad

Continuing a PR in an issue that predates it? Are you sure you referenced the right one?

LouisCAD avatar Aug 25 '22 19:08 LouisCAD

Oh, right, I've meant https://github.com/Kotlin/kotlinx.serialization/pull/2015 :)

qwwdfsad avatar Aug 25 '22 20:08 qwwdfsad