fn prepare()

in components/places/src/db/db.rs [60:114]


    fn prepare(&self, conn: &Connection, db_empty: bool) -> open_database::Result<()> {
        // If this is an empty DB, setup incremental auto-vacuum now rather than wait for the first
        // run_maintenance_vacuum() call.  It should be much faster now with an empty DB.
        if db_empty && !matches!(self.conn_type, ConnectionType::ReadOnly) {
            conn.execute_one("PRAGMA auto_vacuum=incremental")?;
            conn.execute_one("VACUUM")?;
        }

        let initial_pragmas = "
            -- The value we use was taken from Desktop Firefox, and seems necessary to
            -- help ensure good performance on autocomplete-style queries.
            -- Modern default value is 4096, but as reported in
            -- https://bugzilla.mozilla.org/show_bug.cgi?id=1782283, desktop places saw
            -- a nice improvement with this value.
            PRAGMA page_size = 32768;

            -- Disable calling mlock/munlock for every malloc/free.
            -- In practice this results in a massive speedup, especially
            -- for insert-heavy workloads.
            PRAGMA cipher_memory_security = false;

            -- `temp_store = 2` is required on Android to force the DB to keep temp
            -- files in memory, since on Android there's no tmp partition. See
            -- https://github.com/mozilla/mentat/issues/505. Ideally we'd only
            -- do this on Android, and/or allow caller to configure it.
            -- (although see also bug 1313021, where Firefox enabled it for both
            -- Android and 64bit desktop builds)
            PRAGMA temp_store = 2;

            -- 6MiB, same as the value used for `promiseLargeCacheDBConnection` in PlacesUtils,
            -- which is used to improve query performance for autocomplete-style queries (by
            -- UnifiedComplete). Note that SQLite uses a negative value for this pragma to indicate
            -- that it's in units of KiB.
            PRAGMA cache_size = -6144;

            -- We want foreign-key support.
            PRAGMA foreign_keys = ON;

            -- we unconditionally want write-ahead-logging mode
            PRAGMA journal_mode=WAL;

            -- How often to autocheckpoint (in units of pages).
            -- 2048000 (our max desired WAL size) / 32760 (page size).
            PRAGMA wal_autocheckpoint=62;

            -- How long to wait for a lock before returning SQLITE_BUSY (in ms)
            -- See `doc/sql_concurrency.md` for details.
            PRAGMA busy_timeout = 5000;
        ";
        conn.execute_batch(initial_pragmas)?;
        define_functions(conn, self.api_id)?;
        sql_support::debug_tools::define_debug_functions(conn)?;
        conn.set_prepared_statement_cache_capacity(128);
        Ok(())
    }