Skip to content

enhancement(common): add opinionated string builder helper#847

Merged
tobz merged 9 commits intomainfrom
tobz/interned-string-builder
Sep 23, 2025
Merged

enhancement(common): add opinionated string builder helper#847
tobz merged 9 commits intomainfrom
tobz/interned-string-builder

Conversation

@tobz
Copy link
Member

@tobz tobz commented Aug 4, 2025

Summary

This PR adds StringBuilder, a classical "string builder" helper type that allows building strings on top of reusable backing storage. It is primarily designed for our common paradigms, which means that it has first-class support for fallibly building strings based on a user-configurable size limit, such that we can do bounded/deterministic memory usage things on top of it. Going further, it also supports being connected to a string interner to allow building strings that then get interned directly.

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

How did you test this PR?

New unit tests.

References

AGTMETRICS-233

@github-actions github-actions bot added area/core Core functionality, event model, etc. area/memory Memory bounds and memory management. labels Aug 4, 2025
Copy link
Member Author

tobz commented Aug 4, 2025

@pr-commenter
Copy link

pr-commenter bot commented Aug 4, 2025

Regression Detector (DogStatsD)

Regression Detector Results

Run ID: d912f9fe-9480-4e16-bf1c-b2c5df5699fc

Baseline: 7.68.3
Comparison: 7.68.3

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gates_idle_rss memory utilization +0.49 [+0.43, +0.54] 1
dsd_uds_1mb_50k_contexts ingress throughput +0.00 [-0.00, +0.00] 1
dsd_uds_512kb_3k_contexts ingress throughput +0.00 [-0.01, +0.01] 1
dsd_uds_10mb_3k_contexts ingress throughput -0.00 [-0.00, +0.00] 1
dsd_uds_100mb_250k_contexts ingress throughput -0.00 [-0.00, +0.00] 1
dsd_uds_100mb_3k_contexts ingress throughput -0.00 [-0.11, +0.11] 1
dsd_uds_1mb_50k_contexts_memlimit ingress throughput -0.00 [-0.00, +0.00] 1
dsd_uds_1mb_3k_contexts ingress throughput -0.00 [-0.00, +0.00] 1
dsd_uds_1mb_3k_contexts_dualship ingress throughput -0.00 [-0.00, +0.00] 1
dsd_uds_100mb_3k_contexts_distributions_only memory utilization -0.00 [-0.17, +0.16] 1
dsd_uds_500mb_3k_contexts ingress throughput -1.99 [-2.07, -1.91] 1

Bounds Checks: ❌ Failed

perf experiment bounds_check_name replicates_passed links
quality_gates_idle_rss memory_usage 0/10

Explanation

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

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

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 Aug 4, 2025

Regression Detector (Saluki)

Regression Detector Results

Run ID: 5351e85c-7c2d-413b-8c61-e70fbeca74ff

Baseline: b5de018
Comparison: b6fab24
Diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gates_idle_rss memory utilization +1.63 [+1.61, +1.65] 1
dsd_uds_100mb_3k_contexts_distributions_only memory utilization +0.60 [+0.42, +0.78] 1
dsd_uds_1mb_50k_contexts ingress throughput +0.02 [+0.00, +0.05] 1
dsd_uds_50mb_10k_contexts_no_inlining ingress throughput +0.02 [-0.10, +0.13] 1
dsd_uds_1mb_3k_contexts_dualship ingress throughput +0.01 [-0.00, +0.02] 1
dsd_uds_512kb_3k_contexts ingress throughput +0.01 [-0.01, +0.02] 1
dsd_uds_100mb_250k_contexts ingress throughput +0.00 [-0.04, +0.04] 1
dsd_uds_10mb_3k_contexts ingress throughput +0.00 [-0.04, +0.04] 1
dsd_uds_1mb_50k_contexts_memlimit ingress throughput -0.00 [-0.01, +0.01] 1
dsd_uds_100mb_3k_contexts ingress throughput -0.00 [-0.06, +0.06] 1
dsd_uds_1mb_3k_contexts ingress throughput -0.00 [-0.01, +0.00] 1
dsd_uds_50mb_10k_contexts_no_inlining_no_allocs ingress throughput -0.03 [-0.14, +0.09] 1
dsd_uds_500mb_3k_contexts ingress throughput -1.36 [-1.48, -1.24] 1

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed links
quality_gates_idle_rss memory_usage 10/10

Explanation

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

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

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 Aug 4, 2025

Regression Detector (ADP && Checks)

Regression Detector Results

Run ID: fb14e184-4220-41b8-8bcc-a6d69a0a1d77

Baseline: b745e4f
Comparison: 93836ac
Diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gates_idle_rss memory utilization -0.01 [-0.03, +0.00] 1
quality_gates_rss memory utilization -0.09 [-0.12, -0.06] 1

Bounds Checks: ❌ Failed

perf experiment bounds_check_name replicates_passed links
quality_gates_idle_rss memory_usage 10/10
quality_gates_rss memory_usage 0/10

Explanation

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

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

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 Aug 4, 2025

Regression Detector Links

ADP 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_3k_contexts_dualship [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]
quality_gates_idle_rss [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]

ADP && Checks Experiment Result Links

experiment link(s)
quality_gates_idle_rss [Profiling] [SMP Dashboard]
quality_gates_rss [Profiling] [SMP Dashboard]

@tobz tobz force-pushed the tobz/interned-string-builder branch from 543d371 to ac12551 Compare August 5, 2025 16:46
@tobz tobz force-pushed the tobz/interner-trait branch from 7d975a1 to 77ebcd4 Compare August 5, 2025 16:46
Base automatically changed from tobz/interner-trait to main August 5, 2025 18:54
@tobz tobz added the type/enhancement An enhancement in functionality or support. label Aug 5, 2025
@tobz tobz changed the title enhancement(common): add string builder for building interned strings enhancement(common): add opinionated string build helper Aug 5, 2025
@tobz tobz force-pushed the tobz/interned-string-builder branch from ac12551 to 9772eb2 Compare August 5, 2025 19:09
@tobz tobz marked this pull request as ready for review August 5, 2025 19:10
@tobz tobz requested a review from a team as a code owner August 5, 2025 19:10
@tobz tobz changed the title enhancement(common): add opinionated string build helper enhancement(common): add opinionated string builder helper Aug 5, 2025
/// Returns `None` if the string exceeds the configured limit or if it cannot be interned.
pub fn try_intern(&mut self) -> Option<MetaString> {
let interned = self.interner.try_intern(self.string());
self.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we okay with clearing even if the interner fails?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a fair question.

We don't automatically do anything along those lines when just calling StringBuilder::string, so having it happen for try_intern is divergent.

My thought process was that if you're bothering to intern at all, you probably only want the resulting string if it can be interned... but admittedly, that might be a bit too restrictive.

I'll change this to avoid clearing the builder at all in try_intern.

@tobz tobz force-pushed the tobz/interned-string-builder branch from 9772eb2 to e14ab72 Compare August 17, 2025 19:13
@tobz tobz force-pushed the tobz/interned-string-builder branch from e14ab72 to ee97b83 Compare September 22, 2025 17:40
@tobz tobz merged commit faea5ca into main Sep 23, 2025
46 checks passed
@tobz tobz deleted the tobz/interned-string-builder branch September 23, 2025 13:02
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. area/memory Memory bounds and memory management. type/enhancement An enhancement in functionality or support.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants