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

Variable length encoding #86

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

Variable length encoding #86

wants to merge 5 commits into from

Conversation

klaidliadon
Copy link
Contributor

@klaidliadon klaidliadon commented Feb 20, 2025

This is a proposal for variable length encoding for access keys.

  • First byte is version (3)
  • Second byte is 4 bit for length of each IDs
    • 1-4 Bytes for the first ID
    • 1-4 Bytes for the second ID
  • The rest is random bytes

The current version is 32 bits (at least 22 random bytes) but we can change that

Sample keys

  • v0: 7vShFoC0qe2eMQKeSde1hqBAAAAAAAAAA
  • v1: AQAAAAAAAAAB40UGtqT8QqnbqhyGohFvk7Y
  • v2 (old): AgAAAAAAAAABAAAAAAAAAAJ9voA9iD-LUCZ0UF1rYD4Also
  • v2 (new): AxEBAlv8_WVyNz2lgc1Eltn3jzVIgkVw0_HxE_RtGXI

@patrislav
Copy link
Member

I like this, this increases the entropy by a lot and makes the keys more aesthetically pleasing by removing all the screams ("AAAAA"). The v2 was very short-lived - is it even used in production? Maybe this should be v2?

@klaidliadon
Copy link
Contributor Author

The v2 was very short-lived - is it even used in production? Maybe this should be v2?

No it's in yet, so we can use this as v2 if there's quorum.

@klaidliadon
Copy link
Contributor Author

Possible improvements

We could compress this even more by using the first byte for version and length:

  • 4 bits (0-16) for version
  • 2 bits per id length - we save the log2 of the bitsize:
    • 0 = 1 byte
    • 1 = 2 bytes
    • 2 = 4 bytes
    • 3 = 8 bytes

For instance:

  • version 2
  • 2 byte ID1
  • 2 byte ID2
    Byte 1 will be 0x25 (0010 for the version, 01 and 01 for the lengths)

@patrislav
Copy link
Member

Not sure it's worth it for just one byte. I like the version as a separate byte, it's easy to decode, understand, and even see at a glance. We don't need to squeeze every bit of performance out of it IMO

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.

2 participants