I am developing an Android app with offline search functionality. This requires me to read in a dictionary file that has approximately 170,000 entries.
I am facing severe performance issues and initially thought it was due to my code having String.match(regex)
looping through the ArrayList
which I had read the data into.
However, digging deeper, I found that the main issue was actually data I/O. It took ~10,000 ms just to read the dictionary file in via BufferedReader
+ InputStream
, without performing any searches. I've tried other means of reading data in such as using a StringBuilder
but they don't seem to help much.
What are some possible solutions to this problem?
Some points to consider:
- The searches are recursive
- The app has to stay offline
- The entries are basically lines of text, albeit in an East Asian language (increasing the difficulty of the search, since entire sentences can be a single string.)
The standard code I was using for reading in the data was:
InputStream is = getResources().openRawResource(R.raw.data);
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while(br.readLine() != null){
blahblah....
}