Perez Sebastián
Perez Sebastián

Reputation: 89

Why is React Native AsyncStorage so slow on my phone?

I have a problem with an App im Developping with Expo - React Native. The problem is that, having only one small value stored in AsyncStorage, its takes around 25 seconds to load. There are the details:

Expo: Version 33

Ract Native (comes with Expo): 0.59.8

My stored values: {keyOne: "ValueOne"}

This is only an example for testing, obviously in the actual app i have more values. The code i am using for testing, inside App.js is:

async componentDidMount(){
    console.log("Storing value...");
    await AsyncStorage.setItem("keyOne", "valueOne");
    console.log("Value stored");
    var value1 = await AsyncStorage.getItem("keyOne");
    console.log("Obtained value: "+value1);
}

With this code, the 25 seconds are spend storing the item.

I'm facing this problem specifically in Samsung Phones, for example a Galaxy S7 SM-g930F. This happens when developing and in production app.

Also, if I store more values, the first that i obtain is the one slow, the rest are very fast.

Another detail is that, if i make the same test with SecureStore, is very fast. Can i do something to speed things up?
Some alternative to AsyncStorage?

Upvotes: 2

Views: 5195

Answers (1)

Abdul Basit Mangat
Abdul Basit Mangat

Reputation: 1180

Make sure to do following.

  1. Upgrade react-native version to 0.59.5 +
  2. Don't import {AsyncStorage} from react-native (as it is deprecated now)
  3. Use this package instead Async Storage
  4. Import like this import AsyncStorage from '@react-native-community/async-storage';

Upvotes: 1

Related Questions