{"action":"created","issue":{"url":"https://api.github.com/repos/amplitude/Amplitude-Android/issues/101","repository_url":"https://api.github.com/repos/amplitude/Amplitude-Android","labels_url":"https://api.github.com/repos/amplitude/Amplitude-Android/issues/101/labels{/name}","comments_url":"https://api.github.com/repos/amplitude/Amplitude-Android/issues/101/comments","events_url":"https://api.github.com/repos/amplitude/Amplitude-Android/issues/101/events","html_url":"https://github.com/amplitude/Amplitude-Android/issues/101","id":150191418,"number":101,"title":"`initialize` performs blocking disk operations on the calling thread.","user":{"login":"ajalt","id":1109214,"avatar_url":"https://avatars.githubusercontent.com/u/1109214?v=3","gravatar_id":"","url":"https://api.github.com/users/ajalt","html_url":"https://github.com/ajalt","followers_url":"https://api.github.com/users/ajalt/followers","following_url":"https://api.github.com/users/ajalt/following{/other_user}","gists_url":"https://api.github.com/users/ajalt/gists{/gist_id}","starred_url":"https://api.github.com/users/ajalt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajalt/subscriptions","organizations_url":"https://api.github.com/users/ajalt/orgs","repos_url":"https://api.github.com/users/ajalt/repos","events_url":"https://api.github.com/users/ajalt/events{/privacy}","received_events_url":"https://api.github.com/users/ajalt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-21T21:07:16Z","updated_at":"2016-06-16T19:43:20Z","closed_at":null,"body":"The docs recommend calling `Amplitude.getInstance().initialize(...)` in an `onCreate` method. However, there are a number or database queries that take place in that call which block the thread they're called on. This has a noticeable impact on application start time.\r\n\r\nHere are a couple of the StrictMode reports:\r\n\r\n    StrictMode policy violation; ~duration=262 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=29 violation=1\r\n        at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1111)\r\n        at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1247)\r\n        at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:808)\r\n        at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:490)\r\n        at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:464)\r\n        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:363)\r\n        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:228)\r\n        at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:512)\r\n        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206)\r\n        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178)\r\n        at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:908)\r\n        at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:878)\r\n        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:699)\r\n        at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:1585)\r\n        at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:283)\r\n        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)\r\n        at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)\r\n        at com.amplitude.api.DatabaseHelper.getValueFromTable(DatabaseHelper.java:207)\r\n        at com.amplitude.api.DatabaseHelper.getValue(DatabaseHelper.java:196)\r\n        at com.amplitude.api.AmplitudeClient.initialize(AmplitudeClient.java:128)\r\n        at com.amplitude.api.AmplitudeClient.initialize(AmplitudeClient.java:101)\r\n\r\n\r\n    StrictMode policy violation; ~duration=268 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=29 violation=1\r\n        at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1111)\r\n        at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1247)\r\n        at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:808)\r\n        at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:493)\r\n        at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:464)\r\n        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:363)\r\n        at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:228)\r\n        at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:512)\r\n        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206)\r\n        at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178)\r\n        at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:908)\r\n        at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:878)\r\n        at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:699)\r\n        at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:1585)\r\n        at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:283)\r\n        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)\r\n        at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)\r\n        at com.amplitude.api.DatabaseHelper.getValueFromTable(DatabaseHelper.java:207)\r\n        at com.amplitude.api.DatabaseHelper.getLongValue(DatabaseHelper.java:200)\r\n        at com.amplitude.api.AmplitudeClient.upgradeSharedPrefsToDB(AmplitudeClient.java:1239)\r\n        at com.amplitude.api.AmplitudeClient.upgradeSharedPrefsToDB(AmplitudeClient.java:1227)\r\n        at com.amplitude.api.AmplitudeClient.initialize(AmplitudeClient.java:111)\r\n        at com.amplitude.api.AmplitudeClient.initialize(AmplitudeClient.java:101)\r\n\r\nIs it possible for the SDK to perform these calls on a background thread?"},"comment":{"url":"https://api.github.com/repos/amplitude/Amplitude-Android/issues/comments/226592158","html_url":"https://github.com/amplitude/Amplitude-Android/issues/101#issuecomment-226592158","issue_url":"https://api.github.com/repos/amplitude/Amplitude-Android/issues/101","id":226592158,"user":{"login":"djih","id":4776584,"avatar_url":"https://avatars.githubusercontent.com/u/4776584?v=3","gravatar_id":"","url":"https://api.github.com/users/djih","html_url":"https://github.com/djih","followers_url":"https://api.github.com/users/djih/followers","following_url":"https://api.github.com/users/djih/following{/other_user}","gists_url":"https://api.github.com/users/djih/gists{/gist_id}","starred_url":"https://api.github.com/users/djih/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djih/subscriptions","organizations_url":"https://api.github.com/users/djih/orgs","repos_url":"https://api.github.com/users/djih/repos","events_url":"https://api.github.com/users/djih/events{/privacy}","received_events_url":"https://api.github.com/users/djih/received_events","type":"User","site_admin":false},"created_at":"2016-06-16T19:43:19Z","updated_at":"2016-06-16T19:43:19Z","body":"@ajalt @botmane I think the issue is caused by the initial creation of the sqlite database. We timed the init call ourselves, the first time the app opened it was longer than the other times, but no where near 12 s (it was still under 1 s). Subsequent app opening, it only took on avg 50-100ms. \r\n\r\nI am exploring putting the logic on a background thread. There is 1 issue, which is the database is required in order to resolve the device Id. Having the initialization logic run asynchronously on a background thread creates cases where `getDeviceId()` may return null. There are no guarantees that the value will be available when you call the function"}}
{"actor":{"display_login":"djih"}}