@@ -398,15 +398,29 @@ StatusOr<std::optional<GlyphSet>> Merger::MergeSegmentWithCosts(
398398double Merger::BestCaseInertProbabilityThreshold (
399399 uint32_t base_patch_size, double base_probability, double lowest_cost_delta
400400) const {
401- // For a merge of an inert base patch with any other inert segment, this
402- // computes the minimum probability the other segment must have for
403- // it to be possible to produce a delta lower than lowest_cost_delta.
401+ // The following assumptions are made:
402+ // - P(base) >= P( other)
403+ // - the best case merged size is max(base_size, other_size) + k
404404 //
405- // This formula is derived by making the following assumptions:
406- // - The probability of the merged segment = base_probability.
407- // - The size of the merged patch is (base_patch_size + BEST_CASE_MERGE_SIZE_DELTA)
405+ // Then if we start with the formula for the cost delta of an inert merge:
408406 //
409- // These two assumptions give the best possible cost delta for the merge.
407+ // P(merged) * merged_size - P(base) * base_size - P(other) * other_size
408+ //
409+ // (here all sizes include the network overhead delta).
410+ //
411+ // And consider what valid values of P(merged), and other_size will produce the
412+ // lowest total delta we find that this happens when:
413+ // - P(merged) = P(base)
414+ // - other_size = base_size
415+ // - merged_size = base_size + k
416+ //
417+ // From that we find that the smallest possible delta is:
418+ //
419+ // min(cost delta) = P(base) * k - P(other) * base_size
420+ //
421+ // From which we find that:
422+ //
423+ // P(other) > (k * P(base) - lowest_cost_delta) / base_size
410424 base_patch_size += Strategy ().NetworkOverheadCost ();
411425 return std::min (1.0 , std::max (0.0 ,
412426 (((double ) BEST_CASE_MERGE_SIZE_DELTA) * base_probability - lowest_cost_delta) / ((double ) base_patch_size)));
0 commit comments