Commit 9498ca86 authored by Charles Zhao's avatar Charles Zhao Committed by Commit Bot

TabDiscarder: better discard count scorer.

High discard count also means high reload count, which indicates the
user is more likely to come back to this tab. Therefore it should have
higher scorer.

Changed how discard count is scored.

Bug: 948915

Change-Id: Ifea930bfb3aab6bb4eb86a05e4ae949631d55e13
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1560931Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Commit-Queue: Charles . <charleszhao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649763}
parent 58f52eb9
...@@ -26,10 +26,21 @@ using resource_coordinator::GetDiscardCountPenaltyTabRanker; ...@@ -26,10 +26,21 @@ using resource_coordinator::GetDiscardCountPenaltyTabRanker;
using resource_coordinator::GetMRUScorerPenaltyTabRanker; using resource_coordinator::GetMRUScorerPenaltyTabRanker;
using resource_coordinator::GetScorerTypeForTabRanker; using resource_coordinator::GetScorerTypeForTabRanker;
// ReverseRank maps a positive number to the range (0.0, 1.0). // Maps the |mru_index| to it's reverse rank in (0.0, 1.0).
inline float ReverseRank(const float a) { // High score means more likely to be reactivated.
DCHECK_GE(a, 0.0f); // We use inverse rank because we think that the first several |mru_index| is
return 1.0f / (1.0f + a); // more significant than the larger ones.
inline float MruToScore(const float mru_index) {
DCHECK_GE(mru_index, 0.0f);
return 1.0f / (1.0f + mru_index);
}
// Maps the |discard_count| to a score in (0.0, 1.0), for which
// High score means more likely to be reactivated.
// We use std::exp because we think that the first several |discard_count| is
// not as significant as the larger ones.
inline float DiscardCountToScore(const float discard_count) {
return std::exp(discard_count);
} }
// Loads the preprocessor config protobuf, which lists each feature, their // Loads the preprocessor config protobuf, which lists each feature, their
...@@ -83,8 +94,8 @@ TabRankerResult TabScorePredictor::ScoreTab(const TabFeatures& tab, ...@@ -83,8 +94,8 @@ TabRankerResult TabScorePredictor::ScoreTab(const TabFeatures& tab,
// The default value of discard_count_penalty_ is 0.0f, which will not change // The default value of discard_count_penalty_ is 0.0f, which will not change
// the score. // the score.
// The larger the |discard_count_penalty_| is (set from Finch), the quicker // The larger the |discard_count_penalty_| is (set from Finch), the quicker
// the score decreases based on the discard_count. // the score increases based on the discard_count.
*score *= ReverseRank(tab.discard_count * discard_count_penalty_); *score *= DiscardCountToScore(tab.discard_count * discard_count_penalty_);
return result; return result;
} }
...@@ -142,7 +153,7 @@ TabRankerResult TabScorePredictor::ScoreTabWithMLScorer(const TabFeatures& tab, ...@@ -142,7 +153,7 @@ TabRankerResult TabScorePredictor::ScoreTabWithMLScorer(const TabFeatures& tab,
TabRankerResult TabScorePredictor::ScoreTabWithMRUScorer(const TabFeatures& tab, TabRankerResult TabScorePredictor::ScoreTabWithMRUScorer(const TabFeatures& tab,
float* score) { float* score) {
*score = ReverseRank(tab.mru_index * mru_scorer_penalty_); *score = MruToScore(tab.mru_index * mru_scorer_penalty_);
return TabRankerResult::kSuccess; return TabRankerResult::kSuccess;
} }
......
...@@ -65,13 +65,13 @@ TEST_F(TabScorePredictorTest, ScoreWithDiscardPenalty) { ...@@ -65,13 +65,13 @@ TEST_F(TabScorePredictorTest, ScoreWithDiscardPenalty) {
scoped_feature_list_.InitAndEnableFeatureWithParameters( scoped_feature_list_.InitAndEnableFeatureWithParameters(
features::kTabRanker, {{"scorer_type", "0"}, features::kTabRanker, {{"scorer_type", "0"},
{"mru_scorer_penalty", "0.2345"}, {"mru_scorer_penalty", "0.2345"},
{"discard_count_penalty", "0.5678"}}); {"discard_count_penalty", "0.2468"}});
// Pre-calculated score using the generated model outside of Chrome. // Pre-calculated score using the generated model outside of Chrome.
auto tab = GetFullTabFeaturesForTesting(); auto tab = GetFullTabFeaturesForTesting();
EXPECT_FLOAT_EQ(ScoreTab(tab), 0.13639774); EXPECT_FLOAT_EQ(ScoreTab(tab), 0.13639774);
tab.discard_count = 3; tab.discard_count = 3;
EXPECT_FLOAT_EQ(ScoreTab(tab), 0.05045415); EXPECT_FLOAT_EQ(ScoreTab(tab), 0.28599524);
} }
} // namespace tab_ranker } // namespace tab_ranker
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment