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

Remove the Op API #113

Merged
merged 1 commit into from
Dec 21, 2023
Merged

Remove the Op API #113

merged 1 commit into from
Dec 21, 2023

Conversation

polytypic
Copy link
Collaborator

@polytypic polytypic commented Jul 25, 2023

This PR proposes to remove the Op or the low level multi-word compare-and-set (MCAS) API.

Why remove it?

It is typically much harder to program with the lower level MCAS API, because it basically requires you to manually

  • keep track of values read from locations,
  • create retry loops, and
  • use backoffs,

which are all taken care of for you when using the transactional API.

The Xt API also offers further conveniences and fundamental abilities like composability, nesting, blocking, and timeouts that are not supported by the Op API.

Having the Op API is probably an unnecessary distraction for most potential users.

Also, it is relatively easy to implement an Op like API using the Xt API:

type cas = CAS : 'a Loc.t * 'a * 'a -> cas

let rec casn ~xt = function
  | [] -> true
  | CAS (loc, before, after) :: ops ->
    if not (Xt.compare_and_set ~xt loc before after) then
      raise_notrace Exit;
    casn ~xt ops

let atomically ops =
  try Xt.commit { tx = casn ops } with Exit -> false

The overhead of the above is slightly higher than that of the direct Op implementation.

Note that above is different from the existing Op API, because the above allows multiple ops to update the same location, which is not allowed by the Op API. The behavior to reject such overlapping ops could be implemented using Xt.is_in_log at the cost of some additional overhead (which could also be asserts).

OTOH, the above kind of approach also opens the possibility of using some more advanced data structures to represent the ops instead of as just lists, which could allow more flexible and efficient composition of (such intermediate) ops.

It will likely also be possible to specialize the implementation better for transactions. Currently both the Op API and the Xt API share some implementation. After removing the Op API it might be possible to specialize the internal implementation for the Xt API and reduce overheads a little bit.

@polytypic polytypic requested a review from a team July 25, 2023 16:34
@polytypic polytypic force-pushed the remove-op-api branch 8 times, most recently from 96e5658 to 2e6b8e9 Compare August 9, 2023 11:20
@polytypic polytypic force-pushed the remove-op-api branch 2 times, most recently from 072751b to 7506211 Compare August 17, 2023 11:14
@polytypic polytypic force-pushed the remove-op-api branch 2 times, most recently from bb5ec1a to ab3aad5 Compare September 16, 2023 21:09
@polytypic polytypic force-pushed the remove-op-api branch 15 times, most recently from c782dd1 to dfd0e50 Compare December 9, 2023 21:13
@lyrm
Copy link

lyrm commented Dec 21, 2023

I also think that simplifying Kcas's API by removing the Op module is a good move.

Users that needs to chain operations should use the transactional API. It is less error prone and also way more powerful.

Also the 2 APIs (Op and Xt) are completely different so it does make Kcas less accessible in a way that users can loose time trying to use Op before understanding they need Xt and then they have a whole new API to get.

@polytypic polytypic merged commit e893629 into main Dec 21, 2023
2 of 3 checks passed
@polytypic polytypic deleted the remove-op-api branch December 21, 2023 18:41
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