Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mijicd
Copy link
Member

@mijicd mijicd commented Apr 16, 2020

Summary

  • Exposed unsafe getter and setter to avoid building large transactions.
  • Ported "core" operations of TMap to use the unsafe functions.
  • Fixed long-standing issue with improper size count in transformations and retains (i.e. removals weren't decreasing map's size).

Benchmark results

Baseline

Benchmark                     (size)   Mode  Cnt       Score      Error  Units
TMapOpsBenchmarks.fold             0  thrpt   15  258658.256 ± 8415.195  ops/s
TMapOpsBenchmarks.fold            10  thrpt   15  184811.477 ± 1966.108  ops/s
TMapOpsBenchmarks.fold           100  thrpt   15   22520.429 ±   76.867  ops/s
TMapOpsBenchmarks.fold          1000  thrpt   15    2396.229 ±    6.618  ops/s
TMapOpsBenchmarks.fold         10000  thrpt   15     109.687 ±    1.259  ops/s
TMapOpsBenchmarks.fold        100000  thrpt   15       6.887 ±    0.156  ops/s
TMapOpsBenchmarks.foldM            0  thrpt   15  281237.383 ± 9172.810  ops/s
TMapOpsBenchmarks.foldM           10  thrpt   15  165526.805 ± 2169.245  ops/s
TMapOpsBenchmarks.foldM          100  thrpt   15   19590.089 ±  120.782  ops/s
TMapOpsBenchmarks.foldM         1000  thrpt   15    1929.585 ±    5.396  ops/s
TMapOpsBenchmarks.foldM        10000  thrpt   15     100.054 ±    3.493  ops/s
TMapOpsBenchmarks.foldM       100000  thrpt   15       5.975 ±    0.102  ops/s
TMapOpsBenchmarks.lookup           0  thrpt   15    5072.946 ±   19.131  ops/s
TMapOpsBenchmarks.lookup          10  thrpt   15    5172.095 ±   20.090  ops/s
TMapOpsBenchmarks.lookup         100  thrpt   15    4838.867 ±   66.883  ops/s
TMapOpsBenchmarks.lookup        1000  thrpt   15    4963.935 ±    7.921  ops/s
TMapOpsBenchmarks.lookup       10000  thrpt   15    4845.461 ±   19.562  ops/s
TMapOpsBenchmarks.lookup      100000  thrpt   15    4592.221 ±   28.704  ops/s
TMapOpsBenchmarks.removal          0  thrpt   15    3566.088 ±   47.642  ops/s
TMapOpsBenchmarks.removal         10  thrpt   15    3588.899 ±   15.633  ops/s
TMapOpsBenchmarks.removal        100  thrpt   15    3510.764 ±   11.459  ops/s
TMapOpsBenchmarks.removal       1000  thrpt   15    3446.854 ±   13.075  ops/s
TMapOpsBenchmarks.removal      10000  thrpt   15    3431.371 ±    8.108  ops/s
TMapOpsBenchmarks.removal     100000  thrpt   15    3169.424 ±    6.962  ops/s
TMapOpsBenchmarks.transform        0  thrpt   15  148985.179 ± 3818.584  ops/s
TMapOpsBenchmarks.transform       10  thrpt   15  118974.349 ± 2685.904  ops/s
TMapOpsBenchmarks.transform      100  thrpt   15   15679.842 ±   42.883  ops/s
TMapOpsBenchmarks.transform     1000  thrpt   15    1839.234 ±   22.481  ops/s
TMapOpsBenchmarks.transform    10000  thrpt   15      96.660 ±    0.992  ops/s
TMapOpsBenchmarks.transform   100000  thrpt   15       7.093 ±    0.112  ops/s
TMapOpsBenchmarks.transformM       0  thrpt   15  144693.581 ± 4076.923  ops/s
TMapOpsBenchmarks.transformM      10  thrpt   15   97583.697 ± 1395.881  ops/s
TMapOpsBenchmarks.transformM     100  thrpt   15   11675.240 ±   85.219  ops/s
TMapOpsBenchmarks.transformM    1000  thrpt   15    1237.373 ±    3.750  ops/s
TMapOpsBenchmarks.transformM   10000  thrpt   15      74.736 ±    1.810  ops/s
TMapOpsBenchmarks.transformM  100000  thrpt   15       5.120 ±    0.080  ops/s
TMapOpsBenchmarks.update           0  thrpt   15    2839.403 ±   16.044  ops/s
TMapOpsBenchmarks.update          10  thrpt   15    2813.640 ±   10.368  ops/s
TMapOpsBenchmarks.update         100  thrpt   15    2775.875 ±   16.918  ops/s
TMapOpsBenchmarks.update        1000  thrpt   15    2664.176 ±    8.966  ops/s
TMapOpsBenchmarks.update       10000  thrpt   15    2618.346 ±   24.823  ops/s
TMapOpsBenchmarks.update      100000  thrpt   15    2507.069 ±    7.912  ops/s

After changes

Benchmark                     (size)   Mode  Cnt       Score      Error  Units
TMapOpsBenchmarks.fold             0  thrpt   15  453075.353 ± 40158.142  ops/s
TMapOpsBenchmarks.fold            10  thrpt   15  466036.345 ± 28409.890  ops/s
TMapOpsBenchmarks.fold           100  thrpt   15  117445.461 ±  5509.826  ops/s
TMapOpsBenchmarks.fold          1000  thrpt   15   10204.907 ±   119.298  ops/s
TMapOpsBenchmarks.fold         10000  thrpt   15     444.492 ±     2.090  ops/s
TMapOpsBenchmarks.fold        100000  thrpt   15      14.910 ±     0.195  ops/s
TMapOpsBenchmarks.foldM            0  thrpt   15  446625.903 ± 19701.058  ops/s
TMapOpsBenchmarks.foldM           10  thrpt   15  357212.426 ± 13035.195  ops/s
TMapOpsBenchmarks.foldM          100  thrpt   15   73962.405 ±   949.968  ops/s
TMapOpsBenchmarks.foldM         1000  thrpt   15    3973.816 ±    67.446  ops/s
TMapOpsBenchmarks.foldM        10000  thrpt   15     251.758 ±     8.018  ops/s
TMapOpsBenchmarks.foldM       100000  thrpt   15      10.186 ±     0.290  ops/s
TMapOpsBenchmarks.lookup           0  thrpt   15    7539.692 ±   219.089  ops/s
TMapOpsBenchmarks.lookup          10  thrpt   15    7097.233 ±   618.017  ops/s
TMapOpsBenchmarks.lookup         100  thrpt   15    6989.644 ±   239.299  ops/s
TMapOpsBenchmarks.lookup        1000  thrpt   15    6644.971 ±   302.264  ops/s
TMapOpsBenchmarks.lookup       10000  thrpt   15    6633.660 ±   506.379  ops/s
TMapOpsBenchmarks.lookup      100000  thrpt   15    6704.438 ±   117.688  ops/s
TMapOpsBenchmarks.removal          0  thrpt   15    7290.187 ±    85.447  ops/s
TMapOpsBenchmarks.removal         10  thrpt   15    6780.488 ±   435.156  ops/s
TMapOpsBenchmarks.removal        100  thrpt   15    6769.002 ±   134.779  ops/s
TMapOpsBenchmarks.removal       1000  thrpt   15    6599.726 ±   153.399  ops/s
TMapOpsBenchmarks.removal      10000  thrpt   15    6463.428 ±   292.316  ops/s
TMapOpsBenchmarks.removal     100000  thrpt   15    6112.141 ±   164.800  ops/s
TMapOpsBenchmarks.transform        0  thrpt   15  375231.111 ± 27563.383  ops/s
TMapOpsBenchmarks.transform       10  thrpt   15  349838.787 ± 21146.626  ops/s
TMapOpsBenchmarks.transform      100  thrpt   15   71206.680 ±  3216.900  ops/s
TMapOpsBenchmarks.transform     1000  thrpt   15    6076.747 ±    47.607  ops/s
TMapOpsBenchmarks.transform    10000  thrpt   15     286.026 ±     8.112  ops/s
TMapOpsBenchmarks.transform   100000  thrpt   15       8.128 ±     0.401  ops/s
TMapOpsBenchmarks.transformM       0  thrpt   15  334663.030 ± 30279.356  ops/s
TMapOpsBenchmarks.transformM      10  thrpt   15  203145.741 ±  7010.873  ops/s
TMapOpsBenchmarks.transformM     100  thrpt   15   26613.363 ±  1053.412  ops/s
TMapOpsBenchmarks.transformM    1000  thrpt   15    2323.504 ±    47.515  ops/s
TMapOpsBenchmarks.transformM   10000  thrpt   15     145.296 ±     3.139  ops/s
TMapOpsBenchmarks.transformM  100000  thrpt   15       7.012 ±     0.257  ops/s
TMapOpsBenchmarks.update           0  thrpt   15    6128.393 ±   108.275  ops/s
TMapOpsBenchmarks.update          10  thrpt   15    5964.803 ±   223.273  ops/s
TMapOpsBenchmarks.update         100  thrpt   15    6029.006 ±   189.209  ops/s
TMapOpsBenchmarks.update        1000  thrpt   15    5588.270 ±   335.644  ops/s
TMapOpsBenchmarks.update       10000  thrpt   15    5380.730 ±   370.549  ops/s
TMapOpsBenchmarks.update      100000  thrpt   15    5459.173 ±   191.180  ops/s

Further steps

  • Optimize TArray's operations.
  • Improve contention benchmark, a.k.a. TRef vs TMap. This PR significantly improves numbers for TMap, but I still suspect these are a bit misleading, and I'd like to spend some time on that benchmark.

@mijicd mijicd requested a review from jdegoes April 16, 2020 15:00
val length = in.length
var idx = 0

var tx: ZSTM[R, E, ChunkBuilder[B]] = ZSTM.succeedNow(ChunkBuilder.make[B])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're allocating memory in a pure function, which is a no-no. So we have to make sure this is suspended in STM. I'd add a top-level STM wrapper (new STM) to make sure this function becomes referentially transparent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed via ZSTM.suspend.

Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phenomenal work! Just one minor change and then after the tests pass, will be good to merge!

@jdegoes jdegoes merged commit 18482bc into zio:master Apr 16, 2020
@jdegoes
Copy link
Member

jdegoes commented Apr 16, 2020

🎉 🕺

@mijicd mijicd deleted the stm-optimization branch April 16, 2020 22:08
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