Skip to content

Commit 285414c

Browse files
committed
db: Add profile-mode timings of load at startup
As we add more features using the database and more queries we make from it here at the app's startup, this will help us check that we aren't unduly delaying startup. Results on my Pixel 8, with 2 account records: db load time 91.9ms total: 1.5ms init, 85.4ms settings, 5.0ms accounts db load time 87.8ms total: 1.7ms init, 78.1ms settings, 8.0ms accounts db load time 93.3ms total: 1.2ms init, 83.7ms settings, 8.5ms accounts db load time 78.1ms total: 1.4ms init, 71.8ms settings, 4.8ms accounts db load time 86.9ms total: 1.2ms init, 77.8ms settings, 7.9ms accounts
1 parent f036fea commit 285414c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/model/store.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,27 @@ class LiveGlobalStore extends GlobalStore {
882882
// We keep the API simple and synchronous for the bulk of the app's code
883883
// by doing this loading up front before constructing a [GlobalStore].
884884
static Future<GlobalStore> load() async {
885+
// Loading this data takes roughly 80-100ms (measured on a Pixel 8).
886+
// That's only a small increment on the time spent loading server data,
887+
// so we don't worry about optimizing it further.
888+
// In a future where we keep server data locally between runs (#477) --
889+
// which will also mean having much more data to load from the database --
890+
// we'd invest in this area more. For example we'd try doing these
891+
// in parallel, or deferring some to be concurrent with loading server data.
892+
final stopwatch = Stopwatch()..start();
885893
final db = AppDatabase(NativeDatabase.createInBackground(await _dbFile()));
894+
final t1 = stopwatch.elapsed;
886895
final globalSettings = await db.getGlobalSettings();
896+
final t2 = stopwatch.elapsed;
887897
final accounts = await db.select(db.accounts).get();
898+
final t3 = stopwatch.elapsed;
899+
if (kProfileMode) {
900+
String format(Duration d) =>
901+
"${(d.inMicroseconds / 1000.0).toStringAsFixed(1)}ms";
902+
profilePrint("db load time ${format(t3)} total: ${format(t1)} init, "
903+
"${format(t2 - t1)} settings, ${format(t3 - t2)} accounts");
904+
}
905+
888906
return LiveGlobalStore._(
889907
backend: LiveGlobalStoreBackend._(db: db),
890908
globalSettings: globalSettings,

0 commit comments

Comments
 (0)