Skip to content

enhancement(agent-data-plane): skip context clones when tag_filterlist rules do not match - #3500

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
blt/1m-11-borrowed-tag-filterlist
Dec 4, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
blt/1m-11-borrowed-tag-filterlist

Conversation

@blt

@blt blt commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The tag_filterlist transform clones the context of every counter and sketch metric before it checks its cache or its rules. When no rule names the metric, that clone only adds an atomic reference-count increment and decrement per metric. The idle pipeline bypass also needs a filter entry point that does not own the transform's dispatch loop.

This change adds filter_cached, which looks up the cache with the borrowed context and checks rule names first. It clones the context only when a rule matches the metric name. Callers that borrow contexts keep the cached filter result.

This change has no separate Tier 1 measurement. The idle pipeline bypass requires filter_cached and carries the measured gain.

Change Type

  • Bug fix
  • New feature
  • Non-functional
  • Performance

How did you test this PR?

  • cargo check --locked --workspace --tests
  • cargo test --locked -p agent-data-plane --bin agent-data-plane telemetry_records_hits_misses_and_filtered_tags

References

Series overview

This was referenced Nov 26, 2026
@blt
blt added this pull request to stack #3510 November 26, 2026 23:03
@blt
blt marked this pull request as ready for review November 26, 2026 23:11
@blt
blt requested a review from a team as a code owner November 26, 2026 23:11

@github-actions github-actions Bot 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.

AI review by Claude - workflow run

Patch is correct, with 0 blocking findings. The new filter_cached keeps the old cache-first lookup and the same rule-miss, no-change and modified outcomes. It also skips the context clone when no rule names the metric. The non-blocking comments cover rule-lookup logic that the test-only path copies, new assertions that can't catch a regression, and the release note wording.

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Borrowed cache lookups preserve filtering outcomes, cached context reuse, and telemetry; unmatched metric names still pass through unchanged without cloning their context.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 714baae

@pr-commenter

pr-commenter Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Binary Size Analysis (Agent Data Plane)

Baseline: 8c80abe · Comparison: 76fd1cb · diff
Analysis Configuration: optimized-release profile, stripped binaries · Pass/Fail Threshold: +5%
Sizes: 25.96 MiB (baseline) vs 25.95 MiB (comparison)
Size Change: -8.00 KiB (-0.03%)

✅ Binary size difference within threshold

