# Remove the concept of a local clock; use lamport clocks for all per-replica versioning \(\#2924\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/7bcc59c8a506de098ab06f469e6b3cf386944f0d)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 7bcc59c8a506de098ab06f469e6b3cf386944f0d

Requested commit: 7bcc59c8a506de098ab06f469e6b3cf386944f0d

Commit: 7bcc59c8a506de098ab06f469e6b3cf386944f0d

Tree: 738f7cac54ae59393054c3d2bb281d986a871f14

Author: Max Brunsfeld

Committer: GitHub

## Message

```
Remove the concept of a local clock; use lamport clocks for all per-replica versioning (#2924)

### Background

Currently, our CRDT uses three different types of timestamps:

| clock type | representation | purpose |
|-----|----------------|----------|
| `Local` | replica id + u32 | uniquely identifies operations |
| `Lamport` | replica id + u32 | provides a consistent total ordering
for all operations |
| `Global` | N local clocks | fully defines the partial ordering between
all concurrent operations |

All text operations include *each* type of timestamp. And every
`Fragment` in a buffer's fragment tree contains both a local and a
lamport timestamp.

### Change

An operation can be uniquely identified by its lamport timestamp, so we
don't really need a concept of a local timestamp. In this PR, I've
removed the concept of a local timestamp. Version vectors
(`clock::Global`) now store vectors of *lamport* timestamps.

Eliminating local timestamps reduces the memory footprint of a buffer by
four bytes per fragment, reduces the size of our `UpdateBuffer` RPC
messages, and reduces the amount of data we need to store in our
database for channel buffers. It also makes our CRDT a bit easier to
understand, IMO, because there is now only one scalar value that we
increment per replica.

It's possible I'm missing something here though. @as-cii, @nathansobo
it'd be good to get your 👀
```

## Parents

- [00aae5abee3af76c4eed3d1d57bdb0ee45019b46](https://git.cafe/gitcafe/zed/commit/00aae5abee3af76c4eed3d1d57bdb0ee45019b46?format=markdown)

- [1e604546434bbafa79b33087cc1ddb6eca42dc9e](https://git.cafe/gitcafe/zed/commit/1e604546434bbafa79b33087cc1ddb6eca42dc9e?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/7bcc59c8a506de098ab06f469e6b3cf386944f0d?format=markdown)
