Upstream Improvements
1. Expose set_actor in automerge WASM bindings (automerge/automerge)
The Rust automerge crate has doc.set_actor(ActorId) — a single field assignment with no allocation or copying. But the WASM bindings (automerge_wasm_bg.js) don't expose it. The only way to change the actor from JS is Automerge.clone(doc, { actor }), which copies the entire document.
Adding setActor(actor: string) to the WASM Automerge class is a one-line binding to the existing Rust method. The JS layer would then expose it as Automerge.setActorId(doc, actorId) or similar. This would let us replace:
// Current: clone entire document to change one field
handle.update(doc => Automerge.clone(doc, { actor: actorId }))
// With set_actor exposed: mutate in place, no allocation
handle.update(doc => { Automerge.setActorId(doc, actorId); return doc })
Priority: low. The clone is safe (no sync side-effects, old doc is GC'd) and cheap for our document sizes. But it's the right fix long-term.
2. Add actor option to Repo.create() / Repo.find() (automerge/automerge-repo)
Ideally, Repo.create() and Repo.find() would natively accept an actor option:
repo.create<T>({ actor: hexActorId })
repo.find<T>(docId, { actor: hexActorId })
This would eliminate the update+clone workaround and all its downsides:
- Noise in history:
create() writes one change with a random actor before the clone switches to the real one. That random actor is permanently baked into the document.
- Performance:
Automerge.clone() copies the entire document just to change the actor ID.
Migration would be straightforward — update the createDoc/findDoc helpers to pass the native actor option and remove applyActorId.
Upstream Improvements
1. Expose
set_actorin automerge WASM bindings (automerge/automerge)The Rust
automergecrate hasdoc.set_actor(ActorId)— a single field assignment with no allocation or copying. But the WASM bindings (automerge_wasm_bg.js) don't expose it. The only way to change the actor from JS isAutomerge.clone(doc, { actor }), which copies the entire document.Adding
setActor(actor: string)to the WASMAutomergeclass is a one-line binding to the existing Rust method. The JS layer would then expose it asAutomerge.setActorId(doc, actorId)or similar. This would let us replace:Priority: low. The clone is safe (no sync side-effects, old doc is GC'd) and cheap for our document sizes. But it's the right fix long-term.
2. Add
actoroption toRepo.create()/Repo.find()(automerge/automerge-repo)Ideally,
Repo.create()andRepo.find()would natively accept anactoroption:This would eliminate the
update+cloneworkaround and all its downsides:create()writes one change with a random actor before the clone switches to the real one. That random actor is permanently baked into the document.Automerge.clone()copies the entire document just to change the actor ID.Migration would be straightforward — update the
createDoc/findDochelpers to pass the nativeactoroption and removeapplyActorId.