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

Preliminary STM benchmarks and low-hanging fruit optimizations #769

Merged
merged 11 commits into from Apr 18, 2019

Conversation

jdegoes
Copy link
Member

@jdegoes jdegoes commented Apr 16, 2019

A few STM benchmarks and a variety of performance improvements, including:

  • Addressing performance regression caused by ZIO environment (the cost of provide was dominating short-lived benchmarks due to the use of finalizers; now the top-level environment is "free")
  • Refactored STM to use java.util.HashMap, mainly because it is easier to minimize allocations compared to Scala's mutable map (iteration through a Scala map will always allocate tuples)
  • Introduced specializations for effect* variants
  • Make ensuringR cost-free, which means it became ensuring, which allowed elimination of environmental access in bracket
  • As a result of other cost-free changes, made more operators polymorphic in R
  • bracketExit is now fast enough (no forking) it can be the sole implementation

There's much more work to be done, but the runtime system is generating very clean, allocation-free code; STM has been through "first-pass" optimization; and overall, things are looking cleaner and more uniform thanks to the cost-free refactorings.

The main learning of STM benchmarks is that TSemaphore is as fast as the hand-written ZIO Semaphore; and TQueue is as fast as FS2 Queue in parallel access, although only 50% as fast in two other scenarios. With further optimization, it seems likely STM can produce performance competitive with hand-written, hand-optimized Ref + Promise code.

Copy link
Contributor

@wi101 wi101 left a comment

Choose a reason for hiding this comment

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

Looks great!

@jdegoes jdegoes merged commit 4506dca into zio:master Apr 18, 2019
Dan-M added a commit to Dan-M/scalaz-zio that referenced this pull request Apr 21, 2019
* upstream/master:
  Preliminary STM benchmarks and low-hanging fruit optimizations (zio#769)
ghostdogpr pushed a commit to ghostdogpr/scalaz-zio that referenced this pull request May 5, 2019
* Preliminary STM benchmarks & easy opts

* fmt

* Cleanup & fix benchmarks

* Optimization

* Add new tests of new constructors

* Delete ensuringR (not req'd) & propagate to bracket

* Fix todo (make provide interrupt-safe)

* Remove todo

* Update microsite

* Moar R polymorphism
@t5kaji t5kaji mentioned this pull request Jul 28, 2019
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.

None yet

2 participants