summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHans Boehm <hboehm@google.com>2015-05-26 17:52:32 -0700
committerHans Boehm <hboehm@google.com>2015-05-26 18:10:42 -0700
commite4579121c8a9c9df22a35944ad5066d38dc22b37 (patch)
treea6af1b60ca714e7cf8fb79b0e417f42adc3dca63 /src
parent2e1f8eb32826914d1dc2501820f237d4399c53b9 (diff)
downloadandroid_packages_apps_ExactCalculator-e4579121c8a9c9df22a35944ad5066d38dc22b37.tar.gz
android_packages_apps_ExactCalculator-e4579121c8a9c9df22a35944ad5066d38dc22b37.tar.bz2
android_packages_apps_ExactCalculator-e4579121c8a9c9df22a35944ad5066d38dc22b37.zip
Improve evaluate-ahead heuristic
Bug: 21447808 This changes the existing heuristics to compute ahead significantly more aggressively. In my testing, this typically managed to prevent blanks from being displayed even during rapid scrolling. We start the next computation once we get near the end of what we've currently computed. By the time we get to the end, the new results are ready. With this change, we typically compute to nearly 100 digits even without scrolling, and the amount we compute ahead increases as we've scrolled further. With the previous asin() CL, that seems to be fine. I suspect, but have not confirmed, that for this size BigInteger operations, much of the latency is fixed, e.g. JNI, overhead, and the number of digits is not yet critical anyway. This should reduce the total amount of computation, and hence battery usage, during "extreme scrolling", since the evaluation precision now increases geometrically. Update a copyright notice. Change-Id: If3a162016b8ffbacc872361aaa99c77c7fd578a2
Diffstat (limited to 'src')
-rw-r--r--src/com/android/calculator2/CalculatorExpr.java2
-rw-r--r--src/com/android/calculator2/Evaluator.java23
2 files changed, 19 insertions, 6 deletions
diff --git a/src/com/android/calculator2/CalculatorExpr.java b/src/com/android/calculator2/CalculatorExpr.java
index 4a714d8..05afb49 100644
--- a/src/com/android/calculator2/CalculatorExpr.java
+++ b/src/com/android/calculator2/CalculatorExpr.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/com/android/calculator2/Evaluator.java b/src/com/android/calculator2/Evaluator.java
index 8764a99..9e0c7da 100644
--- a/src/com/android/calculator2/Evaluator.java
+++ b/src/com/android/calculator2/Evaluator.java
@@ -143,9 +143,16 @@ class Evaluator {
// We do use these extra digits to display while we are
// computing the correct answer. Thus they may be
// temporarily visible.
- private static final int PRECOMPUTE_DIGITS = 20;
- // Extra digits computed to minimize
- // reevaluations during scrolling.
+ private static final int EXTRA_DIVISOR = 5;
+ // We add the length of the previous result divided by
+ // EXTRA_DIVISOR to try to recover recompute latency when
+ // scrolling through a long result.
+ private static final int PRECOMPUTE_DIGITS = 30;
+ private static final int PRECOMPUTE_DIVISOR = 5;
+ // When we have to reevaluate, we compute an extra
+ // PRECOMPUTE_DIGITS
+ // + <current_result_length>/PRECOMPUTE_DIVISOR digits.
+ // The last term is dropped if prec < 0.
// We cache the result as a string to accelerate scrolling.
// The cache is filled in by the UI thread, but this may
@@ -460,6 +467,9 @@ class Evaluator {
}
mCurrentReevaluator = new AsyncReevaluator();
mCacheDigsReq = prec + PRECOMPUTE_DIGITS;
+ if (mCache != null) {
+ mCacheDigsReq += mCacheDigsReq / PRECOMPUTE_DIVISOR;
+ }
mCurrentReevaluator.execute(mCacheDigsReq);
}
@@ -620,12 +630,15 @@ class Evaluator {
int digs = prec[0];
mLastDigs = digs;
// Make sure we eventually get a complete answer
- ensureCachePrec(digs + EXTRA_DIGITS);
if (mCache == null) {
- // Nothing to do now; seems to happen on rare occasion
+ ensureCachePrec(digs + EXTRA_DIGITS);
+ // Nothing else to do now; seems to happen on rare occasion
// with weird user input timing;
// Will repair itself in a jiffy.
return getPadding(1);
+ } else {
+ ensureCachePrec(digs + EXTRA_DIGITS
+ + mCache.length() / EXTRA_DIVISOR);
}
// Compute an appropriate substring of mCache.
// We avoid returning a huge string to minimize string