Skip to content

jax_fingerprint: Reduce allocations and gate methods at build time#13338

Open
maskit wants to merge 2 commits into
apache:masterfrom
maskit:jax_fingerprint-reduce-allocations
Open

jax_fingerprint: Reduce allocations and gate methods at build time#13338
maskit wants to merge 2 commits into
apache:masterfrom
maskit:jax_fingerprint-reduce-allocations

Conversation

@maskit

@maskit maskit commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary

Reduces per-connection memory work in the jax_fingerprint plugin and makes the set of compiled-in fingerprint methods a configure-time choice.

  • ContextMap is now an inline fixed-size table of (method-name, JAxContext*) pairs, replacing the std::unordered_map<std::string, JAxContext*> used previously. Lookup is a short linear scan; the bucket array and node allocations that the map performed on every TLS connection are gone.

  • set_fingerprint takes std::string_view, dropping the temporary std::string that was materialised at every call site purely to bind a const std::string & parameter.

  • ENABLE_JAX_METHODS is a new CMake cache variable (default "ja3;ja4;ja4h") that drives, from a single list:

    • which method subdirectories contribute sources to the plugin and to test_jax,
    • which ENABLE_JAX_METHOD_<NAME> preprocessor defines are set, and
    • the value of JAX_FINGERPRINT_MAX_METHODS (the inline context-table size, derived from the list length).

    Build slim: cmake -B build -DENABLE_JAX_METHODS="ja4". Empty list or unknown directory name causes a FATAL_ERROR at configure time.

  • plugin.cc dispatcher is now a constexpr table of Method const * entries, each gated by the per-method ENABLE_JAX_METHOD_* macro. The dispatcher and the method #includes are the only place in the plugin that names concrete methods; method.h stays method-agnostic.

  • README in the plugin directory documents the per-method file layout, the build-time switches, and the file-naming rules the CMake glob relies on (including the tls_client_hello_summary.cc historical carve-out and how to handle similar cases going forward).

Test plan

  • cmake --build my-b-bssl -t jax_fingerprint — default (ja3;ja4;ja4h) builds cleanly.
  • cmake --build my-b-bssl -t test_jax and run test_jax — 67 assertions across 5 Catch2 test cases pass.
  • cmake --build my-b-bssl -t format — clang-format / cmake-format clean.
  • AuTest jax_fingerprint* passes against the installed plugin.
  • Slim build: cmake -B my-b-bssl -DENABLE_JAX_METHODS="ja4" — only ja4/*.cc compiled into the plugin.
  • Negative configure paths: -DENABLE_JAX_METHODS="" and -DENABLE_JAX_METHODS="ja99" both fail at configure time with the intended messages.

Notes for reviewers

  • ContextMap keys are std::string_views that alias Method::name (which is itself a string_view pointing at a string literal). The slot table stays valid as long as the Method struct does, i.e. for the lifetime of the process.
  • The plugin's other lookup against a heterogeneous-lookup hash (the SNI server-name set in plugin.cc) is unchanged. The __cpp_lib_generic_unordered_lookup #ifdef there is still needed and is unrelated to ContextMap.
  • JAX_FINGERPRINT_MAX_METHODS is not a separate user knob; CMake derives it from the length of ENABLE_JAX_METHODS. The #ifndef ... #define ... 8 in context_map.h is a fallback so the header is valid when compiled standalone (e.g. IDE indexing). A static_assert in context_map.h enforces a minimum of 1, and set() TSReleaseAsserts on overflow.

Trim per-connection memory work in the hybrid (global + remap) setup
by collapsing the per-connection table of fingerprint contexts to an
inline structure and by passing fingerprints into the context without
an intermediate copy. Lookup behavior is unchanged.

Add ENABLE_JAX_METHODS as the configure-time switch for which
fingerprint methods are compiled in. CMake derives the per-method
preprocessor defines, the dispatcher table in plugin.cc, and the slot
count of the inline context table from the same list. An empty list
or an unknown method directory fails at configure time.

Include a developer README covering the per-method file layout, the
build-time switches, and the naming rules that the CMake glob relies
on.
@maskit maskit added this to the 11.0.0 milestone Jun 26, 2026
@maskit maskit self-assigned this Jun 26, 2026
Copilot AI review requested due to automatic review settings June 26, 2026 02:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 experimental jax_fingerprint plugin by removing per-connection container allocations and making the set of compiled fingerprinting methods a CMake-time choice, reducing runtime overhead and enabling slimmer builds.

Changes:

  • Replaces the per-connection method→context hash map with a fixed-size inline slot table (ContextMap) and updates fingerprint-setting to accept std::string_view.
  • Adds ENABLE_JAX_METHODS CMake cache variable to select method subdirectories, drive per-method compile definitions, and derive JAX_FINGERPRINT_MAX_METHODS.
  • Updates method dispatch to a macro-gated constexpr method table and adds a developer README documenting method layout and build rules.

Reviewed changes

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

Show a summary per file
File Description
plugins/experimental/jax_fingerprint/README New developer-focused documentation for method layout, build-time switches, and file naming rules.
plugins/experimental/jax_fingerprint/plugin.cc Gates method includes/dispatch entries at compile time via ENABLE_JAX_METHOD_* macros and uses a table-driven --method lookup.
plugins/experimental/jax_fingerprint/context.h Changes set_fingerprint to accept std::string_view.
plugins/experimental/jax_fingerprint/context.cc Implements the std::string_view signature and assignment into the stored std::string.
plugins/experimental/jax_fingerprint/context_map.h Replaces unordered_map with a fixed-size (method_name, ctx*) slot table and linear scan lookup.
plugins/experimental/jax_fingerprint/CMakeLists.txt Introduces ENABLE_JAX_METHODS to select sources/defines and derives JAX_FINGERPRINT_MAX_METHODS.

Comment thread plugins/experimental/jax_fingerprint/context_map.h Outdated
Comment thread plugins/experimental/jax_fingerprint/context_map.h Outdated
Comment thread plugins/experimental/jax_fingerprint/context_map.h Outdated
Comment thread plugins/experimental/jax_fingerprint/context_map.h Outdated
Comment thread plugins/experimental/jax_fingerprint/context_map.h Outdated
@maskit maskit requested a review from Copilot June 26, 2026 03:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bryancall bryancall requested a review from bneradt June 29, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants