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

Memorize JSON decoders and encoders #759

Merged
merged 7 commits into from
Dec 30, 2024

Conversation

plokhotnyuk
Copy link
Contributor

@plokhotnyuk plokhotnyuk commented Dec 27, 2024

DO NOT MERGE: it throws a stack overflow error on recursive schemas.

  • Memorize JSON decoders and encoders and reuse them instead of re-instantiation
  • Use alias support of StringMatrix for faster parsing and to reduce in-memory footprint of decoders
  • Clean-up implementation of decoders and encoders for more efficiency in runtime
  • Fix missing 'sbt' command error in GitHub builds for CI and Site

Below are results of benchmarks for real-world message samples using JDK-21 on Intel® Core™ i7-11800H CPU @ 2.3GHz (max 4.6GHz)

Scala 2

Before:

Benchmark                                   Mode  Cnt       Score      Error  Units
GeoJSONReading.zioJson                     thrpt    5    8217.916 ±  708.956  ops/s
GeoJSONReading.zioSchemaJson               thrpt    5   10507.115 ±  308.261  ops/s
GeoJSONWriting.zioJson                     thrpt    5   12001.465 ±  409.730  ops/s
GeoJSONWriting.zioSchemaJson               thrpt    5   15176.798 ±  196.928  ops/s
GitHubActionsAPIReading.zioJson            thrpt    5  245106.646 ± 7744.851  ops/s
GitHubActionsAPIReading.zioSchemaJson      thrpt    5   41738.776 ± 1074.233  ops/s
GitHubActionsAPIWriting.zioJson            thrpt    5  342150.155 ± 7673.760  ops/s
GitHubActionsAPIWriting.zioSchemaJson      thrpt    5  239500.965 ± 3512.695  ops/s
GoogleMapsAPIPrettyPrinting.zioJson        thrpt    5   18351.638 ±  333.036  ops/s
GoogleMapsAPIPrettyPrinting.zioSchemaJson  thrpt    5   11930.878 ±  448.838  ops/s
GoogleMapsAPIReading.zioJson               thrpt    5   13826.638 ±  386.772  ops/s
GoogleMapsAPIReading.zioSchemaJson         thrpt    5    2574.584 ±  104.790  ops/s
GoogleMapsAPIWriting.zioJson               thrpt    5   25483.571 ± 1000.546  ops/s
GoogleMapsAPIWriting.zioSchemaJson         thrpt    5   15409.999 ±  173.149  ops/s

After:

Benchmark                                   Mode  Cnt       Score      Error  Units
GeoJSONReading.zioJson                     thrpt    5    8515.127 ±   82.259  ops/s
GeoJSONReading.zioSchemaJson               thrpt    5   11958.660 ±  538.961  ops/s
GeoJSONWriting.zioJson                     thrpt    5   12041.345 ± 1218.311  ops/s
GeoJSONWriting.zioSchemaJson               thrpt    5   15704.919 ±  395.445  ops/s
GitHubActionsAPIReading.zioJson            thrpt    5  227472.192 ± 6402.040  ops/s
GitHubActionsAPIReading.zioSchemaJson      thrpt    5  221879.461 ± 1932.287  ops/s
GitHubActionsAPIWriting.zioJson            thrpt    5  335536.111 ± 4429.710  ops/s
GitHubActionsAPIWriting.zioSchemaJson      thrpt    5  328997.358 ± 5657.510  ops/s
GoogleMapsAPIPrettyPrinting.zioJson        thrpt    5   17538.264 ±  152.789  ops/s
GoogleMapsAPIPrettyPrinting.zioSchemaJson  thrpt    5   16875.654 ±  706.970  ops/s
GoogleMapsAPIReading.zioJson               thrpt    5   13809.736 ±  255.612  ops/s
GoogleMapsAPIReading.zioSchemaJson         thrpt    5   14034.516 ±  184.394  ops/s
GoogleMapsAPIWriting.zioJson               thrpt    5   26385.957 ±  511.136  ops/s
GoogleMapsAPIWriting.zioSchemaJson         thrpt    5   25622.675 ±  263.302  ops/s

