PlayerPrefs.Save takes 740 ms

Profiling the game, it seems that PlayerPrefs.Save() takes over 700 ms (in the editor).

Why is this save so slow? Is this proportional to the amount of data that is saved ? or is this a regression?

Did anyone else encounter slow performance with the PlayerPrefs class ? (i am on 5.1.2p3)

How much information are you saving?

I guess in this scenario we are probably saving a large amount of data (around 10kb).

Have you tried the same save on different hardware?

What kind of data do you store? Have you considered using an alternative? I personally wouldn’t use it to store game data, but that’s just my opinion.

I haven’t compared this to profiling results on an actual device yet. It’s just that this halts the game for a brief moment and then continues, which is very noticeable, even in the editor.

@Suddoha we are reporting data to analytics, and storing the events that should be sent, in case the game is closed/crashes or there’s no network connectivity to deliver it at the moment. This is around ~ 11 kb of data (in this case).

Don’t use player preferences for that purpose.
Player preferences are intended for storing small amounts of data. Like preferences. Key bindings, graphics options, difficulty settings, etcetera.

Look at Application.persistentDataPath, instead.

Do you have performance data that compares both of these ?

That compares what? The speed of saving 10kb of data via player preferences vs via a file?

No, but I’m sure you’ll be able to make the comparison yourself and see that it’s much faster. As I said, player prefs are not intended for what you’re using them for.

There is plenty of documentation out there about data persistence.

Start here: https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading

1 Like