Skip to content

Conversation

@costela
Copy link
Member

@costela costela commented Oct 10, 2025

This PR sacrifices a bit of readibility for significant less allocations:

goos: linux
goarch: amd64
pkg: github.com/exaring/ja4plus
cpu: AMD Ryzen 7 7840U w/ Radeon  780M Graphics     
       │  old.bench  │              new.bench              │
       │   sec/op    │   sec/op     vs base                │
JA4-16   684.6n ± 1%   207.8n ± 1%  -69.65% (p=0.000 n=10)

       │  old.bench  │             new.bench              │
       │    B/op     │    B/op     vs base                │
JA4-16   240.00 ± 0%   48.00 ± 0%  -80.00% (p=0.000 n=10)

       │  old.bench  │             new.bench              │
       │  allocs/op  │ allocs/op   vs base                │
JA4-16   15.000 ± 0%   1.000 ± 0%  -93.33% (p=0.000 n=10)

@costela costela requested a review from Copilot October 12, 2025 06:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes the JA4 fingerprinting algorithm to significantly reduce memory allocations while maintaining the same functionality. The changes replace string concatenation and fmt.Sprintf calls with manual byte buffer manipulation and custom hex encoding functions.

Key changes:

  • Replace slice operations and string formatting with manual loops and byte operations
  • Introduce custom helper functions for hex encoding and digit formatting
  • Change hash functions to return fixed-size byte arrays instead of slices

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

File Description
ja4plus.go Core optimization replacing string operations with byte buffer manipulation and custom encoding functions
ja4plus_test.go Update test to work with new hash function signature returning byte array
examples_test.go Update expected output and add comment about Go version differences
.github/workflows/ci.yml Add Go 1.25 to test matrix

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@costela costela force-pushed the leo.antunes/significantly-reduce-allocations branch from 82f233c to 76214a8 Compare October 13, 2025 13:12
@costela costela merged commit 29412cc into main Oct 15, 2025
2 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.

3 participants