Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mutating of tags on contexts. #121

Merged
merged 3 commits into from
Jul 19, 2024
Merged

Allow mutating of tags on contexts. #121

merged 3 commits into from
Jul 19, 2024

Conversation

tobz
Copy link
Member

@tobz tobz commented Jul 19, 2024

Context

Currently, contexts are effectively immutable because we initially wanted to focus on making them able to be cached and "resolvable" (looked up with a borrowed version of the name/tags) without needing any allocations. Doing so involves caching their hashed value, which meant avoiding mutating the name/tags to avoid messing with the hash value and breaking how they were stored (which is in a hashset).

Solution

This PR adds back the ability to mutate tags. When acquiring a mutable reference to the tags on a context, we do a clone-on-write approach with the inner state, which clones it if there's another reference to the inner state. As such, this creates a new context which can then be modified as much as possible without further cloning, since it's now owned independently of the original context.

Additionally, we've also tweaked the handling of the context's hash value to mark a context as "dirty" when we do anything mutable with the tags, which causes its Hash implementation to flip back to hashing on demand instead of using the cached value.

This is a little suboptimal for a few reasons:

  • we end up cloning the tag set (the tags themselves are still potentially inlined/interned, but we have to allocate for the Vec<Tag>)
  • the new context isn't pushed back into the context resolver
  • no more cached hash value

I think this is acceptable for the moment, because:

  • the tags themselves are the heaviest part, so only allocating one Vec<Tag> is a lot better than allocating Vec<Tag> and N tags
  • improving the above would involve far more complex changes, along the lines of an intrusive linked list: not sure the juice is worth the squeeze on that (at least not yet sure)
  • not pushing the new context into the resolver is also likely OK because since we know we're about to modify the context, it's virtually certain that incoming resolve calls wouldn't ever match it anyways so there's no good reason to track it anyways
  • hashing is already very fast, so we're not killing ourselves by potentially doing a little more of it downstream in the pipeline

@tobz tobz added the type/enhancement An enhancement in functionality or support. label Jul 19, 2024
@tobz tobz requested a review from a team as a code owner July 19, 2024 15:29
@github-actions github-actions bot added the area/core Core functionality, event model, etc. label Jul 19, 2024
@tobz tobz changed the title context: allow mutating of tags on context Allow mutating of tags on contexts. Jul 19, 2024
@pr-commenter
Copy link

pr-commenter bot commented Jul 19, 2024

Regression Detector (DogStatsD)

Regression Detector Results

Run ID: d5d12a44-8643-446a-8e12-b5b23af98d04

Baseline: 7.52.0
Comparison: 7.52.1

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

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

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.07 [+0.00, +0.13]
dsd_uds_100mb_3k_contexts ingress throughput +0.00 [-0.01, +0.02]
dsd_uds_500mb_3k_contexts ingress throughput +0.00 [+0.00, +0.01]
dsd_uds_100mb_250k_contexts ingress throughput -0.00 [-0.05, +0.04]
dsd_uds_1mb_50k_contexts_memlimit ingress throughput -0.02 [-0.06, +0.02]
dsd_uds_512kb_3k_contexts ingress throughput -0.02 [-0.07, +0.04]
dsd_uds_10mb_3k_contexts ingress throughput -0.03 [-0.07, +0.00]
dsd_uds_1mb_50k_contexts ingress throughput -0.03 [-0.09, +0.02]
dsd_uds_100mb_3k_contexts_distributions_only memory utilization -1.75 [-1.97, -1.54]

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
Copy link

pr-commenter bot commented Jul 19, 2024

Regression Detector (Saluki)

Regression Detector Results

Run ID: d281d9cc-6c7e-4ae5-a656-65ff90bc5313

Baseline: 57d2912
Comparison: a567311

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

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

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_100mb_3k_contexts_distributions_only memory utilization +1.32 [+1.20, +1.44]
dsd_uds_500mb_3k_contexts ingress throughput +0.96 [+0.82, +1.11]
dsd_uds_1mb_50k_contexts_memlimit ingress throughput +0.64 [-2.51, +3.80]
dsd_uds_10mb_3k_contexts ingress throughput +0.08 [+0.01, +0.15]
dsd_uds_512kb_3k_contexts ingress throughput +0.01 [-0.05, +0.07]
dsd_uds_100mb_3k_contexts ingress throughput +0.00 [-0.01, +0.02]
dsd_uds_50mb_10k_contexts_no_inlining_no_allocs ingress throughput +0.00 [-0.05, +0.05]
dsd_uds_50mb_10k_contexts_no_inlining ingress throughput -0.00 [-0.00, +0.00]
dsd_uds_1mb_50k_contexts ingress throughput -0.00 [-0.02, +0.02]
dsd_uds_1mb_3k_contexts ingress throughput -0.01 [-0.06, +0.04]
dsd_uds_100mb_250k_contexts ingress throughput -0.29 [-0.49, -0.08]

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

@tobz tobz merged commit 8bda909 into main Jul 19, 2024
13 checks passed
@tobz tobz deleted the tobz/mutable-context-tags branch July 19, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core Core functionality, event model, etc. type/enhancement An enhancement in functionality or support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant