Hello everyone, I was working on some optimization...
# android
a
Hello everyone, I was working on some optimizations and found that data store is taking significant time in storing/removing values. So why dataStore is slower than shared preference. ?
not kotlin but kotlin colored 3
m
Does that happen when using flow for the storing/removing values?
a
Copy code
dataStoreManager.getDataStore(prefName, prefAlreadyExists).edit {
    it.remove(preferencesKey<T>(prefKey))
}
suspend fun <T> DataStore<Preferences>.storeValue(key: Preferences.Key<T>, value: T) {
    this.edit {
        it[key] = value
    }
}
We are using above code for storing/removing
m
ah, where are you using the datastore manager? in the function that uses the suspend function for storing, try to execute it inside a scope block, for example: Viewmodel:
viewModelScope.launch { datastoreManager.storeValue(...) }
Repository:
/* inside a suspend function or flow { ... } */
datastoreManager.storeValue(...)