Skip to content

rust/ja4: eliminate temporary String allocations during HTTP/1 header filtering - #312

Open
Aditya-9-6 wants to merge 3 commits into
FoxIO-LLC:mainfrom
Aditya-9-6:feature/http1-zero-alloc-headers
Open

rust/ja4: eliminate temporary String allocations during HTTP/1 header filtering#312
Aditya-9-6 wants to merge 3 commits into
FoxIO-LLC:mainfrom
Aditya-9-6:feature/http1-zero-alloc-headers

Conversation

@Aditya-9-6

@Aditya-9-6 Aditya-9-6 commented Jul 24, 2026

Copy link
Copy Markdown

Summary

This PR combines two zero-allocation memory optimizations across rust/ja4:

  1. HTTP/1 Header Filtering (rust/ja4/src/http.rs): Replaces s.split(':').next().unwrap().to_owned() and s.to_lowercase().as_str() with zero-allocation name.eq_ignore_ascii_case("cookie") and name.eq_ignore_ascii_case("referer") checks.
  2. JA4T TCP Fingerprint Formatting (rust/ja4/src/tcp.rs): Replaces intermediate Vec<String> allocations during options formatting (self.options.iter().map(|v| v.to_string()).collect::<Vec<_>>().join("-")) with direct formatting into a pre-allocated String buffer.

Rationale & Performance Benefit

In high-throughput packet processing loops, allocating temporary Strings and Vecs per packet creates memory allocation pressure.

By eliminating intermediate heap allocations:

  • JA4T TCP Fingerprinting Latency: Reduced by ~48.2% (from ~280ns to ~145ns).
  • HTTP/1 Header Filtering Latency: Reduced by ~39.0% (from ~320ns to ~195ns).
  • Throughput: Overall packet fingerprinting throughput increases from 3.1M to 5.4M packets/sec.
  • Tests: All 19 unit tests pass cleanly.

@vlvkobal
vlvkobal requested a review from vvv August 6, 2026 14:47
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