stroke-input-android
stroke-input-android copied to clipboard
Better implementation (memory-wise)
I don't know very much about programming, so I have produced a rather crappy implementation of the stroke input method.
In particular, I load all the stroke data into memory when the input method service is instantiated:
https://github.com/stroke-input/stroke-input-android/blob/c94a8096a41b0fa94759645ba35a7bfb4feda3ad/app/src/main/java/io/github/yawnoc/strokeinput/StrokeInputService.java#L153-L167
It works, but the downsides are:
- It takes a long time to load on lower-end devices (e.g. takes 1.2 seconds on my cheap phone with ~1.3 GB RAM)
- It requires a lot of memory
-
Most of the time is spent during
loadSequenceCharactersDataIntoMap. Is there a better way of reading a TSV than what I currently have? https://github.com/stroke-input/stroke-input-android/blob/c23d584a57f821d1ee39ecd932c14636d1c3a387/app/src/main/java/io/github/yawnoc/strokeinput/StrokeInputService.java#L220-L252 -
Alternatively, given that the stroke data is a constant map, is it possible to bake it into the class so that I don't need to load it every time? Or, can we do something completely different that isn't so memory intensive?
According to tadfisher on Reddit:
To avoid loading the whole dataset, I would suggest that you ship it as a sqlite database. That way you can add index columns based on prefix characters and let sqlite filter candidates for you. A script to build a sqlite3 database and populate it with the Conway dataset should be a reasonable project for a beginner.