perf(tags): cache tag strings; hoist per-call regexes to LazyLock#1278
Draft
duncanista wants to merge 1 commit into
Draft
Conversation
Compute the Lambda tag vec/string/function-tags-map once in Lambda::new_from_config and return the cached values from the getters, so repeated init- and per-trace-time calls to get_tags_vec/get_tags_string/get_function_tags_map are O(1) reads instead of re-iterating the tag map and re-running format!/join on every call. Hoist the two static limits-file regexes in proc/mod.rs (Max open files, Max processes) to LazyLock<Regex> so they compile once instead of on every fd/threads metrics sample. The trace_processor span_matches_tag_regex pattern is left as-is: its value comes from per-call user config (apm_filter_tags_regex_reject), not a static literal, so it cannot be hoisted to a LazyLock without changing behavior. Output (tag set, format, values) is unchanged.
|
12 tasks
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.
Jira: none yet — add before marking ready.
Overview
Two small cold-start / hot-path cleanups. Behavior is unchanged — same tag set, order, format, and values; same metrics. Only redundant work is removed.
1. Cache Lambda tag representations (
tags/lambda/tags.rs,tags/provider.rs)Lambda::get_tags_vec,get_tags_string, andget_function_tags_mappreviously re-iterated the tag map and re-ranformat!("{k}:{v}")(andjoin(",")) on every call. These are called repeatedly during init (start_dogstatsdbuilds the enrichment-tag string/vec) and per-trace (trace_processor, log processor), so the same string was rebuilt many times over.The tag set is immutable after construction, so the
Vec<String>, joinedString, and_dd.tags.functionmap are now computed once inLambda::new_from_configand stored. The getters return the cached values, making repeated reads O(1). Aget_tags_string()returning&strwas added soProvider::get_tags_string()clones the cached string instead of re-joining the vec.2. Hoist per-call regexes to
LazyLock(proc/mod.rs)get_fd_max_data_from_pathandget_threads_max_data_from_pathcalledRegex::new(...)on every invocation (every fd/threads metrics sample). Both patterns are static literals, so they are now compiled once viaLazyLock<Regex>(using.expect("valid static regex")).trace_processor::span_matches_tag_regex— left unchanged. Its pattern comes from per-call user config (apm_filter_tags_regex_reject), not a static literal, so it cannot be hoisted to aLazyLockwithout changing behavior. Left as-is intentionally.Testing
cargo fmtclean;cargo clippy --bin bottlecap --no-depsclean (only the pre-existingbuf_redux/multipartfuture-incompat warning remains; pedantic/unwrap_useddenied — satisfied, only.expect()used).cargo test --libforproc::tests,tags::lambda::tags::tests,tags::provider::testspasses. (Twotest_get_function_tags_map*cases are a pre-existing multi-threaded env-var-race flake — they also fail on the unmodified base branch and pass single-threaded / in isolation; not caused by this change.)