diff --git a/sql/version-014.sql b/sql/version-014.sql new file mode 100644 index 00000000..1c35c06f --- /dev/null +++ b/sql/version-014.sql @@ -0,0 +1,4 @@ +-- +-- Dummy file to upgrade to version 14. See imap-db-database.vala for the +-- actual code that gets executed here. +-- diff --git a/src/engine/imap-db/imap-db-database.vala b/src/engine/imap-db/imap-db-database.vala index f1986076..bac99642 100644 --- a/src/engine/imap-db/imap-db-database.vala +++ b/src/engine/imap-db/imap-db-database.vala @@ -83,6 +83,10 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase { case 13: post_upgrade_populate_additional_attachments(); break; + + case 14: + post_upgrade_expand_page_size(); + break; } } @@ -272,6 +276,31 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase { } } + // Version 14. + private void post_upgrade_expand_page_size() { + try { + // When the MessageSearchTable is first touched, SQLite seems to + // read the whole table into memory (or an awful lot of data, + // either way). This was causing slowness when Geary first started + // and checked for any messages not yet in the search table. With + // the database's page_size set to 4096, the reads seem to happen + // about 2 orders of magnitude quicker, probably because 4096 + // matches the default filesystem block size and/or Linux's default + // memory page size. With this set, the full read into memory is + // barely noticeable even on slow machines. + + // NOTE: these can't be in the .sql file itself because they must + // be back to back, outside of a transaction. + exec(""" + PRAGMA page_size = 4096; + VACUUM; + """); + } catch (Error e) { + debug("Error bumping page_size or vacuuming database; performance may be degraded: %s", + e.message); + } + } + private void on_prepare_database_connection(Db.Connection cx) throws Error { cx.set_busy_timeout_msec(Db.Connection.RECOMMENDED_BUSY_TIMEOUT_MSEC); cx.set_foreign_keys(true);