Preliminary STM benchmarks and low-hanging fruit optimizations #769
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A few STM benchmarks and a variety of performance improvements, including:
provide
was dominating short-lived benchmarks due to the use of finalizers; now the top-level environment is "free")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)effect*
variantsensuringR
cost-free, which means it becameensuring
, which allowed elimination of environmental access inbracket
R
bracketExit
is now fast enough (no forking) it can be the sole implementationThere'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 ZIOSemaphore
; andTQueue
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-optimizedRef
+Promise
code.