googlefonts / fontra

A browser-based font editor
https://fontra.xyz
GNU General Public License v3.0
494 stars 21 forks source link

A simple optimistic auto-locking scheme #20

Open justvanrossum opened 2 years ago

justvanrossum commented 2 years ago

Adjacent to #19, here is the outline of a simple auto-locking scheme.

The idea is that we assume a glyph is unlocked/editabe, expecting this to be the common case by far, and simply go ahead with an edit (say, drag some points). But it will stop an edit-in-progress once the system finds out it is already being edited by someone else. I would like multiple clients to be able to have a glyph in "edit mode", so I don't want to tie glyph locking to the edit mode. I would like to lock only when actual editing takes place.

Prerequisites:

Steps:

(The server could let clients pro-actively know which glyphs are locked, which would be a little friendlier for the user in most cases. But the above is still necessary to avoid race conditions: what if two users start editing a glyph at roughly the same time, before either can be notified? The server will have to reject one of them while it is already editing.)

This is much simpler than a full CRDT, and has the following drawbacks:

Compared to RoboCJK, this has the following advantage:

This scheme can be made to work with RoboCJK's locking mechanism:

(This will cause quite some traffic between the Fontra server and the RoboCJK server, if edits come in quick succession, such as when dragging points. Perhaps it can be streamlined, eg. by delaying unlocking a little, so rapid successive edits can use the same lock.)

justvanrossum commented 1 year ago

This is partially done in https://github.com/BlackFoundryCom/fontra-rcjk/pull/27, at least on the back-end level. We still need a more integrated method for live changes, mostly in fonthandler.py.