Skip to content

perf(rust): optimize hash12 by directly hex-encoding 6-byte digest slices in ja4 and ja4x - #314

Merged
vlvkobal merged 7 commits into
FoxIO-LLC:mainfrom
Aditya-9-6:main
Sep 1, 2026
Merged

perf(rust): optimize hash12 by directly hex-encoding 6-byte digest slices in ja4 and ja4x#314
vlvkobal merged 7 commits into
FoxIO-LLC:mainfrom
Aditya-9-6:main

Conversation

@Aditya-9-6

Copy link
Copy Markdown
Contributor

Summary

This PR optimizes the core hash12 helper function in both the ja4 and ja4x Rust crates.

Technical Details

Previously, hash12 performed hex::encode(Sha256::digest(s)) over all 32 bytes of the digest into a 64-character heap string, followed by sha256[..12].into() to extract the 12-char slice:

// Old: 2 heap allocations + hex encoding 26 unused trailing bytes
let sha256 = hex::encode(Sha256::digest(s));
sha256[..12].into()

@vlvkobal
vlvkobal requested a review from vvv August 19, 2026 11:09
@vlvkobal

Copy link
Copy Markdown
Member

Let’s merge #312 first, then rebase this PR on top of it. @vvv, could you review the earlier pending PRs when you have a chance?

@vlvkobal
vlvkobal self-requested a review August 27, 2026 13:52
Comment thread rust/ja4x/src/main.rs

@vlvkobal vlvkobal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One note for future PRs: a PR should have a clear idea behind it, and the changes in it should be coherent and related to that idea. Unrelated fixes, refactoring, and cleanup are better kept in separate PRs, otherwise the PR becomes harder to understand and review.

No need to split this one now, but please keep this in mind for future PRs.

@Aditya-9-6

Copy link
Copy Markdown
Contributor Author

Yes sir !

@vlvkobal
vlvkobal merged commit c91d705 into FoxIO-LLC:main Sep 1, 2026
9 checks passed
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