From 4b03618f0877e70ffffa88735d400dd55d8da6b1 Mon Sep 17 00:00:00 2001 From: Charles Lindsay Date: Tue, 24 Sep 2013 18:48:12 -0700 Subject: [PATCH] Set SQLite page size to 4K: Closes #7423 This speeds up startup time immensely, probably due it matching the the filesystem's or Linux memory mgmt's page size. It's also expected that this will improve database performance in other ways, as the default was 1K, meaning potentially more I/O than necessary for standard operations. --- sql/version-014.sql | 4 ++++ src/engine/imap-db/imap-db-database.vala | 29 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 sql/version-014.sql 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);