Skip to content

enhancement(aggregate): store live aggregate metrics in dense typed pages indexed by u32 slots - #3496

Merged
tobz merged 1 commit into
mainfrom
blt/1m-07-dense-aggregate-pages
Dec 4, 2026
Merged

tobz merged 1 commit into
mainfrom
blt/1m-07-dense-aggregate-pages

Conversation

@blt

@blt blt commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

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
  • 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: enhancement(core): store singleton Set values inline #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

@dd-octo-sts dd-octo-sts Bot added area/core Core functionality, event model, etc. area/components Sources, transforms, and destinations. transform/aggregate Aggregate transform. labels Nov 26, 2026
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 dense rows, slot repair on swap-remove, and inline packing behave the same as MetricValues::merge, and kind changes now keep the per-type gauges right. I left three non-blocking notes: overflow memory stays allocated after churn, the memory bound no longer counts overflow, and the new type-change telemetry has no test.

@datadog-prod-us1-5 datadog-prod-us1-5 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.

Bits Code Review: PASS

More details

Merge behavior, metadata retention, page compaction, and flushing showed no reportable static defects. Runtime behavior remains untested.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit a261acb

@pr-commenter

pr-commenter Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Binary Size Analysis (Agent Data Plane)

Baseline: 1a74961 · Comparison: e16b770 · diff
Analysis Configuration: optimized-release profile, stripped binaries · Pass/Fail Threshold: +5%
Sizes: 25.75 MiB (baseline) vs 25.78 MiB (comparison)
Size Change: +36.00 KiB (+0.14%)

✅ Binary size difference within threshold

Changes by Module
Module File Size Symbols
saluki_transform_kernels::aggregate::storage +17.64 KiB 10
core +7.92 KiB 41
saluki_transform_kernels::aggregate::AggregateCore<M> +4.07 KiB 2
[sections] +3.72 KiB 4
saluki_components::transforms::aggregate +2.36 KiB 5
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.12170 +2.12 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.12980 +2.12 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.12162 -2.12 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.12950 -2.12 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.13296 +2.05 KiB 1
_RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.13266 -2.05 KiB 1
_ZN12serde_saphyr2de6events33attach_alias_locations_if_missing17hd49dea7029be1b37E.12303 +1.62 KiB 1
_ZN12serde_saphyr2de6events33attach_alias_locations_if_missing17hd49dea7029be1b37E.13092 +1.62 KiB 1
_ZN12serde_saphyr2de6events33attach_alias_locations_if_missing17hd49dea7029be1b37E.12295 -1.62 KiB 1
_ZN12serde_saphyr2de6events33attach_alias_locations_if_missing17hd49dea7029be1b37E.13062 -1.62 KiB 1
hashbrown -1.37 KiB 4
_ZN17crossbeam_channel5waker9SyncWaker6notify17hb853f08e8c3932caE.14807 +949 B 1
_ZN17crossbeam_channel5waker9SyncWaker6notify17hb853f08e8c3932caE.14777 -949 B 1
smallvec +800 B 2
_RNvXs_NtNtCs27Vx93FoQ6z_4core3str7patternNtB4_12CharSearcherNtB4_8Searcher10next_match.13292 +799 B 1
Detailed Symbol Changes
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [NEW] +28.5Ki  [NEW] +28.5Ki    _<saluki_components::transforms::aggregate::Aggregate as saluki_core::components::transforms::Transform>::run::_{{closure}}::_{{closure}}::h77dcc1e258766730
  [NEW] +26.1Ki  [NEW] +26.1Ki    saluki_transform_kernels::aggregate::AggregateCore<M>::insert_with::hbb71551601c3c59f
  +1.1% +16.8Ki  +1.1% +16.6Ki    [224 Others]
  [NEW] +4.73Ki  [NEW] +4.73Ki    _ZN59_<rustls::error::Error as core::clone::Clone>5clone17h40d1888bcf0ace9bE.12454
  [NEW] +4.31Ki  [NEW] +4.31Ki    saluki_transform_kernels::aggregate::storage::Storage<M>::unlink::h6e4107d68d16398d
  [NEW] +3.74Ki  [NEW] +3.74Ki    saluki_transform_kernels::aggregate::storage::Rows<M>::push::hb7a54522fee1987b
  [NEW] +3.29Ki  [NEW] +3.29Ki    _ZN57_<rustls::error::Error as core::fmt::Debug>3fmt17hd5c00d77e4ed4348E.12455
  [NEW] +3.12Ki  [NEW] +3.12Ki    saluki_transform_kernels::aggregate::storage::Storage<M>::set_values::h28a7c0f3c876e419
  [NEW] +2.61Ki  [NEW] +2.61Ki    _ZN91_<saluki_core::data_model::tags::tagset::owned::TagSet as core::clone::Clone>5clone17h4a3e71b4d8cd8fe5E.12704
  [NEW] +2.26Ki  [NEW] +2.26Ki    _ZN57_<webpki::error::Error as core::fmt::Debug>3fmt17hfba5c0be087b6976E.12677
  +0.3% +2.14Ki  +0.3% +2.14Ki    [section .gcc_except_table]
  [NEW] +2.12Ki  [NEW] +2.12Ki    _RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.12170
  [NEW] +2.12Ki  [NEW] +2.12Ki    _RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.12980
  [DEL] -2.12Ki  [DEL] -2.12Ki    _RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.12162
  [DEL] -2.12Ki  [DEL] -2.12Ki    _RNvXst_NtNtCs27Vx93FoQ6z_4core3str7patternReNtB5_7Pattern15is_contained_in.12950
  [DEL] -2.26Ki  [DEL] -2.26Ki    _ZN57_<webpki::error::Error as core::fmt::Debug>3fmt17hfba5c0be087b6976E.12669
  [DEL] -2.61Ki  [DEL] -2.61Ki    _ZN91_<saluki_core::data_model::tags::tagset::owned::TagSet as core::clone::Clone>5clone17h4a3e71b4d8cd8fe5E.12696
  [DEL] -3.29Ki  [DEL] -3.29Ki    _ZN57_<rustls::error::Error as core::fmt::Debug>3fmt17hd5c00d77e4ed4348E.12447
  [DEL] -4.73Ki  [DEL] -4.73Ki    _ZN59_<rustls::error::Error as core::clone::Clone>5clone17h40d1888bcf0ace9bE.12446
  [DEL] -22.0Ki  [DEL] -22.0Ki    saluki_transform_kernels::aggregate::AggregateCore<M>::insert_with::h679d42712c7a4337
  [DEL] -26.7Ki  [DEL] -26.7Ki    _<saluki_components::transforms::aggregate::Aggregate as saluki_core::components::transforms::Transform>::run::_{{closure}}::_{{closure}}::haf7c00a7bffa95ad
  +0.1% +36.0Ki  +0.1% +35.9Ki    TOTAL

@pr-commenter

pr-commenter Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Regression Detector (Agent Data Plane)

Run ID: f13926e5-a9d8-4a61-8c82-bded47f3b5bf
Baseline: 1a749610 · Comparison: e16b7706 · 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_idle memory utilization ⚪ +0.49 metrics profiles logs
quality_gates_rss_dsd_low memory utilization ⚪ -0.98 metrics profiles logs
quality_gates_rss_dsd_ultraheavy memory utilization ⚪ -3.88 metrics profiles logs
quality_gates_rss_dsd_medium memory utilization ⚪ -3.98 metrics profiles logs
quality_gates_rss_dsd_heavy memory utilization ⚪ -4.81 metrics profiles logs
Bounds Checks: ✅ Passed (5)
experiment check replicates observed links
quality_gates_rss_dsd_heavy memory_usage 10/10 ✅ 170.06MiB ≤ 250MiB metrics profiles logs
quality_gates_rss_dsd_low memory_usage 10/10 ✅ 46.06MiB ≤ 55MiB metrics profiles logs
quality_gates_rss_dsd_medium memory_usage 10/10 ✅ 70.42MiB ≤ 92MiB metrics profiles logs
quality_gates_rss_dsd_ultraheavy memory_usage 10/10 ✅ 269.12MiB ≤ 420MiB metrics profiles logs
quality_gates_rss_idle memory_usage 10/10 ✅ 30.90MiB ≤ 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-07-dense-aggregate-pages branch from 65c9898 to e1d8569 Compare December 3, 2026 01:45
@blt
blt force-pushed the blt/1m-07-dense-aggregate-pages branch from e1d8569 to 2abfdf0 Compare December 3, 2026 01:47

@datadog-prod-us1-5 datadog-prod-us1-5 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.

Bits Code Review: PASS

More details

