From 74f094faabb3cf0e031c13f85116be69172cd69e Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Mon, 25 Jul 2016 17:31:37 -0700 Subject: [PATCH 1/2] [core] Update SQLite schema with WAL journal mode and normal sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Offers 2×-4× performance, depending on device vintage. --- platform/default/mbgl/storage/offline_database.cpp | 13 +++++++++++-- platform/default/mbgl/storage/offline_database.hpp | 1 + test/storage/offline_database.cpp | 10 +++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/platform/default/mbgl/storage/offline_database.cpp b/platform/default/mbgl/storage/offline_database.cpp index 46a2c2bc25b..d93b1734b4f 100644 --- a/platform/default/mbgl/storage/offline_database.cpp +++ b/platform/default/mbgl/storage/offline_database.cpp @@ -48,7 +48,8 @@ void OfflineDatabase::ensureSchema() { case 0: break; // cache-only database; ok to delete case 1: break; // cache-only database; ok to delete case 2: migrateToVersion3(); // fall through - case 3: return; + case 3: migrateToVersion4(); // fall through + case 4: return; default: throw std::runtime_error("unknown schema version"); } @@ -79,8 +80,10 @@ void OfflineDatabase::ensureSchema() { // If you change the schema you must write a migration from the previous version. db->exec("PRAGMA auto_vacuum = INCREMENTAL"); + db->exec("PRAGMA synchronous = NORMAL"); + db->exec("PRAGMA journal_mode = WAL"); db->exec(schema); - db->exec("PRAGMA user_version = 3"); + db->exec("PRAGMA user_version = 4"); } catch (...) { Log::Error(Event::Database, "Unexpected error creating database schema: %s", util::toString(std::current_exception()).c_str()); throw; @@ -111,6 +114,12 @@ void OfflineDatabase::migrateToVersion3() { db->exec("PRAGMA user_version = 3"); } +void OfflineDatabase::migrateToVersion4() { + db->exec("PRAGMA synchronous = NORMAL"); + db->exec("PRAGMA journal_mode = WAL"); + db->exec("PRAGMA user_version = 4"); +} + OfflineDatabase::Statement OfflineDatabase::getStatement(const char * sql) { auto it = statements.find(sql); diff --git a/platform/default/mbgl/storage/offline_database.hpp b/platform/default/mbgl/storage/offline_database.hpp index 55cb7ad2fa2..00394aa7206 100644 --- a/platform/default/mbgl/storage/offline_database.hpp +++ b/platform/default/mbgl/storage/offline_database.hpp @@ -60,6 +60,7 @@ class OfflineDatabase : private util::noncopyable { void ensureSchema(); void removeExisting(); void migrateToVersion3(); + void migrateToVersion4(); class Statement { public: diff --git a/test/storage/offline_database.cpp b/test/storage/offline_database.cpp index 81da46bc78c..bcea3cd8f31 100644 --- a/test/storage/offline_database.cpp +++ b/test/storage/offline_database.cpp @@ -559,18 +559,18 @@ TEST(OfflineDatabase, MigrateFromV2Schema) { // v2.db is a v2 database containing a single offline region with a small number of resources. - deleteFile("test/fixtures/offline_database/v3.db"); - writeFile("test/fixtures/offline_database/v3.db", util::read_file("test/fixtures/offline_database/v2.db")); + deleteFile("test/fixtures/offline_database/v4.db"); + writeFile("test/fixtures/offline_database/v4.db", util::read_file("test/fixtures/offline_database/v2.db")); { - OfflineDatabase db("test/fixtures/offline_database/v3.db", 0); + OfflineDatabase db("test/fixtures/offline_database/v4.db", 0); auto regions = db.listRegions(); for (auto& region : regions) { db.deleteRegion(std::move(region)); } } - EXPECT_EQ(3, databaseUserVersion("test/fixtures/offline_database/v3.db")); - EXPECT_LT(databasePageCount("test/fixtures/offline_database/v3.db"), + EXPECT_EQ(4, databaseUserVersion("test/fixtures/offline_database/v4.db")); + EXPECT_LT(databasePageCount("test/fixtures/offline_database/v4.db"), databasePageCount("test/fixtures/offline_database/v2.db")); } From c034ba4ee16b1a8fc4ff92b4672671f636dadaab Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Tue, 23 Aug 2016 13:04:45 -0400 Subject: [PATCH 2/2] [ios, macos] Update changelog with database performance note --- platform/ios/CHANGELOG.md | 1 + platform/macos/CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index e12933cb226..b81acf63a62 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -40,6 +40,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ### Other changes * Fixed a crash that sometimes occurred when initializing an MGLMapView. ([#5932](https://github.com/mapbox/mapbox-gl-native/pull/5932)) +* Improved offline and ambient cache database performance. ([#5796](https://github.com/mapbox/mapbox-gl-native/pull/5796)) * As the user zooms in, tiles from lower zoom levels are scaled up until tiles for higher zoom levels are loaded. ([#5143](https://github.com/mapbox/mapbox-gl-native/pull/5143)) * MGLMapDebugOverdrawVisualizationMask no longer has any effect in Release builds of the SDK. This debug mask has been disabled for performance reasons. ([#5555](https://github.com/mapbox/mapbox-gl-native/pull/5555)) * Fixed a typo in the documentation for the MGLCompassDirectionFormatter class. ([#5879](https://github.com/mapbox/mapbox-gl-native/pull/5879)) diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 6e8b10246f4..2e51a4d3d3a 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -5,6 +5,7 @@ * Fixed an issue causing code signing failures and bloating the framework. ([#5850](https://github.com/mapbox/mapbox-gl-native/pull/5850)) * Xcode 7.3 or higher is now required for using this SDK. ([#6059](https://github.com/mapbox/mapbox-gl-native/issues/6059)) * A new runtime styling API allows you to adjust the style and content of the base map dynamically. All the options available in [Mapbox Studio](https://www.mapbox.com/studio/) are now exposed via MGLStyle and subclasses of MGLStyleLayer and MGLSource. ([#5727](https://github.com/mapbox/mapbox-gl-native/pull/5727)) +* Improved offline and ambient cache database performance. ([#5796](https://github.com/mapbox/mapbox-gl-native/pull/5796)) * Added `showAnnotations:animated:` and `showAnnotations:edgePadding:animated:`, which moves the map viewport to show the specified annotations. ([#5749](https://github.com/mapbox/mapbox-gl-native/pull/5749)) * To make an MGLPolyline or MGLPolygon span the antimeridian, specify coordinates with longitudes greater than 180° or less than −180°. ([#6088](https://github.com/mapbox/mapbox-gl-native/pull/6088)) * MGLMapView’s `styleURL` property can now be set to an absolute file URL. ([#6026](https://github.com/mapbox/mapbox-gl-native/pull/6026))