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

Time-ordered event ids #1587

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vitorpamplona
Copy link
Collaborator

@vitorpamplona vitorpamplona commented Nov 19, 2024

There are a lot of performance benefits to having primary keys with temporal locality. For instance, when your database needs to check the uniqueness of IDs, only a small portion of the index needs to be hot (in memory). With the current "random identifiers", the working set eventually becomes all of the data and your database will be page-faulting continuously. Sequential primary keys also make it easier for the database to place new records in order, minimizing the need to rearrange data or update index structures.

This PR makes a simple, but breaking change, to the way we compute event ids. It was inspired by the improvements made by UUIDv7.

It's a long shot, but I do think we should do this at some point in Nostr's lifetime.

@staab
Copy link
Member

staab commented Nov 19, 2024

Neat idea, might be a better fit for https://github.com/mikedilger/nostr-next

@mikedilger
Copy link
Contributor

I don't use event IDs as database keys in chorus. I use offset (into a long list of events serialized back-to-back). I have to have an index from event ID to offset for filters specifying IDs, but all the other indexes go straight to offset.

But your idea would still cut down on page faults into the one index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants