DataDog / saluki

An experimental toolkit for building telemetry data planes in Rust.
Apache License 2.0
12 stars 2 forks source link

[APR-205] experiment: refactor `MetaString` to shrink size by one machine word #187

Closed tobz closed 2 weeks ago

tobz commented 1 month ago

Context

Currently, MetaString is four machine words (32 bytes on 64-bit) large, while a normal String is three machine words (24 bytes). This is due to the overhead of the enum discriminant field: while only a u8 is needed to encode all the discriminants, alignment requirements round this up to usize, on top of the largest variant (String), thus leaving us with four machine words.

Overall, this is less than ideal because we're always paying just a little more in memory to store a MetaString than a String, and double and quadruple the size cost of an Arc<str> and InternedString, respectively.

Solution

This PR introduces a refactored MetaString based on a hand-rolled enum pattern using unions. This design encodes the discriminant into the data fields themselves by virtue of valid/invalid bitpatterns for those fields, allowing us to decode the information necessary to extract the discriminant on access.

MetaString still supports all four primary variants -- owned (String), static (&'static str), interned (InternedString), and inlined -- allow the maximum size of an inlined string is now 23 bytes, instead of 31 bytes, as we're limited by the overall size of the structure.

pr-commenter[bot] commented 1 month ago

Regression Detector (DogStatsD)

Regression Detector Results

Run ID: 420bc452-fbd2-429c-909c-16511f01d8c9

Baseline: 7.55.2 Comparison: 7.55.3

Performance changes are noted in the perf column of each table:

No significant changes in experiment optimization goals

Confidence level: 90.00% Effect size tolerance: |Δ mean %| ≥ 5.00%

There were no significant changes in experiment optimization goals at this confidence level and effect size tolerance.

Fine details of change detection per experiment

| perf | experiment | goal | Δ mean % | Δ mean % CI | links | |------|----------------------------------------------|--------------------|----------|----------------|-------| | ➖ | dsd_uds_1mb_3k_contexts | ingress throughput | +0.08 | [+0.02, +0.15] | | | ➖ | dsd_uds_1mb_50k_contexts_memlimit | ingress throughput | +0.00 | [-0.03, +0.04] | | | ➖ | dsd_uds_512kb_3k_contexts | ingress throughput | +0.00 | [-0.05, +0.05] | | | ➖ | dsd_uds_1mb_50k_contexts | ingress throughput | +0.00 | [-0.03, +0.03] | | | ➖ | dsd_uds_500mb_3k_contexts | ingress throughput | -0.00 | [-0.00, +0.00] | | | ➖ | dsd_uds_100mb_250k_contexts | ingress throughput | -0.00 | [-0.02, +0.01] | | | ➖ | dsd_uds_100mb_3k_contexts | ingress throughput | -0.01 | [-0.02, -0.00] | | | ➖ | dsd_uds_10mb_3k_contexts | ingress throughput | -0.01 | [-0.05, +0.02] | | | ➖ | dsd_uds_100mb_3k_contexts_distributions_only | memory utilization | -1.92 | [-2.14, -1.69] | |

Explanation

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI". For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true: 1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look. 2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that *if our statistical model is accurate*, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants. 3. Its configuration does not mark it "erratic".
pr-commenter[bot] commented 1 month ago

Regression Detector (Saluki)

Regression Detector Results

Run ID: 712f4263-41e8-4fda-b43d-afe3cc4f9a64

Baseline: ca65c5ba3b4b7024db10d30a08507f116f4d1a36 Comparison: 8b95bc593c0ed64f467edd2c5a1a25db3155c124

Performance changes are noted in the perf column of each table:

Significant changes in experiment optimization goals

Confidence level: 90.00% Effect size tolerance: |Δ mean %| ≥ 5.00%

perf experiment goal Δ mean % Δ mean % CI links
dsd_uds_1mb_50k_contexts_memlimit ingress throughput +6.91 [+3.54, +10.27]

Fine details of change detection per experiment

| perf | experiment | goal | Δ mean % | Δ mean % CI | links | |------|-------------------------------------------------|--------------------|----------|-----------------|-------| | ✅ | dsd_uds_1mb_50k_contexts_memlimit | ingress throughput | +6.91 | [+3.54, +10.27] | | | ➖ | dsd_uds_100mb_250k_contexts | ingress throughput | +0.04 | [-0.23, +0.30] | | | ➖ | dsd_uds_512kb_3k_contexts | ingress throughput | +0.00 | [-0.05, +0.06] | | | ➖ | dsd_uds_50mb_10k_contexts_no_inlining | ingress throughput | +0.00 | [-0.00, +0.00] | | | ➖ | dsd_uds_50mb_10k_contexts_no_inlining_no_allocs | ingress throughput | -0.00 | [-0.04, +0.04] | | | ➖ | dsd_uds_1mb_3k_contexts | ingress throughput | -0.01 | [-0.05, +0.04] | | | ➖ | dsd_uds_100mb_3k_contexts | ingress throughput | -0.01 | [-0.01, -0.00] | | | ➖ | dsd_uds_1mb_50k_contexts | ingress throughput | -0.02 | [-0.03, +0.00] | | | ➖ | dsd_uds_10mb_3k_contexts | ingress throughput | -0.04 | [-0.08, -0.00] | | | ➖ | dsd_uds_100mb_3k_contexts_distributions_only | memory utilization | -0.42 | [-0.57, -0.27] | | | ➖ | dsd_uds_500mb_3k_contexts | ingress throughput | -1.85 | [-1.95, -1.75] | |

Explanation

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI". For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true: 1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look. 2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that *if our statistical model is accurate*, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants. 3. Its configuration does not mark it "erratic".
pr-commenter[bot] commented 1 month ago

Regression Detector Links

Experiment Result Links

experiment link(s)
dsd_uds_100mb_250k_contexts [Profiling (ADP)] [Profiling (DSD)] [SMP Dashboard]
dsd_uds_100mb_3k_contexts [Profiling (ADP)] [Profiling (DSD)] [SMP Dashboard]
dsd_uds_100mb_3k_contexts_distributions_only [Profiling (ADP)] [Profiling (DSD)] [SMP Dashboard]
dsd_uds_10mb_3k_contexts [Profiling (ADP)] [Profiling (DSD)] [SMP Dashboard]
dsd_uds_1mb_3k_contexts [Profiling (ADP)] [Profiling (DSD)] [SMP Dashboard]
dsd_uds_1mb_50k_contexts [Profiling (ADP)] [Profiling (DSD)] [SMP Dashboard]
dsd_uds_1mb_50k_contexts_memlimit [Profiling (ADP)] [Profiling (DSD)] [SMP Dashboard]
dsd_uds_500mb_3k_contexts [Profiling (ADP)] [Profiling (DSD)] [SMP Dashboard]
dsd_uds_512kb_3k_contexts [Profiling (ADP)] [Profiling (DSD)] [SMP Dashboard]
dsd_uds_50mb_10k_contexts_no_inlining (ADP only) [Profiling (ADP)] [SMP Dashboard]
dsd_uds_50mb_10k_contexts_no_inlining_no_allocs (ADP only) [Profiling (ADP)] [SMP Dashboard]