summaryrefslogtreecommitdiff
path: root/absl/strings/cord.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2021-05-10 12:57:06 -0700
committerGravatar vslashg <gfalcon@google.com>2021-05-11 09:59:12 -0400
commit7ba826e50dff1878e6ecc6b9af44097c040c8968 (patch)
treea465938ae07904733beafdaa830866dbe8cbc7ac /absl/strings/cord.cc
parent079cf662544a14bd1cfaae6d6512645541ba10fb (diff)
Export of internal Abseil changes
-- 5f3c139695d5c497ca030e95a607537a7be7caa7 by Benjamin Barenblat <bbaren@google.com>: Don’t examine irrelevant destination buckets in DiscreteDistributionTest Abseil generates discrete distributions using Walker’s aliasing algorithm. This creates uniformly distributed buckets, each with a probability of sending traffic to a different bucket. Abseil represents a bucket as a pair (probability of retaining traffic × alternate bucket if traffic is passed) and a distribution as a vector of such pairs. For example, {(0.3, 1), (1.0, 1)} represents a distribution with two buckets, the zeroth of which passes 70% of its traffic to bucket 1 and the first of which holds on to all its traffic. This representation is not unique: When a bucket retains traffic with probability 1, the alternate bucket is irrelevant. Continuing the example above, {(0.3, 1), (1.0, 0)} _also_ represents a two-bucket distribution where the zeroth bucket passes 70% of its traffic to the first and the first hangs on to all traffic. Exactly what representation Abseil generates for a given input is related to how much precision is used in intermediate floating-point operations, which is an architectural implementation detail. Remove sensitivity to that detail by not examining the alternate bucket when the retention probability is 1.0. PiperOrigin-RevId: 372993410 -- 062ac80699f748831c09a061538abffec2cdea5c by Martijn Vels <mvels@google.com>: Avoid alredy sampled cord remaining sampled if not picked or source is sampled PiperOrigin-RevId: 372985990 -- a9f3537e1110b7bb6450fd72a03f0c5dc6b8c89b by Evan Brown <ezb@google.com>: Add tests for function pointer comparators, comparators that have SFINAE-visible comparison operators that are unimplemented, and for implicit construction from unadapted comparators. PiperOrigin-RevId: 372927616 GitOrigin-RevId: 5f3c139695d5c497ca030e95a607537a7be7caa7 Change-Id: I996a8452e7bd88f9dd2e59633b01bbc09f42620d
Diffstat (limited to 'absl/strings/cord.cc')
-rw-r--r--absl/strings/cord.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/absl/strings/cord.cc b/absl/strings/cord.cc
index 238532f9..5dad781e 100644
--- a/absl/strings/cord.cc
+++ b/absl/strings/cord.cc
@@ -535,6 +535,23 @@ void Cord::InlineRep::AssignSlow(const Cord::InlineRep& src) {
EmplaceTree(CordRep::Ref(src.as_tree()), src.data_, method);
return;
}
+
+ // See b/187581164: unsample cord if already sampled
+ // TODO(b/117940323): continuously 'assigned to' cords would reach 100%
+ // sampling probability. Imagine a cord x in some cache:
+ // cache.SetCord(const Cord& foo) {
+ // x = foo;
+ // }
+ // CordzInfo::MaybeTrackCord does:
+ // x.profiled = foo.profiled | x.profiled | random(cordz_mean_interval)
+ // Which means it will on the long run converge to 'always samples'
+ // The real fix is in CordzMaybeTrackCord, but the below is a low risk
+ // forward fix for b/187581164 and similar BT benchmark regressions.
+ if (ABSL_PREDICT_FALSE(is_profiled())) {
+ cordz_info()->Untrack();
+ clear_cordz_info();
+ }
+
CordRep* tree = as_tree();
if (CordRep* src_tree = src.tree()) {
data_.set_tree(CordRep::Ref(src_tree));