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

Minor performance improvement in Free #776

Merged
merged 4 commits into from
Nov 24, 2016

Conversation

mpilquist
Copy link
Member

@mpilquist mpilquist commented Nov 24, 2016

This PR improves performance of Free by eagerly applying Bind(Pure(a), f) patterns in Free#step. We used to do this but it had the unfortunate side effect of evaluating suspends, because suspend is (still) implemented as pure(()) >> fa. This PR takes a conservative approach to fixing this issue by introducing a new flag on the Pure constructor, indicating whether or not eager evaluation is supported. Free.pure sets the flag to true whereas Free.suspend sets the flag to false.

The Free benchmarks show 18% - 42% increase:

a0aef44 (head of series/1.0)

[info] Benchmark                      Mode  Cnt   Score   Error  Units
[info] FreeBenchmark.nestedFlatMaps  thrpt   10  11.023 ± 1.311  ops/s
[info] FreeBenchmark.nestedMaps      thrpt   10   7.292 ± 1.810  ops/s

fa9aa99 (this PR)

info] Benchmark                      Mode  Cnt   Score   Error  Units
[info] FreeBenchmark.nestedFlatMaps  thrpt   10  13.660 ± 1.745  ops/s
[info] FreeBenchmark.nestedMaps      thrpt   10  10.412 ± 1.739  ops/s

The Stream benchmarks show a wider range of improvements -- the worse case is about equal (runLog_102400) and the best case shows a 330% improvement (awaitPull_256).

a0aef44 (head of series/1.0)

[info] Benchmark                                  Mode  Cnt    Score    Error  Units
[info] StreamBenchmark.awaitPull_256             thrpt   10   57.634 ±  8.218  ops/s
[info] StreamBenchmark.eval_102400               thrpt   10    0.616 ±  0.025  ops/s
[info] StreamBenchmark.leftAssocConcat_102400    thrpt   10    3.261 ±  0.448  ops/s
[info] StreamBenchmark.leftAssocFlatMap_102400   thrpt   10    9.509 ±  0.501  ops/s
[info] StreamBenchmark.rightAssocConcat_102400   thrpt   10    3.171 ±  0.409  ops/s
[info] StreamBenchmark.rightAssocFlatMap_102400  thrpt   10    8.579 ±  0.496  ops/s
[info] StreamBenchmark.runLog_102400             thrpt   10  770.429 ± 28.606  ops/s

fa9aa99 (this PR)

[info] Benchmark                                  Mode  Cnt    Score    Error  Units
[info] StreamBenchmark.awaitPull_256             thrpt   10  188.070 ± 16.577  ops/s
[info] StreamBenchmark.eval_102400               thrpt   10    1.443 ±  0.317  ops/s
[info] StreamBenchmark.leftAssocConcat_102400    thrpt   10    5.101 ±  0.323  ops/s
[info] StreamBenchmark.leftAssocFlatMap_102400   thrpt   10   12.276 ±  1.137  ops/s
[info] StreamBenchmark.rightAssocConcat_102400   thrpt   10    5.069 ±  0.568  ops/s
[info] StreamBenchmark.rightAssocFlatMap_102400  thrpt   10   12.130 ±  1.069  ops/s
[info] StreamBenchmark.runLog_102400             thrpt   10  767.122 ± 14.423  ops/s

I think we should merge this in order to establish a new baseline for performance, and then do the more extensive Free refactorings, like map fusion with type aligned sequences, after this version.

@pchiusano
Copy link
Contributor

pchiusano commented Nov 24, 2016 via email

@mpilquist
Copy link
Member Author

Benchmarks for the 2 minor commits today -- some minor improvements to raw Free benchmarks but about the same on Stream benchmarks:

3326944

[info] Benchmark                      Mode  Cnt   Score   Error  Units
[info] FreeBenchmark.nestedFlatMaps  thrpt   20  15.920 ± 1.165  ops/s
[info] FreeBenchmark.nestedMaps      thrpt   20  13.326 ± 2.023  ops/s
[info] Benchmark                                  Mode  Cnt    Score    Error  Units
[info] StreamBenchmark.awaitPull_256             thrpt   20  183.778 ±  3.760  ops/s
[info] StreamBenchmark.eval_102400               thrpt   20    1.478 ±  0.045  ops/s
[info] StreamBenchmark.leftAssocConcat_102400    thrpt   20    5.043 ±  0.304  ops/s
[info] StreamBenchmark.leftAssocFlatMap_102400   thrpt   20   12.832 ±  0.289  ops/s
[info] StreamBenchmark.rightAssocConcat_102400   thrpt   20    4.688 ±  0.447  ops/s
[info] StreamBenchmark.rightAssocFlatMap_102400  thrpt   20   12.375 ±  0.532  ops/s
[info] StreamBenchmark.runLog_102400             thrpt   20  767.376 ± 18.580  ops/s

@mpilquist mpilquist merged commit 3e40f17 into typelevel:series/1.0 Nov 24, 2016
@mpilquist mpilquist deleted the topic/free-eager-bind-pure branch November 27, 2017 12:42
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