Improving caching

The place for translators to get support and report localization system issues
Post Reply
badryuner
Posts: 1
Joined: Thu Aug 05, 2021 3:08 am

Improving caching

Post by badryuner » Thu Aug 05, 2021 6:12 am

I will say in advance that English is not my native language, so there may be small mistakes in words. Also all code is taken using DnSpy.

Let's start with the items. The next example will be on PLPawnItem_PhasePistol, but this applies to all items.

Code: Select all

public override string GetItemName(bool skipLocalization = false)
{
	return PLLocalize.Localize("Phase Pistol", skipLocalization) + base.GetItemEnd(); 
}
Calling PLLocalize.Localize every frame is inefficient, you can replace it like this:

Code: Select all

public PLPawnItem_PhasePistol() : base(EPawnItemType.E_PHASEPISTOL)
{
	// end of constructor
	LocalizedItemName = PLLocalize.Localize("Phase Pistol", false);
}

string LocalizedItemName;

public override string GetItemName()
{
	return LocalizedItemName + (this.Level > 0 ? (" +" + this.Level) : null); //C#9 or LocalizedItemName + GetEnd();
}
This will speed up the method execution by 4-12 ns. You can do the same for all other items, as well as for their descriptions, and get a small performance increase.

In the latest versions of Unity (2021.2.0b6 and 2022.1.0a3), Net Standard 2.1 is available, which has more optimized versions of Dictionary and String. Do you plan to switch to it? Unity Forum

I will also add that the feature of the Sylvassi ship cannot be translated.

User avatar
cptslog
Leafy Developer
Leafy Developer
Posts: 1104
Joined: Sun Sep 08, 2013 9:08 pm

Re: Improving caching

Post by cptslog » Wed Aug 11, 2021 12:49 pm

Thanks for the suggestions

We use some internal string caching inside the localization system to help with these 'every frame' cases but there are definitely more options like you mentioned to increase the speed and decrease memory throttling

Working on a large project like this is always a balance between runtime execution speed and coding time. With one programmer there are countless compromises to make to try and get as much as possible done. I actually enjoy optimization and getting things running as fast as possible but there is only so much time in the day :)

As for your second suggestion, we will likely upgrade the Unity engine version at some point but are currently unable to due to some regressions in the way Unity handles multi-camera setups in VR specifically. We will be spending more time on that at some point to work around it as we are planning a fairly large VR overhaul in the future. We are definitely interested in the upgrades to Mono / .NET runtime and bringing them to the game

Thanks again, I will keep it in mind as I try to make improvements in the future

Post Reply