-
Notifications
You must be signed in to change notification settings - Fork 179
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
Should the backend be Send + Sync? #75
Comments
Maybe a preferred use case is message passing rather than shared memory for this? I could imagine a wrapper around a backend with methods to push into channels and read from them. |
The That said, my preference would be for the message passing wrapper. Automerge is intended to be a foundational library so I don't think we should make decisions about what kind of performance is acceptable to users when we don't have to. I think the message passing wrapper makes sense in the case of using one backend for multiple frontends anyway because you'll still need to ship patches from individual changes off to each of the frontends on every change, so there will be additional glue code to write (I think, I haven't thought about this in detail). |
I've never done work with Rust and threads so Sync and Send are new to me. When I needed Now that said, this might be a good time to think about the right time to design this so we can move cleanly into Sync Send terratory. I could remove all the Rc's and automerge would work fine - the reason I put them in there was facilitate fast forks and memory efficient backends with common ancestry. Is it important for us to be able to fork a backend and then send the fork to another thread? If so the changes need mutexes or to be copied. I wonder how much Rc->Arc would affect performance in WASM given that its single threaded. Is the compiler smart enough to reduce one to the other. I should run some benchmarks and find out. Option 1: axe all the Rc's and deal with fast forking another day or What do you think? |
That PR deals with Option 1, just an option though. I'm not sure what you mean by forking in an automerge document as no forking seems to be implemented, unless you mean just cloning a backend? How common is it to fork a backend? |
Sorry - the action got renamed to |
Given the ideas proposing to have a single backend with multiple frontends I think it would make sense for the backend to be
Send
+Sync
. This means we could send a backend across threads as well as use it in shared memory settings with, for example, aMutex
. I can see this being particularly useful for server implementations in Rust where clients for a document may not always land on the same thread.Basically this comes down to replacing instances of
Rc
with eitherArc
or removing them if they aren't necessary. Also we'd need to switch fromim_rc
toim
which has a minor performance penalty I believe.I'm not sure of the impact of this on wasm but think it should still work the same. I've got an example branch of this here
The text was updated successfully, but these errors were encountered: