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
STM - Next level #863
STM - Next level #863
Conversation
for { | ||
surplus <- IO.effectTotal { | ||
val as = unsafeOfferAll(queue, remaining.toList) | ||
unsafeCompleteTakers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add ()
otherwise dotty complains.
Nice simplification!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
def suspend(journal: Journal): Unit = { | ||
addTodo(txnId, journal, () => tryCommitAsync(null, platform, stm, txnId, done)(k)) | ||
|
||
if (isInvalid(journal)) tryCommit(platform, stm) match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is super clean, but I don't understand this line. Isn't it redundant with the line above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In between the time when the STM was executed and the "todo" was added, it may happen that the variables underlying the transaction have changed (by some other transaction), and the "todo" lists cleared by that transaction. In this case, the suspended transaction would never be retried. This line detects this case, and re-runs the transaction again if necessary.
This way of structuring the code allows dramatic minimization of the commit lock, albeit at the cost of trickier reasoning about correctness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yesterday I did a presentation of STM at the guardian, super psyched to start using it on our projects 🎉
A little light airplane coding to improve performance of STM, as well as Promise and Queue. A quick look at Queue reveals lots of low hanging fruit. STM is getting in good shape (performance competitive with and in some cases better than
Ref
+Promise
) but still needs some intelligence around overlapping retries.