Static validation was limited by two unavailable base-version blobs and unrun tests. Production telemetry was intentionally excluded.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 2abfdf0

@blt
blt force-pushed the blt/1m-07-dense-aggregate-pages branch from 2abfdf0 to 63efc93 Compare December 3, 2026 02:05

@datadog-prod-us1-5 datadog-prod-us1-5 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.

Bits Code Review: PASS

More details

Counter flushing and expiry preserve the previous kernel’s behavior in the inspected source. Runtime behavior was not exercised, and the specialist lacked two base-file comparisons.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 63efc93

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

I have to resort to clankie 😅

The main thing it's flagging, which I think @tobz is already aware of, is that it conflicts with @lukesteensen's #3427. I think you are all aware, but I've just been catching up.

gh-worker-dd-mergequeue-cf854d 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>
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot force-pushed the blt/1m-07-dense-aggregate-pages branch from 63efc93 to dd7f2f3 Compare December 3, 2026 15:26
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-5 datadog-prod-us1-5 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.

Bits Code Review: PASS

More details

Runtime equivalence of the dense-page storage was assessed through static inspection only; tests were not run, and production telemetry was explicitly excluded.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit dd7f2f3

gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Dec 3, 2026
…hind `FlushCursor` (#3641)

## Summary

`AggregateCore` in `saluki-transform-kernels` currently exposes `contexts_and_remove_buf_mut`, `pending_removals`, `AggregatedMetric`, `FlushWindow`, `extract_closed_values`, and `expand_flushed_metric` so `AggregateState::flush` can iterate the internal `HashMap` directly across `dispatcher.push(...).await`.

This follow-up PR encapsulates the internal storage and flush mechanics behind an opaque `FlushCursor` API:

- Add `AggregateCore::begin_flush`, `AggregateCore::flush_chunk`, and `AggregateCore::finish_flush`.
- Add `AggregateCore::entry_size_bytes()` so callers account for memory bounds without depending on `AggregatedMetric`.
- Keep `AggregatedMetric`, `FlushWindow`, `extract_closed_values`, and `expand_flushed_metric` private inside `saluki-transform-kernels::aggregate`.
- Re-check emptiness in `finish_flush` before removing pending contexts so samples inserted between flush chunks are never dropped.
- Update `lib/saluki-components/src/transforms/aggregate/mod.rs` to drive flushes in bounded 1,024-context chunks and drop the mutable borrow on `AggregateCore` before awaiting downstream dispatch.

This keeps #3427 strictly mechanical while giving future dense aggregate storage (#3496) and interleaved resumable flushes (#3499) a clean crate boundary.

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

## How did you test this PR?

- `cargo check --workspace --tests`
- `cargo clippy -p saluki-transform-kernels -p saluki-components --all-targets -- -D warnings`
- `cargo nextest run -p saluki-transform-kernels` (34/34 passed, including `chunked_flush_cursor_matches_full_flush_and_preserves_interleaved_inserts`)
- `cargo nextest run -p saluki-components -E 'test(transforms::aggregate)'` (41/41 passed)
- `make fmt`

## References

- Stacked on: #3427 (`programmable-phase1-metric-kernels`)
- Required by: #3424 (`programmable-exploration`)

Co-authored-by: luke.steensen <luke.steensen@datadoghq.com>
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>
Base automatically changed from blt/1m-06-inline-singleton-set to main December 3, 2026 17:40
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>

@datadog-prod-us1-5 datadog-prod-us1-5 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.

Bits Code Review: PASS

More details

Metric merging, metadata retention, and flush behavior appear preserved under static analysis. Runtime behavior and memory characteristics were not validated by execution.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit dd7f2f3

…ages indexed by u32 slots

Move dense typed-page Storage<M> into saluki-transform-kernels::aggregate (replacing HashMap<Context, AggregatedMetric<M>> inside AggregateCore<M>), keep saluki-components/src/transforms/aggregate/mod.rs as a thin wrapper, add merge-then-spill parity tests for every metric kind, and expose aggregate_overflow_contexts and aggregate_overflow_capacity_bytes debug gauges.
@blt
blt force-pushed the blt/1m-07-dense-aggregate-pages branch from dd7f2f3 to e16b770 Compare December 3, 2026 19:00

@datadog-prod-us1-5 datadog-prod-us1-5 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.

Bits Code Review: PASS

More details

Overflow-store retention under sustained distribution traffic and the reported memory/CPU gains remain unverified at runtime.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit e16b770

@tobz tobz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm approving this with the caveat, and the caveat is mostly as a reminder to myself and sort of... let's call it an open challenge: I think this is very complex and could stand to be simplified.

It works, obviously, and tests pass... but it feels too clever and I have a nagging feeling that it could stand to be a lot simpler. My growing worry with this stack is that while we are certainly heading towards a vast performance improvement, we're doing so in a way where our grasp on how the system works, and why it performs the way it does, is rapidly loosening. Basically, I don't want to consider this stack to be the end state, but more of a "now that we've gotten things improved, let's see if we can't reorient it back towards fitting our ideals around simplicity, layering of basic building blocks, etc".

@tobz
tobz merged commit 4f46054 into main Dec 4, 2026
140 checks passed
@tobz
tobz deleted the blt/1m-07-dense-aggregate-pages branch 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
@blt

blt commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator Author

I'm approving this with the caveat, and the caveat is mostly as a reminder to myself and sort of... let's call it an open challenge: I think this is very complex and could stand to be simplified.

It works, obviously, and tests pass... but it feels too clever and I have a nagging feeling that it could stand to be a lot simpler. My growing worry with this stack is that while we are certainly heading towards a vast performance improvement, we're doing so in a way where our grasp on how the system works, and why it performs the way it does, is rapidly loosening. Basically, I don't want to consider this stack to be the end state, but more of a "now that we've gotten things improved, let's see if we can't reorient it back towards fitting our ideals around simplicity, layering of basic building blocks, etc".

Fully onboard. You have a more cohesive notion of the system as a whole compared to me so while I expect there's a tidier means of representing this I don't have the inherent context to imagine it.

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 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 Bot pushed a commit that referenced this pull request Dec 4, 2026
…3499)

