jax_fingerprint: Reduce allocations and gate methods at build time#13338
Open
maskit wants to merge 2 commits into
Open
jax_fingerprint: Reduce allocations and gate methods at build time#13338maskit wants to merge 2 commits into
maskit wants to merge 2 commits into
Conversation
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.
Contributor
There was a problem hiding this comment.
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 acceptstd::string_view. - Adds
ENABLE_JAX_METHODSCMake cache variable to select method subdirectories, drive per-method compile definitions, and deriveJAX_FINGERPRINT_MAX_METHODS. - Updates method dispatch to a macro-gated
constexprmethod 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduces per-connection memory work in the
jax_fingerprintplugin 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 thestd::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_fingerprinttakesstd::string_view, dropping the temporarystd::stringthat was materialised at every call site purely to bind aconst std::string ¶meter.ENABLE_JAX_METHODSis a new CMake cache variable (default"ja3;ja4;ja4h") that drives, from a single list:test_jax,ENABLE_JAX_METHOD_<NAME>preprocessor defines are set, andJAX_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 aFATAL_ERRORat configure time.plugin.ccdispatcher is now aconstexprtable ofMethod const *entries, each gated by the per-methodENABLE_JAX_METHOD_*macro. The dispatcher and the method#includes are the only place in the plugin that names concrete methods;method.hstays method-agnostic.READMEin the plugin directory documents the per-method file layout, the build-time switches, and the file-naming rules the CMake glob relies on (including thetls_client_hello_summary.cchistorical 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_jaxand runtest_jax— 67 assertions across 5 Catch2 test cases pass.cmake --build my-b-bssl -t format— clang-format / cmake-format clean.jax_fingerprint*passes against the installed plugin.cmake -B my-b-bssl -DENABLE_JAX_METHODS="ja4"— onlyja4/*.cccompiled into the plugin.-DENABLE_JAX_METHODS=""and-DENABLE_JAX_METHODS="ja99"both fail at configure time with the intended messages.Notes for reviewers
ContextMapkeys arestd::string_views that aliasMethod::name(which is itself astring_viewpointing at a string literal). The slot table stays valid as long as theMethodstruct does, i.e. for the lifetime of the process.plugin.cc) is unchanged. The__cpp_lib_generic_unordered_lookup#ifdefthere is still needed and is unrelated to ContextMap.JAX_FINGERPRINT_MAX_METHODSis not a separate user knob; CMake derives it from the length ofENABLE_JAX_METHODS. The#ifndef ... #define ... 8incontext_map.his a fallback so the header is valid when compiled standalone (e.g. IDE indexing). Astatic_assertincontext_map.henforces a minimum of 1, andset()TSReleaseAsserts on overflow.