Loading a StringTable at runtime is slow (0.3s to load a string)

Hello,
I was intrigued by this new Localization package and spent a few hours trying to set it up.

my Use case:
I have a random sentence generator, picking 1 sentence in a list, modify it, return it to use it in gameplay and display it.

So I created a StringTable, filling it with my sentences,
and in my code generator class I added a
public UnityEngine.Localization.Settings.LocalizedStringDatabase db;

I load my string table and copy all of its value strings to my List of string form my generator.
(code below)
However, loading the String Database takes me 0.3 seconds,
0.22 if I use the Adressables → groups → use existing builds option

it’s been long since I needed my string, which would should be displayed at the start of the scene.

So, is it an expected behavior of the Localization system, and I used it for the wrong case?
Did I used it incorrectly or did I forgot to check an option?

I found the documentation pretty sparse (had to search on the forum), and do a lot of trial and error.
I don’t understand why I find calls of these methods in OnGUI methods, as it should be pretty expensive to run.

In the documentation’s screenshots there are reference to “preload” option In LocalizedSettings I cannot find in mine. I suppose it is deprecated, but I would have wanted to preload my strings.

here is my code for loading a complete StringTable into a List of string.
I hope someone could point me on a direction to fix these performance issue,
or that it will be useful to someone who can wait.

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class TestLocLoad : MonoBehaviour
{
    public UnityEngine.Localization.Settings.LocalizedStringDatabase db;
    public List<string> names;

    public IEnumerator Start()
    {
        var d = db.GetTableAsync(db.DefaultTable);
        yield return d;
        var stringEntryList = d.Result.ToList();

        for (int i = 0; i < stringEntryList.Count(); i++)
        {
            var loc = stringEntryList[i].Value.GetLocalizedString();
            names.Add(loc);
        }
    }

    public string getRandomName() => names[Random.Range(0, names.Count)];

}

All of this almost makes me want to restart working on Android apps.

Hi,
The preloading option was moved to the table window, see here String Tables | Localization | 0.6.1-preview
It sounds like you may be using the wrong version of the manual, make sure that the version in the URL matches the version you are using.
The bulk of the time will be the loading the asset bundle the first time, after this, it should be much faster than the 0.3.
Also part of that delay could just be the coroutine as they don’t come back till LateUpdate. So it may be checking the status of the async operation and only yielding if you need to.

I would not hold a reference to the actual LocalizedStringDatabase. Just use LocalizationSettings like so:

IEnumerator Start()
{
    var d = LocalizationSettings.StringDatabase.GetTableAsync(LocalizationSettings.StringDatabase.DefaultTable);
    if (!d.IsDone)
        yield return d;

    foreach(var entry in d.Result.Values)
    {
        var loc = entry.GetLocalizedString();
        names.Add(loc);
    }
}

We are more than happy to take feedback so feel welcome to make suggestions/comments etc.

1 Like

Thank you for the fast response!

Indeed I was reading an old version of the documentation: Google redirected me to the 0.4 one.
And I didn’t saw the blue “View Latest Button” on the top bar, I guess I was tired.
On the new version of the documentation however, the version number with the dropdown is really useful, I saw it immediatly.
(I guess you can’t retroactively change previously published documentation pages to add it, sadly)

I followed your advice for the code, and also checked the “preload all tables” option.
But when running from the Editor I still get the same time, 0.3 seconds to load.

I admit It is not critical for the game build, as I could preload a table at the startupscreen of the game,
to have the AssetBundle loaded when needed.

But for debug, when launching directly from a scene, it can be annoying when testing.
I’ll have to add a delay in my debug code, and it will add 300 more ms to a game launch I already find a bit slow :confused:

just throwing stupid ideas away: maybe, for strings table, have a special check if (!Application.isEditor)(
and return the string table from another object less costly to load, separate from the AssetBundle?
I don’t know, I have now idea of the internals of this package, so I’m saying random things…

Thanks again for your availability.

In the editor it goes through the Addressables system which does have an instant mode. So I’m a bit surprised that it is taking so long. Maybe file a bug report and we can look into it, we may be able to do something to speed it up.
Also check the mode Addressables is using, it’s in the Addressables window.

It’s unfortunate that Google is so determined to send people to the old docs :frowning:

I tried with the “Use Asset Database(faster)” option and the “use existing builds”, without changes.
I tried messing with the order of elements in the group panel.
I removed everything (except my Dotween settings) from the Resources folder.

If you tell me how to file a bug report, and what to put inside (as there shouldn’t be crashes) I’d be glad to do so.
But I think I’ll just re-concentrate on my game project and wait a bit until this package has matured,
as I start being tired of troubleshooting this issue all the day :confused:

You can see my Adressable Groups panel below and the event Analyzer, if useful.
i’m on Linux 2019.3.3f1.

1 Like