Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize and Refactor KotlinValueInstantiator.createFromObjectWith #687

Merged
merged 4 commits into from
Jul 15, 2023

Conversation

k163377
Copy link
Contributor

@k163377 k163377 commented Jul 15, 2023

Optimized various checks on paramVal.

  • Null check of paramVal is done only once
  • Skip MismatchedInput check when paramVal is non-null
  • Skip strictNullCheck for empty collections completed by requireEmptyValue
  • Modified isGenericTypeVar to be determined at the last(relates to Reflection overhead #310)

These changes are expected to improve deserialization performance.

In addition, several refactors were made to improve readability.


This optimization was ported from jackson-module-kogera.
https://github.com/ProjectMapK/jackson-module-kogera/blob/ca6bfe5a1689ebef4dff795ae21ccbe7ca0248df/src/main/kotlin/io/github/projectmapk/jackson/module/kogera/deser/value_instantiator/KotlinValueInstantiator.kt#L64-L79C14

- Changed so that null check of paramVal is done only once
- Skip MismatchedInput check when paramVal is non-null
- Skip strictNullCheck for empty collections completed by requireEmptyValue
@k163377 k163377 force-pushed the feat/refactor-valueinstantiator branch from e57dd11 to e6fe727 Compare July 15, 2023 15:42
@k163377 k163377 merged commit 4bd4845 into FasterXML:2.16 Jul 15, 2023
@k163377 k163377 mentioned this pull request Jul 15, 2023
@k163377 k163377 deleted the feat/refactor-valueinstantiator branch July 15, 2023 16:24
@k163377
Copy link
Contributor Author

k163377 commented Jul 17, 2023

Comparison of benchmark results.
https://github.com/ProjectMapK/kogera-benchmark

The score for no default argument (no _default in the name) is improved, especially since there are fewer unnecessary checks when the argument is nonnull.
1.38x for 5-argument constructors and 1.42x for 20-argument constructors.

2.15.2

Benchmark                                                    Mode  Cnt        Score        Error  Units
o.w.extra.deser.Collections.array                           thrpt    4   632178.940 ±  62245.856  ops/s
o.w.extra.deser.Collections.list                            thrpt    4   667036.369 ±  19188.400  ops/s
o.w.extra.deser.Collections.map                             thrpt    4   451129.135 ± 104692.358  ops/s
o.w.extra.deser.wrapper.A_1Props_Constructor.call           thrpt    4   922550.390 ±  61783.797  ops/s
o.w.extra.deser.wrapper.A_1Props_Constructor.call_default   thrpt    4   465611.927 ±   5009.255  ops/s
o.w.extra.deser.wrapper.A_1Props_Function.call              thrpt    4   589765.566 ±  17162.595  ops/s
o.w.extra.deser.wrapper.A_1Props_Function.call_default      thrpt    4   393881.907 ± 134149.714  ops/s
o.w.extra.deser.wrapper.E_5Props_Constructor.call           thrpt    4   368225.002 ±   5881.920  ops/s
o.w.extra.deser.wrapper.E_5Props_Constructor.call_default   thrpt    4   188749.023 ±  37037.545  ops/s
o.w.extra.deser.wrapper.E_5Props_Function.call              thrpt    4   249229.020 ±  35884.608  ops/s
o.w.extra.deser.wrapper.E_5Props_Function.call_default      thrpt    4   181385.096 ±  16514.633  ops/s
o.w.extra.deser.wrapper.T_20Props_Constructor.call          thrpt    4   108650.605 ±  12030.540  ops/s
o.w.extra.deser.wrapper.T_20Props_Constructor.call_default  thrpt    4    60044.770 ±  14198.114  ops/s
o.w.extra.deser.wrapper.T_20Props_Function.call             thrpt    4    78049.482 ±   9220.824  ops/s
o.w.extra.deser.wrapper.T_20Props_Function.call_default     thrpt    4    57743.133 ±  13174.738  ops/s
o.w.main.deser.A_1Props_Constructor.call                    thrpt    4   905299.043 ± 171740.844  ops/s
o.w.main.deser.A_1Props_Constructor.call_default            thrpt    4   459963.596 ±  11314.047  ops/s
o.w.main.deser.A_1Props_Function.call                       thrpt    4   581911.821 ± 116910.948  ops/s
o.w.main.deser.A_1Props_Function.call_default               thrpt    4   410564.308 ±  92110.673  ops/s
o.w.main.deser.E_5Props_Constructor.call                    thrpt    4   375518.970 ±  45620.235  ops/s
o.w.main.deser.E_5Props_Constructor.call_default            thrpt    4   188502.131 ±  18832.117  ops/s
o.w.main.deser.E_5Props_Function.call                       thrpt    4   251917.163 ±  24952.497  ops/s
o.w.main.deser.E_5Props_Function.call_default               thrpt    4   174505.158 ±  54319.444  ops/s
o.w.main.deser.T_20Props_Constructor.call                   thrpt    4   118543.101 ±    886.087  ops/s
o.w.main.deser.T_20Props_Constructor.call_default           thrpt    4    55088.109 ±   8251.193  ops/s
o.w.main.deser.T_20Props_Function.call                      thrpt    4    77837.276 ±   4960.774  ops/s
o.w.main.deser.T_20Props_Function.call_default              thrpt    4    57402.649 ±  11043.743  ops/s

4bd484

Benchmark                                                    Mode  Cnt        Score         Error  Units
o.w.extra.deser.Collections.array                           thrpt    4   709625.513 ±   84047.924  ops/s
o.w.extra.deser.Collections.list                            thrpt    4   740316.578 ±    9947.498  ops/s
o.w.extra.deser.Collections.map                             thrpt    4   470609.756 ±  153569.244  ops/s
o.w.extra.deser.wrapper.A_1Props_Constructor.call           thrpt    4  1030100.252 ±  225109.864  ops/s
o.w.extra.deser.wrapper.A_1Props_Constructor.call_default   thrpt    4   443397.768 ±   98136.233  ops/s
o.w.extra.deser.wrapper.A_1Props_Function.call              thrpt    4   650006.003 ±   37686.335  ops/s
o.w.extra.deser.wrapper.A_1Props_Function.call_default      thrpt    4   390431.341 ±  176945.191  ops/s
o.w.extra.deser.wrapper.E_5Props_Constructor.call           thrpt    4   485056.381 ±   33810.825  ops/s
o.w.extra.deser.wrapper.E_5Props_Constructor.call_default   thrpt    4   185649.225 ±   26400.644  ops/s
o.w.extra.deser.wrapper.E_5Props_Function.call              thrpt    4   288919.466 ±   65699.654  ops/s
o.w.extra.deser.wrapper.E_5Props_Function.call_default      thrpt    4   180391.522 ±   62270.190  ops/s
o.w.extra.deser.wrapper.T_20Props_Constructor.call          thrpt    4   157982.945 ±    9446.212  ops/s
o.w.extra.deser.wrapper.T_20Props_Constructor.call_default  thrpt    4    57935.431 ±   21145.934  ops/s
o.w.extra.deser.wrapper.T_20Props_Function.call             thrpt    4    96686.421 ±    2930.914  ops/s
o.w.extra.deser.wrapper.T_20Props_Function.call_default     thrpt    4    57681.886 ±   14776.246  ops/s
o.w.main.deser.A_1Props_Constructor.call                    thrpt    4  1061930.180 ±   76134.431  ops/s
o.w.main.deser.A_1Props_Constructor.call_default            thrpt    4   462015.108 ±   67246.314  ops/s
o.w.main.deser.A_1Props_Function.call                       thrpt    4   644780.174 ±   39590.943  ops/s
o.w.main.deser.A_1Props_Function.call_default               thrpt    4   407588.615 ±   28888.307  ops/s
o.w.main.deser.E_5Props_Constructor.call                    thrpt    4   518419.225 ±   37713.180  ops/s
o.w.main.deser.E_5Props_Constructor.call_default            thrpt    4   196644.413 ±   22016.926  ops/s
o.w.main.deser.E_5Props_Function.call                       thrpt    4   304336.379 ±   14271.245  ops/s
o.w.main.deser.E_5Props_Function.call_default               thrpt    4   182563.904 ±   18759.374  ops/s
o.w.main.deser.T_20Props_Constructor.call                   thrpt    4   168907.082 ±   24194.241  ops/s
o.w.main.deser.T_20Props_Constructor.call_default           thrpt    4    56676.873 ±   14807.320  ops/s
o.w.main.deser.T_20Props_Function.call                      thrpt    4   102733.105 ±    4844.048  ops/s
o.w.main.deser.T_20Props_Function.call_default              thrpt    4    56738.995 ±    6578.376  ops/s

k163377 added a commit to k163377/jackson-module-kotlin that referenced this pull request Jul 17, 2023
Added reference to the amount of improvement.
k163377 added a commit that referenced this pull request Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant