Skip to content

Compute SHA1 shard key from raw digest bytes#1239

Closed
crodas wants to merge 1 commit into
pgdogdev:mainfrom
crodas:feature/improve-sha1-calculation
Closed

Compute SHA1 shard key from raw digest bytes#1239
crodas wants to merge 1 commit into
pgdogdev:mainfrom
crodas:feature/improve-sha1-calculation

Conversation

@crodas

@crodas crodas commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

The SHA1 sharding hash formatted the full 20-byte digest as a hex string, then parsed the last 8 hex characters back into an integer on every call. That allocated a string and ran a radix parse to recover bytes already sitting in the digest.

Read the last four bytes directly and assemble the key with u32::from_be_bytes. The last 8 hex characters map to bytes 16 through 19, so the shard assignment is unchanged; only the work to extract it goes away. This also drops the unwrap on the parse.

The SHA1 sharding hash formatted the full 20-byte digest as a hex string, then
parsed the last 8 hex characters back into an integer on every call. That
allocated a string and ran a radix parse to recover bytes already sitting in
the digest.

Read the last four bytes directly and assemble the key with u32::from_be_bytes.
The last 8 hex characters map to bytes 16 through 19, so the shard assignment
is unchanged; only the work to extract it goes away. This also drops the unwrap
on the parse.
@CLAassistant

CLAassistant commented Jul 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@crodas

crodas commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

This is already merged as part of #1240

@crodas crodas closed this Jul 20, 2026
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