## Summary

The aggregator flushes every 15 s in one blocking pass over all rows. On 1M RUM, the median flush takes 3.38 s to 3.43 s. On 1M all-unique, it takes 7.71 s to 8.85 s. Ingest stops during that pass, so receive buffers fill and cgroup peaks reach 1,796 MiB to 2,865 MiB.

Moving the flush onto another task cannot fix this, because that task would have to copy or lock the whole aggregate state. This change walks rows in chunks of at most 1,024 against a fixed cutoff. A `select!` loop interleaves each chunk with ingest and keeps ingesting while a downstream send waits.

A late update does not change output that the current flush already detached. The change also adds a fast path for gauges with one buffered point and an `adp.aggregate_flush_duration_seconds` histogram.

Stripped `optimized-release` Tier 1 runs show peak memory falling by 155.6 MiB on 1M RUM, 259.0 MiB on all-unique and 107.6 MiB on mixed churn. Resulting peaks are 383.2 MiB, 779.7 MiB and 314.9 MiB, and each run holds its active contexts with zero drops.

## 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 owner_ingests_while_downstream_is_full_and_finishes_shutdown`
- 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: #3498 (`blt/1m-09-recycle-events-buffer`)
- Requires: dense aggregate pages, and recycled `EventsBuffer` allocations.
- Required by: none.
- Release note: `releasenotes/notes/aggregate-flush-telemetry-51041394316097e8.yaml`, `releasenotes/notes/resumable-aggregate-flush-ca660bb52fb10d0d.yaml`, `releasenotes/notes/singleton-gauge-flush-1ba31cf63b01e203.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
  - #3498: recycle drained EventsBuffer allocations
  - **Current (#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 Bot pushed a commit that referenced this pull request Dec 4, 2026
…t rules do not match (#3500)

## 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
- [x] 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

- Stacked on: #3499 (`blt/1m-10-resumable-flush`)
- Requires: none.
- Required by: the idle transform bypass through `filter_cached`.
- Release note: `releasenotes/notes/tag-filterlist-borrow-a2be81a44f22884a.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 (#3497–#3499): shrink metric buffers and interleave bounded flush chunks.
- **Idle Pipeline Bypass:** skip inactive transforms and borrow client telemetry.
  - **Current (#3500):** skip context clones when tag_filterlist rules do not match
  - #3501: bypass idle DogStatsD transforms, cache buffer timestamps 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/components Sources, transforms, and destinations. area/core Core functionality, event model, etc. transform/aggregate Aggregate transform.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants