[y-partyserver] Provider sends other clients' awareness back to the server
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
- 领域
- backend
调研方向
从 YProvider 中的 _awarenessUpdateHandler 开始,它是每次变化都会广播的 awareness 变更处理函数;同时查看以 provider 作为 origin 应用服务端更新的 awareness 消息处理函数。当 origin 是 provider 时添加提前返回,使客户端不会重新发送从服务端收到的更新。完成标准是:一个标签页中移动光标时发送一帧而不是 N 帧,并且其他标签页中仍能渲染远程光标。一个检查处理函数会跳过服务端来源更新的测试可以证明这一点。
由索引模型根据 Issue 内容生成。
描述
What happens
YProvider's awareness handler sends a message on every awareness change, whatever its origin:
this._awarenessUpdateHandler = ({ added, updated, removed }, _origin) => { /* … */ broadcastMessage(/* … */) };
Awareness updates from the server are applied with the provider as origin (applyAwarenessUpdate(provider.awareness, …, provider) in the awareness message handler), so each client sends every other client's change straight back. YServer already relays every awareness message to all connections, so with N clients one cursor move costs the server N incoming frames instead of 1. On Durable Objects each of them is an invocation: a billed request, and a log event when Workers Logs is on.
Measured
y-partyserver 2.2.0 (the handler is the same on main), 3 Chromium tabs on one document, frames counted by wrapping WebSocket.prototype.send:
| Now | With the fix below | |
|---|---|---|
| Cursor move (arrow key) in one tab | 3 frames | 1 |
| Keystroke, with Tiptap's CollaborationCaret | 10 | 4 (2 with ueberdosis/y-tiptap#55 fixed too) |
Remote cursors still render in every tab with the fix.
Suggested fix
this._awarenessUpdateHandler = ({ added, updated, removed }, origin) => {
if (origin === this) return; // from the server, which has already relayed it to everyone
// …
};
Every client only needs to receive each awareness update once; re-sending is allowed but not needed (Yjs's author on the same y-websocket behaviour: https://discuss.yjs.dev/t/redundant-messages/1062). Happy to open a PR with a test.
- 主要语言
- TypeScript
- 星标
- 1.3k
- 派生
- 84
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cloudflare/partykit 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
cloudflare/partykit#425 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
cloudflare/partykit#423 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
cloudflare/partykit#419 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
cloudflare/partykit#411 ·
-
[y-partyserver] provider.destroy() leaks reconnect timer, hanging Node processes and delaying GC未关闭
难度 2/5 1-3 小时 新手友好度 65/100
cloudflare/partykit#402 · 1 条评论 ·
查看 cloudflare/partykit 的全部 Issue
相似的 Issue
-
[Bug]: Pen taps on sidebar rows start a drag and lose their click可能已有人在做 @makhnatkin 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 70/100
b310-digital/teammapper#1515 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
puckeditor/puck#1884 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
outline/outline#14378 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
nicobailon/pi-web-access#642 ·
维护者通常 1 天内回复