Changes by Module
Module File Size Symbols
agent_data_plane::components::tag_filterlist -23.79 KiB 28
saluki_transform_kernels::tag_filter::MatchingFilters +22.42 KiB 1
[Unmapped] -4.28 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.12189 +2.12 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.13004 +2.12 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.12222 -2.12 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.13038 -2.12 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.13320 +2.05 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.13354 -2.05 KiB 1
_ZN12serde_saphyr2de6events33attach_alias_locations_if_missing17hd49dea7029be1b37E.12322 +1.62 KiB 1
_ZN12serde_saphyr2de6events33attach_alias_locations_if_missing17hd49dea7029be1b37E.13116 +1.62 KiB 1
_ZN12serde_saphyr2de6events33attach_alias_locations_if_missing17hd49dea7029be1b37E.12355 -1.62 KiB 1
_ZN12serde_saphyr2de6events33attach_alias_locations_if_missing17hd49dea7029be1b37E.13150 -1.62 KiB 1
saluki_core::data_model::event -1.40 KiB 2
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.10663 +1.29 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.10686 -1.29 KiB 1
_ZN5regex5regex6string5Regex11captures_at17h1ab60415564af407E.10908 +1.05 KiB 1
_ZN5regex5regex6string5Regex11captures_at17h1ab60415564af407E.10935 -1.05 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.9700 +1018 B 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.9723 -1018 B 1
Detailed Symbol Changes
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [NEW] +22.4Ki  [NEW] +22.4Ki    saluki_transform_kernels::tag_filter::MatchingFilters::apply::h7f3c7429a50761b5
 +18e2% +14.2Ki +18e2% +14.2Ki    saluki_core::data_model::event::metric::context::Context::with_tags::h409cae7ea8892656
  [NEW] +9.19Ki  [NEW] +9.19Ki    _<agent_data_plane::components::tag_filterlist::TagFilterlist as saluki_core::components::transforms::Transform>::run::_{{closure}}::hf115a5c83431a7cc
  [NEW] +4.73Ki  [NEW] +4.73Ki    _ZN59_<rustls::error::Error as core::clone::Clone>5clone17h40d1888bcf0ace9bE.12473
  [NEW] +4.08Ki  [NEW] +4.08Ki    _ZN76_<saluki_core::data_model::event::Event as core::clone::Clone>5clone17h448236d0fc510d32E.10855
  [NEW] +3.38Ki  [NEW] +3.38Ki    _ZN57_<rustls::error::Error as core::fmt::Debug>3fmt17hd5c00d77e4ed4348E.10509
  [NEW] +3.29Ki  [NEW] +3.29Ki    _ZN85_<saluki_core::data_model::event::metric::Metric as core::clone::Clone>5clone17h2da1e8a05877b12dE.10856
  [NEW] +3.29Ki  [NEW] +3.29Ki    _ZN57_<rustls::error::Error as core::fmt::Debug>3fmt17hd5c00d77e4ed4348E.12474
  [NEW] +3.27Ki  [NEW] +3.27Ki    _ZN57_<rustls::error::Error as core::fmt::Debug>3fmt17hd5c00d77e4ed4348E.8195
  [NEW] +2.96Ki  [NEW] +2.96Ki    _<saluki_transform_kernels::tag_filter::CompiledValuePrefixFilters as core::clone::Clone>::clone::h9f35f8f079226e7a
  -0.1%    -967  -0.1%    -967    [570 Others]
  [DEL] -2.96Ki  [DEL] -2.96Ki    _<saluki_transform_kernels::tag_filter::CompiledValuePrefixFilters as core::clone::Clone>::clone::hf20669646a01e44e
  [DEL] -3.27Ki  [DEL] -3.27Ki    _ZN57_<rustls::error::Error as core::fmt::Debug>3fmt17hd5c00d77e4ed4348E.8214
  [DEL] -3.29Ki  [DEL] -3.29Ki    _ZN57_<rustls::error::Error as core::fmt::Debug>3fmt17hd5c00d77e4ed4348E.12507
  [DEL] -3.29Ki  [DEL] -3.29Ki    _ZN85_<saluki_core::data_model::event::metric::Metric as core::clone::Clone>5clone17h2da1e8a05877b12dE.10883
  [DEL] -3.38Ki  [DEL] -3.38Ki    _ZN57_<rustls::error::Error as core::fmt::Debug>3fmt17hd5c00d77e4ed4348E.10532
  [DEL] -4.08Ki  [DEL] -4.08Ki    _ZN76_<saluki_core::data_model::event::Event as core::clone::Clone>5clone17h448236d0fc510d32E.10882
 -76.4% -4.28Ki  [ = ]       0    [Unmapped]
  [DEL] -4.73Ki  [DEL] -4.73Ki    _ZN59_<rustls::error::Error as core::clone::Clone>5clone17h40d1888bcf0ace9bE.12506
  [DEL] -15.6Ki  [DEL] -15.6Ki    saluki_core::data_model::event::metric::context::Context::derive::hdae6687341cbee96
  [DEL] -33.0Ki  [DEL] -33.0Ki    _<agent_data_plane::components::tag_filterlist::TagFilterlist as saluki_core::components::transforms::Transform>::run::_{{closure}}::ha7dbac6fb46c235a
  -0.0% -8.00Ki  -0.0% -3.72Ki    TOTAL

@pr-commenter

pr-commenter Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Regression Detector (Agent Data Plane)

Run ID: 29c9e146-d997-4b43-be2b-bfd8bb5f3bc7
Baseline: 8c80abeb · Comparison: 76fd1cb4 · diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment (5)

Experiments configured erratic: true are tagged (ignored) and skipped when determining which experiments regressed or improved. Experiments which are detected as erratic at runtime are tagged (erratic) to flag that the run's sample dispersion was high, but their regression / improvement signal still counts.

experiment goal Δ mean % links
quality_gates_rss_dsd_low memory utilization ⚪ +0.48 metrics profiles logs
quality_gates_rss_dsd_heavy memory utilization ⚪ +0.25 metrics profiles logs
quality_gates_rss_idle memory utilization ⚪ -0.46 metrics profiles logs
quality_gates_rss_dsd_medium memory utilization ⚪ -0.53 metrics profiles logs
quality_gates_rss_dsd_ultraheavy memory utilization ⚪ -1.04 metrics profiles logs
Bounds Checks: ✅ Passed (5)
experiment check replicates observed links
quality_gates_rss_dsd_heavy memory_usage 10/10 ✅ 159.94MiB ≤ 250MiB metrics profiles logs
quality_gates_rss_dsd_low memory_usage 10/10 ✅ 46.55MiB ≤ 55MiB metrics profiles logs
quality_gates_rss_dsd_medium memory_usage 10/10 ✅ 70.90MiB ≤ 92MiB metrics profiles logs
quality_gates_rss_dsd_ultraheavy memory_usage 10/10 ✅ 260.05MiB ≤ 420MiB metrics profiles logs
quality_gates_rss_idle memory_usage 10/10 ✅ 30.28MiB ≤ 36MiB metrics profiles logs
Explanation

A change is flagged as a regression when |Δ mean %| > 5.00% in the regressing direction for its optimization goal AND SMP marks the experiment as a regression (is_regression: true). Improvements use the matching criteria for the improving direction. Experiments configured erratic: true (tagged (ignored)) are skipped outright; experiments detected as erratic at runtime (tagged (erratic)) still count, since that flag describes sample dispersion rather than directional certainty. The Δ mean % cell is colored accordingly: 🟢 = improvement, 🔴 = regression, ⚪ = neutral. Reduction in CPU or memory is an improvement; reduction in ingress throughput is a regression. Experiments tagged (no analysis) show ⚠️ n/a: SMP ran them but produced no analysis, usually because a replicate failed and exhausted its retries. Check the SMP report for that experiment's replicate failures.

@blt
blt force-pushed the blt/1m-11-borrowed-tag-filterlist branch from 714baae to 6794af4 Compare November 27, 2026 00:01

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Context cloning is deferred until a metric name matches a rule. Cache hits still restore the filtered context and the removed-tag count used by telemetry.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 6794af4

@blt
blt force-pushed the blt/1m-11-borrowed-tag-filterlist branch from 6794af4 to 9d871a2 Compare November 27, 2026 00:22
dd-octo-sts Bot pushed a commit that referenced this pull request Dec 3, 2026
…it admission (#3492)

## Summary

Packed contexts need to share recurring strings, such as `env:prod`, without storing a copy in every context. The existing `GenericMapInterner` cannot serve that role, and no existing crate meets all four constraints below.

`GenericMapInterner` admits every string on its first lookup. On the 1M RUM workload, each gauge carries one unique 51 B UUID tag. Roughly 143,000 of those one-off tags fill the 8 MiB interner budget, and later recurring tags fall back to the heap. `SymbolTable` admits a string only on its second sighting, through a lazily allocated 8,192-slot thread-local witness (64 KiB per interning thread).

Each of the 16 `SymbolTable` shards also keeps a 512 B atomic bloom filter of resident strings, 8 KiB across all shards. A first sighting checks that filter and the witness without taking any shard lock. Filter false positives cost a read lock but cannot admit a first sighting.

`GenericMapInterner` returns a self-contained 24 B `MetaString` handle around a 16 B `StringState`. A packed context stores many tags in one allocation and needs a 4 B handle per tag. `SymbolTable` returns `u32` IDs into an external table, and owners read them without locking. The same IDs double as dictionary hints for the V3 encoder.

Changing `GenericMapInterner` to match would break its current callers. Workload metadata, the tagger, OTLP traces and strict-mode context resolution rely on self-contained handles and first-hit admission. `SymbolTable` therefore stays a separate type with its own contract.

Existing crates do not fit either. `lasso`, `ustr` and `string-interner` never reclaim dropped strings, so a long-lived agent grows as tags churn. `internment` reclaims strings but lacks a byte cap, two-hit admission and 4 B IDs. `SymbolTable` reference-counts each record and returns its space to a per-shard free list on the last release.

This change adds no caller, so it has no Tier 1 effect by itself. Packed contexts and the V3 packed-symbol mapping depend on it.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [x] Non-functional
- [ ] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p stringtheory --lib singletons_leave_space_for_late_shared_symbols`
- `cargo test --locked -p stringtheory`

## References

- Stacked on: #3491 (`blt/1m-02-tagstr-borrowed-views`)
- Requires: none.
- Required by: packed `Context` storage through `SymbolTable` IDs, and V3 packed-symbol mapping through `Symbol` IDs.
- Release note: none, because this change has no externally visible effect.

### Series overview

- **Context & Tag Density:** pack contexts into one allocation and drop unused cache overhead.
  - #3490: shard ContextCache with inline expiry and live-context reuse (merged)
  - #3491: expose borrowed metric names and tags as `&str`
  - **Current (#3492):** add a sharded symbol dictionary with two-hit admission
  - #3511: store Context and its tags in one packed allocation
- Dense Aggregation (#3495–#3496): replace 177 B buckets with per-kind typed pages.
- Resumable Flush (#3497–#3499): shrink metric buffers and interleave bounded flush chunks.
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory limits with idle reclaim and counted drops.

Co-authored-by: brian.troutwine <brian.troutwine@datadoghq.com> 8299071

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

The borrowed-context path preserves cached filtering results and telemetry while returning before cloning for unmatched metric names. Static review identified no actionable regression.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 4192ad7

gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Dec 3, 2026
#3511)

## Summary

Each DogStatsD context at base costs about 1 KB across separate heap objects. It holds a 192 B `ArcInner<ContextInner>`, a 48 B tag-set `Arc`, a 128 B to 320 B tag `Vec` and 64 B for spilled UUIDs. On 1M RUM, active `dsd_in` live heap reaches 886.9 MiB to 929.9 MiB.

The `TagSetCache` adds 108 MiB to 145 MiB at the production 2,000,000-entry limit. It hits on 0.095% of lookups, 977 hits against 1,022,675 misses, and its backing slabs never shrink.

Tuning the existing types cannot remove this cost, because the separate allocations and the shared tag-set `Arc` are the overhead. This change stores the name, host, tag descriptors and inline bytes in one immutable allocation behind an 8 B handle. Recurring strings become 4 B `SymbolTable` IDs, and contexts keep sharing origin tags.

A closed `PrefixKind` selects the prefix layout. The `WithOrigin`, `WithLease`, and `WithOriginLease` structs define the layouts that have a prefix.

The default heap-allowed path bypasses the `TagSetCache` entirely. The strict path keeps its interner quota and refuses data that it cannot represent.

Stripped `optimized-release` Tier 1 runs show the gain from this change together with the borrowed views and `SymbolTable` it activates. Peak memory falls by 707.7 MiB on 1M RUM, 679.6 MiB on 500k default, 636.3 MiB on all-unique and 278.0 MiB on mixed churn. Cgroup CPU on 1M RUM falls 14.9%. Active `dsd_in` live heap on 1M RUM falls from 836.8 MiB to 210.2 MiB.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p saluki-core --lib data_model::event::metric::context`
- `cargo test --locked -p saluki-components --lib sources::dogstatsd::resolver::tests`
- Tier 1 runs use stripped `optimized-release` builds against base `18f587f5f6` in cgroup v2, in default unbounded mode.
- 1M RUM holds 1,000,000 gauges that each carry one unique 51 B UUID tag and 4 to 10 shared tags.
- 500k default runs the same stream under Saluki's default 500,000-entry context and tag-set cache limits.
- All-unique holds 1,000,000 gauges that each carry eight unique tags of 32 B to 50 B.
- Mixed churn cycles gauges, counters, rates, sets and sketches between 200,000 and 1,000,000 active contexts.

## References

- Stacked on: #3492 (`blt/1m-03-sharded-symbol-table`)
- Supersedes: #3494 (auto-closed by GitHub when reordering #3493 above packed contexts)
- Requires: borrowed `&str` / `ContextTags` views (#3491), and two-hit `SymbolTable` IDs (#3492).
- Required by: V3 packed-symbol mapping through packed tag symbol IDs, and stack tag deduplication through the packed builder.
- Release note: `releasenotes/notes/packed-contexts-0a5b1c9ad15dc05f.yaml`

### Series overview

- **Context & Tag Density:** pack contexts into one allocation and drop unused cache overhead.
  - #3490: shard ContextCache with inline expiry and live-context reuse (merged)
  - #3491: expose borrowed metric names and tags as `&str`
  - #3492: add a sharded symbol dictionary with two-hit admission
  - **Current (#3511):** store Context and its tags in one packed allocation
- Dense Aggregation (#3495–#3496): replace 177 B buckets with per-kind typed pages.
- Resumable Flush (#3497–#3499): shrink metric buffers and interleave bounded flush chunks.
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory limits with idle reclaim and counted drops.


Co-authored-by: brian.troutwine <brian.troutwine@datadoghq.com>
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Dec 3, 2026
## Summary

Every aggregated DogStatsD `Set` at base allocates a `HashSet`, even when it holds one member. A singleton set therefore pays for a heap table and its control bytes to store a single string.

Dense aggregate pages need a set representation that fits a fixed-size `SetRow`. Without `SetMembers`, the dense storage build fails with `E0425` for the missing type.

This change adds `SetMembers`, which stores empty and singleton sets inline. It allocates a hash table only when a second distinct member arrives. Merging timestamped buckets still preserves exact deduplication.

This change has no separate Tier 1 measurement. It is a compile prerequisite for dense aggregate pages, which carry the measured gain.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p saluki-core --lib promotes_only_for_distinct_members`

## References

- Stacked on: #3511 (`blt/1m-05-packed-context`)
- Requires: none.
- Required by: dense aggregate pages through `SetMembers` in `SetRow`.
- Release note: `releasenotes/notes/inline-sets-b5611095646c97f9.yaml`

### Series overview

- Context & Tag Density (#3490–#3492, #3511): pack contexts into one allocation and drop unused cache overhead.
- **Dense Aggregation:** replace 177 B buckets with per-kind typed pages.
  - **Current (#3495):** store singleton Set values inline
  - #3496: store live aggregate metrics in dense typed pages indexed by u32 slots
- Resumable Flush (#3497–#3499): shrink metric buffers and interleave bounded flush chunks.
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory limits with idle reclaim and counted drops.


Co-authored-by: brian.troutwine <brian.troutwine@datadoghq.com>
@blt
blt force-pushed the blt/1m-11-borrowed-tag-filterlist branch from 4192ad7 to de7ea0e Compare December 3, 2026 19:00

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Unmatched metric names return before context cloning, while matched rules share the filtering implementation used by the existing entry point. The completed static review identified no actionable regressions; human PR discussion did not change that conclusion.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit de7ea0e

@blt
blt force-pushed the blt/1m-11-borrowed-tag-filterlist branch from de7ea0e to ca33efc Compare December 3, 2026 19:57

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Unmatched metric names retain the rule-miss path, while cache hits preserve filtered contexts and telemetry outcomes. The completed static review identified no actionable regression.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit ca33efc

tobz pushed a commit that referenced this pull request Dec 4, 2026
…ages indexed by u32 slots (#3496)

## Summary

The aggregator stores every series in `HashMap<Context,
AggregatedMetric>`. Each bucket costs 177 B, because `MetricValues`
reserves 104 B for its largest variant, a DDSketch. A gauge pays that
full size plus 48 B of inline metadata. On 1M RUM, the table holds 362.0
MiB to 379.6 MiB of live heap.

The table also doubles at 917,505 contexts, just below the 1M target.
That resize grows it from 192 MiB to 384 MiB and briefly holds 576 MiB
of old and new tables at once. A different hash map type cannot fix
this, because each bucket stays sized for the largest value.

This change moves values into per-kind 32 KiB typed pages. A thin index
stores a 4 B `u32` slot with 3 kind bits and 29 row bits, about 10 MiB
at 1M contexts. A gauge row takes 40 B, about 48 MiB at 1M contexts.
Rare multi-point rows and owned metadata spill to exact overflow stores.

Stripped `optimized-release` Tier 1 runs show peak memory falling by
497.9 MiB on 1M RUM, 506.5 MiB on all-unique and 482.3 MiB on mixed
churn. Cgroup CPU falls 20.8% on 1M RUM, 10.9% on all-unique and 28.6%
on mixed churn. Active `dsd_agg` live heap on 1M RUM falls from 362.0
MiB to 56.3 MiB.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p saluki-components --lib
every_type_matches_metric_values_merge`
- Tier 1 runs use stripped `optimized-release` builds against base
`18f587f5f6` in cgroup v2, in default unbounded mode.
- 1M RUM holds 1,000,000 gauges that each carry one unique 51 B UUID tag
and 4 to 10 shared tags.
- All-unique holds 1,000,000 gauges that each carry eight unique tags of
32 B to 50 B.
- Mixed churn cycles gauges, counters, rates, sets and sketches between
200,000 and 1,000,000 active contexts.

## References

- Stacked on: #3495 (`blt/1m-06-inline-singleton-set`)
- Requires: inline `SetMembers`.
- Required by: resumable flush through `u32` slot cursors, and storage
growth estimates through dense rows.
- Release note:
`releasenotes/notes/use-dense-aggregate-storage-8f83ecb8c4eaac61.yaml`

### Series overview

- Context & Tag Density (#3490–#3492, #3511): pack contexts into one
allocation and drop unused cache overhead.
- **Dense Aggregation:** replace 177 B buckets with per-kind typed
pages.
  - #3495: store singleton Set values inline
- **Current (#3496):** store live aggregate metrics in dense typed pages
indexed by u32 slots
- Resumable Flush (#3497–#3499): shrink metric buffers and interleave
bounded flush chunks.
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and
borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path
cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory
limits with idle reclaim and counted drops.
@tobz
tobz force-pushed the blt/1m-11-borrowed-tag-filterlist branch from ca33efc to 4214757 Compare December 4, 2026 15:28
dd-octo-sts Bot pushed a commit that referenced this pull request Dec 4, 2026
…ages indexed by u32 slots (#3496)

## Summary

The aggregator stores every series in `HashMap<Context,
AggregatedMetric>`. Each bucket costs 177 B, because `MetricValues`
reserves 104 B for its largest variant, a DDSketch. A gauge pays that
full size plus 48 B of inline metadata. On 1M RUM, the table holds 362.0
MiB to 379.6 MiB of live heap.

The table also doubles at 917,505 contexts, just below the 1M target.
That resize grows it from 192 MiB to 384 MiB and briefly holds 576 MiB
of old and new tables at once. A different hash map type cannot fix
this, because each bucket stays sized for the largest value.

This change moves values into per-kind 32 KiB typed pages. A thin index
stores a 4 B `u32` slot with 3 kind bits and 29 row bits, about 10 MiB
at 1M contexts. A gauge row takes 40 B, about 48 MiB at 1M contexts.
Rare multi-point rows and owned metadata spill to exact overflow stores.

Stripped `optimized-release` Tier 1 runs show peak memory falling by
497.9 MiB on 1M RUM, 506.5 MiB on all-unique and 482.3 MiB on mixed
churn. Cgroup CPU falls 20.8% on 1M RUM, 10.9% on all-unique and 28.6%
on mixed churn. Active `dsd_agg` live heap on 1M RUM falls from 362.0
MiB to 56.3 MiB.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p saluki-components --lib
every_type_matches_metric_values_merge`
- Tier 1 runs use stripped `optimized-release` builds against base
`18f587f5f6` in cgroup v2, in default unbounded mode.
- 1M RUM holds 1,000,000 gauges that each carry one unique 51 B UUID tag
and 4 to 10 shared tags.
- All-unique holds 1,000,000 gauges that each carry eight unique tags of
32 B to 50 B.
- Mixed churn cycles gauges, counters, rates, sets and sketches between
200,000 and 1,000,000 active contexts.

## References

- Stacked on: #3495 (`blt/1m-06-inline-singleton-set`)
- Requires: inline `SetMembers`.
- Required by: resumable flush through `u32` slot cursors, and storage
growth estimates through dense rows.
- Release note:
`releasenotes/notes/use-dense-aggregate-storage-8f83ecb8c4eaac61.yaml`

### Series overview

- Context & Tag Density (#3490–#3492, #3511): pack contexts into one
allocation and drop unused cache overhead.
- **Dense Aggregation:** replace 177 B buckets with per-kind typed
pages.
  - #3495: store singleton Set values inline
- **Current (#3496):** store live aggregate metrics in dense typed pages
indexed by u32 slots
- Resumable Flush (#3497–#3499): shrink metric buffers and interleave
bounded flush chunks.
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and
borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path
cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory
limits with idle reclaim and counted drops. 4f46054

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Rule misses return before cloning the context, while cache hits and matching rules preserve the prior filtering and telemetry outcomes. The completed static review identified no reportable defects.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 4214757

gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Dec 4, 2026
## Summary

`EventsBuffer` stores every element as an `Event` enum, which sizes each slot for the largest event type at 344 B. A `Metric` needs only 160 B. A full 1,024-event metric batch therefore reserves 344 KiB to carry 160 KiB of metrics. A 1M-context flush emits about a thousand such batches, and many wait in channels at once.

This change stores metric-only batches as `Metric` values. The buffer promotes to mixed `Event` storage when a different event type arrives. It keeps event order when it promotes, filters or drains.

This change halves the payload of a full metric buffer. Its Tier 1 effect appears together with buffer recycling and resumable flush, which lower peak memory by 155.6 MiB on 1M RUM.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p saluki-core --lib metric_backing_promotes_in_order_and_restarts_after_clear`

## References

- Stacked on: #3496 (`blt/1m-07-dense-aggregate-pages`)
- Requires: none.
- Required by: buffer recycling through typed `Metric` backing.
- Release note: `releasenotes/notes/typed-event-buffers-d3339735dc45e3a0.yaml`

### Series overview

- Context & Tag Density (#3490–#3492, #3511): pack contexts into one allocation and drop unused cache overhead.
- Dense Aggregation (#3495–#3496): replace 177 B buckets with per-kind typed pages.
- **Resumable Flush:** shrink metric buffers and interleave bounded flush chunks.
  - **Current (#3497):** add typed Metric storage to EventsBuffer
  - #3498: recycle drained EventsBuffer allocations
  - #3499: interleave bounded flush chunks with ingest
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory limits with idle reclaim and counted drops.


Co-authored-by: brian.troutwine <brian.troutwine@datadoghq.com>
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot force-pushed the blt/1m-11-borrowed-tag-filterlist branch from 4214757 to 479e24c Compare December 4, 2026 16:29

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

The static review identified no reportable defect in borrowed cache lookup or shared rule application. Human PR discussion provided no reason to change that conclusion.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 479e24c

@webern webern 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.

Looks like there might be an invisible conflict of some sort with the kernel stack. Otherwise looks simple enough.


impl TagFilterlist {
fn filter_cached(&self, metric: &mut Metric, state: &mut TagSetMutViewState) -> FilterMetricTagsOutcome {
if let Some(cached) = self.context_cache.get(metric.context()) {

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.

AI

I think #3670 adds a second per-context cache inside TagFilterKernel next to this one: a FastHashMap<Context, Option<(Context, usize)>> with a fixed DEFAULT_CONTEXT_CACHE_CAPACITY = 100_000 that clears itself when full (lib/saluki-transform-kernels/src/tag_filter.rs:498, :505, :569 on #3670). This one uses the configured aggregator_tag_filter_cache_capacity, idle expiry, hit/miss telemetry and a firm memory bound. So after both land, the component and the metric region would diverge on eviction, expiry, capacity and telemetry for the same rules.

Could we agree on a home first? One option is that the kernel owns the cache logic, built on this PR's CompiledFilters::matching (borrowed lookup, then matching, clone only on a match), and each host injects capacity and handles its own bound and telemetry. cc @lukesteenson, happy to defer to you both on the shape.

gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Dec 4, 2026
## Summary

Each aggregate flush allocates fresh `EventsBuffer` storage for every output batch and frees it once the downstream drains it. A 1M-context flush emits about a thousand batches, so the allocator sees a burst of large requests every interval. The freed storage then returns to jemalloc only for the next flush to request it again.

This change returns drained storage to a recycler local to the producing component. The recycler keeps at most one empty allocation of each kind. `Dispatcher::event_buffer_manager` lets flush code request recycled buffers for its output.

This change has no separate Tier 1 measurement. Resumable flush and the idle pipeline bypass depend on it, and resumable flush carries the measured gain.

## Change Type
- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

## How did you test this PR?

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p saluki-core --lib downstream_drain_recycles_backing_across_buffered_outputs`

## References

- Stacked on: #3497 (`blt/1m-08-typed-metric-buffer`)
- Requires: typed `Metric` storage in `EventsBuffer`.
- Required by: resumable flush and the idle pipeline bypass through `Dispatcher::event_buffer_manager`.
- Release note: `releasenotes/notes/recycle-event-buffers-1029b421ff51c533.yaml`

### Series overview

- Context & Tag Density (#3490–#3492, #3511): pack contexts into one allocation and drop unused cache overhead.
- Dense Aggregation (#3495–#3496): replace 177 B buckets with per-kind typed pages.
- **Resumable Flush:** shrink metric buffers and interleave bounded flush chunks.
  - #3497: add typed Metric storage to EventsBuffer
  - **Current (#3498):** recycle drained EventsBuffer allocations
  - #3499: interleave bounded flush chunks with ingest
- Idle Pipeline Bypass (#3500–#3501): skip inactive transforms and borrow client telemetry.
- `300m` CPU (#3502–#3507): cut encoder, codec and worker-pool hot-path cost.
- Memory Admission (#3508–#3509): enforce opt-in configured memory limits with idle reclaim and counted drops.


Co-authored-by: brian.troutwine <brian.troutwine@datadoghq.com>
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot force-pushed the blt/1m-11-borrowed-tag-filterlist branch from 479e24c to f974e41 Compare December 4, 2026 17:30

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

The borrowed cache lookup and delayed context clone preserve cache-hit behavior, tag replacements, and rule-miss outcomes.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit f974e41

@blt
blt force-pushed the blt/1m-11-borrowed-tag-filterlist branch from f974e41 to 0de076d Compare December 4, 2026 19:25

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Cache hits still apply the stored filtered context, and rule misses still pass metrics through unchanged while avoiding a context clone.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 0de076d

Base automatically changed from blt/1m-10-resumable-flush to main December 4, 2026 20:29
…t rules do not match

The `tag_filterlist` transform clones the context of every counter and sketch metric before it checks its cache or its rules. When no rule names the metric, that clone only adds an atomic reference-count increment and decrement per metric. The idle pipeline bypass also needs a filter entry point that does not own the transform's dispatch loop.

This change adds `filter_cached`, which looks up the cache with the borrowed context and checks rule names first. It clones the context only when a rule matches the metric name. Callers that borrow contexts keep the cached filter result.

This change has no separate Tier 1 measurement. The idle pipeline bypass requires `filter_cached` and carries the measured gain.

- [ ] Bug fix
- [ ] New feature
- [ ] Non-functional
- [x] Performance

- `cargo check --locked --workspace --tests`
- `cargo test --locked -p agent-data-plane --bin agent-data-plane telemetry_records_hits_misses_and_filtered_tags`

- Requires: none.
- Required by: the idle transform bypass through `filter_cached`.
- Release note: `releasenotes/notes/tag-filterlist-borrow-a2be81a44f22884a.yaml`

- Context & Tag Density: pack contexts into one allocation and drop unused cache overhead.
- Dense Aggregation: replace 177 B buckets with per-kind typed pages.
- Resumable Flush: shrink metric buffers and interleave bounded flush chunks.
- **Idle Pipeline Bypass:** skip inactive transforms and borrow client telemetry.
  - **Current:** skip context clones when `tag_filterlist` rules miss
  - PR TBD: bypass idle transforms, cache timestamps and borrow client telemetry
- `300m` CPU: cut encoder, codec and worker-pool hot-path cost.
- Memory Admission: enforce opt-in configured memory limits with idle reclaim and counted drops.
@blt

blt commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator Author

/merge -m squash

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-12-04 20:30:03 UTC ℹ️ Start processing command /merge -m squash


2026-12-04 20:30:11 UTC ℹ️ MergeQueue: Pull request is not mergeable yet

It will be processed automatically as soon as GitHub reports it as mergeable. View in MergeQueue UI.

  • Run /code blockers to see what is blocking it.
  • Run /remove to cancel it.

2026-12-04 21:07:13 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in main is approximately 2h (p90).


2026-12-04 21:28:31 UTC ℹ️ MergeQueue: This merge request was merged

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Unmatched metric names return before cloning the context, while cache hits and matched rules preserve their filtering and telemetry outcomes.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 76fd1cb

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