Scala 3

Before:

Benchmark                                   Mode  Cnt       Score      Error  Units
GeoJSONReading.zioJson                     thrpt    5    8056.478 ±   48.752  ops/s
GeoJSONWriting.zioJson                     thrpt    5   11507.007 ±   72.053  ops/s
GeoJSONWriting.zioSchemaJson               thrpt    5   13423.758 ±  157.252  ops/s
GitHubActionsAPIReading.zioJson            thrpt    5  280990.914 ± 7652.044  ops/s
GitHubActionsAPIReading.zioSchemaJson      thrpt    5   25057.913 ± 1195.442  ops/s
GitHubActionsAPIWriting.zioJson            thrpt    5  361023.783 ± 7934.218  ops/s
GitHubActionsAPIWriting.zioSchemaJson      thrpt    5   53048.311 ± 1703.869  ops/s
GoogleMapsAPIPrettyPrinting.zioJson        thrpt    5   18976.670 ±  269.471  ops/s
GoogleMapsAPIPrettyPrinting.zioSchemaJson  thrpt    5    2474.936 ±   50.427  ops/s
GoogleMapsAPIReading.zioJson               thrpt    5   17260.998 ±  643.725  ops/s
GoogleMapsAPIReading.zioSchemaJson         thrpt    5    1260.880 ±   23.826  ops/s
GoogleMapsAPIWriting.zioJson               thrpt    5   27803.223 ±  805.158  ops/s
GoogleMapsAPIWriting.zioSchemaJson         thrpt    5    2483.574 ±   44.469  ops/s

After:

Benchmark                                   Mode  Cnt       Score       Error  Units
GeoJSONReading.zioJson                     thrpt    5    8158.757 ±    87.620  ops/s
GeoJSONWriting.zioJson                     thrpt    5   11547.910 ±   180.709  ops/s
GeoJSONWriting.zioSchemaJson               thrpt    5   15076.344 ±   247.426  ops/s
GitHubActionsAPIReading.zioJson            thrpt    5  273058.111 ±  2292.523  ops/s
GitHubActionsAPIReading.zioSchemaJson      thrpt    5  278277.146 ±  5317.096  ops/s
GitHubActionsAPIWriting.zioJson            thrpt    5  361939.297 ± 10258.167  ops/s
GitHubActionsAPIWriting.zioSchemaJson      thrpt    5  347101.131 ±  4593.115  ops/s
GoogleMapsAPIPrettyPrinting.zioJson        thrpt    5   19383.008 ±   412.298  ops/s
GoogleMapsAPIPrettyPrinting.zioSchemaJson  thrpt    5   19033.172 ±   640.325  ops/s
GoogleMapsAPIReading.zioJson               thrpt    5   16833.435 ±   528.396  ops/s
GoogleMapsAPIReading.zioSchemaJson         thrpt    5   19597.635 ±   881.126  ops/s
GoogleMapsAPIWriting.zioJson               thrpt    5   27674.151 ±   590.001  ops/s
GoogleMapsAPIWriting.zioSchemaJson         thrpt    5   24819.837 ±   653.172  ops/s

@plokhotnyuk plokhotnyuk requested a review from a team as a code owner December 27, 2024 16:22
@plokhotnyuk plokhotnyuk force-pushed the add-json-decoder-encoder-memorization branch from a8e7dd0 to f8c45ab Compare December 27, 2024 16:31
@plokhotnyuk plokhotnyuk force-pushed the add-json-decoder-encoder-memorization branch 2 times, most recently from 8030723 to 0920453 Compare December 30, 2024 10:29
@jdegoes jdegoes merged commit 7097284 into zio:main Dec 30, 2024
26 checks passed
@plokhotnyuk plokhotnyuk deleted the add-json-decoder-encoder-memorization branch December 30, 2024 14:32
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.

2 participants