Reviewing how the engine recomputes its state
After handling an action, the engine doesn’t know what changed, so it rereads and compares the state needed by the screen, lock screen, watch and widgets. We look at the cause and the alternatives.
This isn't the first time we've met this problem. In October, a person listed the screens to reread when a record changed, and some were missing from the list. We tried tracking tables to compute the screens to reread, but that machinery disappeared when we rebuilt the app. In November, to avoid missing anything, we went around every area on every input, and removed it when it started doing unrelated work. The method changed, but we still couldn't answer one question. What did the action we just took change?
Today's engine doesn't know the answer even after an action finishes. So it rereads the state needed by the screen, lock screen, watch and widgets, and compares it to the previous values. Since it doesn't know what changed, it has to read a lot to find what differs. Before speeding up the reading, we need to know why it has to reread so much.
We doubt the first measurement too
The lookup counts we first measured counted only what happened inside the engine. Lookups from the lock screen, watch and widgets were left out, and so were those that prepare the screen. Some values were also measured with no past workout records at all. We could see the numbers going down, but couldn't say what really decreased and by how much. We don't use these values as an achievement.
Are we looking for a faster cache?
We're testing Salsa now. Salsa is a Rust library that helps recompute only the parts whose inputs changed. We don't intend to hand it all the data. We'd try it only on values computed for display, like the screens, and keep the original records in SQLite as now. A small experiment ran, but we don't yet know what it will do to the app's size and speed.
We also looked at reactive_graph, GRDB, sqlite-watcher, comemo and DBSP. For now we think they don't fit our engine. We won't build our own cache, change markers, dependency table or event bus. If a person starts writing down what changed in yet another list, we could go back to October's problem.
That doesn't mean we've decided Salsa is the answer. For values that change over time, what should we treat as the input? How do we track state that lives only in memory? If an error occurs during a computation, can we reuse its result? If we can't answer these, we may swap only the library and leave the problem as it is.
We haven't decided whether to put it in the product. We're testing it in code kept apart from the product and reviewing the direction again. This time we want to answer “why do we have to work it out again?” before “how do we recompute faster?”
