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

Allow encoding awareness values as binary in updates #26

Open
Myrannas opened this issue Mar 30, 2023 · 2 comments
Open

Allow encoding awareness values as binary in updates #26

Myrannas opened this issue Mar 30, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@Myrannas
Copy link

Myrannas commented Mar 30, 2023

y-protocols/awareness currently encodes updates using a combination of writeVarString and JSON.stringify today.

The codebase I am working on uses a decent amount of single precision floating point numbers in awareness, and so would benefit from binary encoding. My understanding is that lib0 can encode arbitrary structures as binary using the writeAny method (used in yjs).

Backwards compatibility may be a little difficult with introducing binary encoding, as old clients would expect a JSON stringified value. To allow users of the library to control the rollout, it might be possible to introduce similar functionality to how YJS supports V1 and V2 updates - where an encoder is passed in as a parameter (with a default value).

For example:

class AwarenessEncoderV1 {
  encodeAwareness(state, encoder) {
    encoding.writeVarString(encoder, JSON.stringify(state));
  }
}

...

export const applyAwarenessUpdate = (awareness, update, origin, encoder = new AwarenessEncoderV1()) => { ... }

Would you be open to accepting a contribution with these changes?

@Myrannas Myrannas added the enhancement New feature or request label Mar 30, 2023
@dmonad
Copy link
Member

dmonad commented Mar 30, 2023

Hi @Myrannas,

I'm not sure if this is worth the trouble right now.

FYI: We are experimenting with several ideas to replace the current (extremely simple) Awareness CRDT. A v2 based on any-encoding would only slightly decrease the size of messages in most cases (Awareness is mainly used for syncing small updates like cursor positions and user names).

I'd accept a PR that adds the suggested optional parameter for a custom Awareness encoder. At this time, I'd not accept a PR that switches the default awareness protocol for a (slightly improved) v2 encoder. I don't think it's worth the trouble to switch the protocol right now. We are currently trying to maintain compatibility with the y-crdt project. I'd like to wait for a much-improved Awareness implementation before we change the default protocol.

@Myrannas
Copy link
Author

Thanks for the heads up!

Makes sense for a lot of teams it may not make a large difference. For my use case, we anticipate this would make a large difference as we are using it to share some information like the current selection state (which can be 1000s of items).

I'll prepare a PR that would allow for a custom encoder, but leave the default as is.

Is there anywhere to read about the improved awareness implementation? I'd love to see what the plan is for that.

Myrannas pushed a commit to Myrannas/y-protocols that referenced this issue Mar 31, 2023
…xported encoding and decoding methods, and add a binary encoding strategy.
Myrannas pushed a commit to Myrannas/y-protocols that referenced this issue Mar 31, 2023
…xported encoding and decoding methods, and add a binary encoding strategy.
Myrannas pushed a commit to Myrannas/y-protocols that referenced this issue Mar 31, 2023
…xported encoding and decoding methods, and add a binary encoding strategy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants