aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-04-24 12:54:44 +0900
committerJean Chalard <jchalard@google.com>2012-04-24 15:16:17 +0900
commit1d80a7f395290cd0e7344210bb3960f685059264 (patch)
treebe1e48e0c9d31c5d626b90ea44bb0d3c62122899 /java/src
parent5ee0ee0dbe316aac80949bd35f9834e46d5e2799 (diff)
downloadlatinime-1d80a7f395290cd0e7344210bb3960f685059264.tar.gz
latinime-1d80a7f395290cd0e7344210bb3960f685059264.tar.xz
latinime-1d80a7f395290cd0e7344210bb3960f685059264.zip
Fix binary reading code performance.
This is not the Right fix ; the Right fix would be to read the file in a buffered way. However this delivers tolerable performance for a minimal amount of code changes. We may want to skip submitting this patch, but keep it around in case we need to use the functionality until we have a good patch. Change-Id: I1ba938f82acfd9436c3701d1078ff981afdbea60
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
index 97df98e34..4256871cc 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
@@ -1122,6 +1122,12 @@ public class BinaryDictInputOutput {
}
}
+ // The word cache here is a stopgap bandaid to help the catastrophic performance
+ // of this method. Since it performs direct, unbuffered random access to the file and
+ // may be called hundreds of thousands of times, the resulting performance is not
+ // reasonable without some kind of cache. Thus:
+ // TODO: perform buffered I/O here and in other places in the code.
+ private static TreeMap<Integer, String> wordCache = new TreeMap<Integer, String>();
/**
* Finds, as a string, the word at the address passed as an argument.
*
@@ -1131,8 +1137,10 @@ public class BinaryDictInputOutput {
* @return the word, as a string.
* @throws IOException if the file can't be read.
*/
- private static String getWordAtAddress(RandomAccessFile source, long headerSize,
+ private static String getWordAtAddress(final RandomAccessFile source, final long headerSize,
int address) throws IOException {
+ final String cachedString = wordCache.get(address);
+ if (null != cachedString) return cachedString;
final long originalPointer = source.getFilePointer();
source.seek(headerSize);
final int count = readCharGroupCount(source);
@@ -1171,6 +1179,7 @@ public class BinaryDictInputOutput {
}
}
source.seek(originalPointer);
+ wordCache.put(address, result);
return result;
}