Skip to content

Simplify Sha1 shard key extraction and drop its unwrap#957

Open
crodas wants to merge 1 commit into
postgresml:mainfrom
crodas:feature/improve-sha1
Open

Simplify Sha1 shard key extraction and drop its unwrap#957
crodas wants to merge 1 commit into
postgresml:mainfrom
crodas:feature/improve-sha1

Conversation

@crodas

@crodas crodas commented Jul 20, 2026

Copy link
Copy Markdown

The Sha1 sharder built a hex string of the whole digest just to parse its tail back into an integer, which introduced a fallible i64::from_str_radix and an .unwrap() that could panic on malformed input. Since a SHA1 digest is already raw bytes, the same value can be read directly.

Read the shard key from the last four bytes of the digest with u32::from_be_bytes instead of formatting to hex and parsing the tail with i64::from_str_radix. This removes the allocation, the fallible parse, and the unwrap. The same bytes are selected (the previous code took the last eight hex characters), so shard assignments are unchanged.

The Sha1 sharder built a hex string of the whole digest just to parse
its tail back into an integer, which introduced a fallible
i64::from_str_radix and an .unwrap() that could panic on malformed
input. Since a SHA1 digest is already raw bytes, the same value can be
read directly.

Read the shard key from the last four bytes of the digest with
u32::from_be_bytes instead of formatting to hex and parsing the tail
with i64::from_str_radix. This removes the allocation, the fallible
parse, and the unwrap. The same bytes are selected (the previous code
took the last eight hex characters), so shard assignments are
unchanged.
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.

1 participant