[clang-tools-extra] r337907 - [clangd] Use a sigmoid style function for #usages boost in symbol quality.
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 25 04:26:35 PDT 2018
Author: ioeric
Date: Wed Jul 25 04:26:35 2018
New Revision: 337907
URL: http://llvm.org/viewvc/llvm-project?rev=337907&view=rev
Log:
[clangd] Use a sigmoid style function for #usages boost in symbol quality.
Summary:
This has a shape to similar logarithm function but grows much slower for
large #usages.
Metrics: https://reviews.llvm.org/P8096
Reviewers: ilya-biryukov
Reviewed By: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, cfe-commits, sammccall
Differential Revision: https://reviews.llvm.org/D49780
Modified:
clang-tools-extra/trunk/clangd/Quality.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=337907&r1=337906&r2=337907&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Wed Jul 25 04:26:35 2018
@@ -190,8 +190,18 @@ float SymbolQualitySignals::evaluate() c
// This avoids a sharp gradient for tail symbols, and also neatly avoids the
// question of whether 0 references means a bad symbol or missing data.
- if (References >= 10)
- Score *= std::log10(References);
+ if (References >= 10) {
+ // Use a sigmoid style boosting function, which flats out nicely for large
+ // numbers (e.g. 2.58 for 1M refererences).
+ // The following boosting function is equivalent to:
+ // m = 0.06
+ // f = 12.0
+ // boost = f * sigmoid(m * std::log(References)) - 0.5 * f + 0.59
+ // Sample data points: (10, 1.00), (100, 1.41), (1000, 1.82),
+ // (10K, 2.21), (100K, 2.58), (1M, 2.94)
+ float s = std::pow(References, -0.06);
+ Score *= 6.0 * (1 - s) / (1 + s) + 0.59;
+ }
if (Deprecated)
Score *= 0.1f;
Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=337907&r1=337906&r2=337907&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Wed Jul 25 04:26:35 2018
@@ -476,11 +476,12 @@ TEST(CompletionTest, ScopedWithFilter) {
}
TEST(CompletionTest, ReferencesAffectRanking) {
- auto Results = completions("int main() { abs^ }", {ns("absl"), func("abs")});
- EXPECT_THAT(Results.Completions, HasSubsequence(Named("abs"), Named("absl")));
+ auto Results = completions("int main() { abs^ }", {ns("absl"), func("absb")});
+ EXPECT_THAT(Results.Completions, HasSubsequence(Named("absb"), Named("absl")));
Results = completions("int main() { abs^ }",
- {withReferences(10000, ns("absl")), func("abs")});
- EXPECT_THAT(Results.Completions, HasSubsequence(Named("absl"), Named("abs")));
+ {withReferences(10000, ns("absl")), func("absb")});
+ EXPECT_THAT(Results.Completions,
+ HasSubsequence(Named("absl"), Named("absb")));
}
TEST(CompletionTest, GlobalQualified) {
More information about the cfe-commits
mailing list