Refactor KVI by k163377 · Pull Request #512 · FasterXML/jackson-module-kotlin (original) (raw)

This PR is a partial realization of the first step of the 3-step change I suggested in my comment #439.

Changes from existing

Many of the reflection operations performed by the KotlinValueInstantiator are now cached.
This is expected to speed up the process since the reflection process is omitted.

The results of the benchmark comparison are as follows.
From this result, we can see that it is actually faster.

before

Benchmark                                           Mode  Cnt        Score        Error  Units
c.w.constructor.Benchmarks.useDefaultKotlinMapper  thrpt    9   639074.213 ±  19600.918  ops/s
c.w.constructor.Benchmarks.useJavaMapper           thrpt    9  2883418.695 ± 117219.003  ops/s
c.w.constructor.Benchmarks.useKotlinMapper         thrpt    9  1163349.939 ±  34378.903  ops/s
c.w.factory.Benchmarks.useDefaultKotlinMapper      thrpt    9   556424.552 ±  10447.484  ops/s
c.w.factory.Benchmarks.useJavaMapper               thrpt    9  2848669.598 ±  25770.187  ops/s
c.w.factory.Benchmarks.useKotlinMapper             thrpt    9   571255.239 ±  14027.060  ops/s

after

Benchmark                                           Mode  Cnt        Score        Error  Units
c.w.constructor.Benchmarks.useDefaultKotlinMapper  thrpt    9   775820.306 ±  40891.839  ops/s
c.w.constructor.Benchmarks.useJavaMapper           thrpt    9  2823625.426 ± 107884.530  ops/s
c.w.constructor.Benchmarks.useKotlinMapper         thrpt    9  1312132.093 ±   6461.389  ops/s
c.w.factory.Benchmarks.useDefaultKotlinMapper      thrpt    9   749118.995 ±   2194.277  ops/s
c.w.factory.Benchmarks.useJavaMapper               thrpt    9  2873057.532 ± 142978.335  ops/s
c.w.factory.Benchmarks.useKotlinMapper             thrpt    9   820204.472 ±  32521.224  ops/s

Changes from #439

The class that was originally named Instantiator has been changed to ValueCreator.
Because the name Instantiator seemed to be confusing with the keyword derived from Jackson.

Also, the content that was originally defined as just an interface has been changed to a sealed class.
This makes it easier to standardize the process and improve the handling of conditional expressions.

Others

I don't think it's necessary to make it ExperimentalDeserializationBackend, since many of the changes are based on existing content.
Therefore, I have not incorporated the relevant changes.

Also, to keep the size of the PR small, I have not yet refactored the KVI.createFromObjectWith function, such as splitting it.
I plan to do that after this PR is merged.