cache asset operation instances created legacy interceptors

This commit is contained in:
Jesse Plamondon-Willard 2022-05-06 18:26:35 -04:00
parent b834ed7ef5
commit a969828e93
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 48 additions and 29 deletions

View File

@ -3,8 +3,9 @@
# Release notes
## Upcoming release
* For players:
* Improved performance for many mods still using the older content API.
* Disabled case-insensitive file paths (introduced in 3.14.0) by default.
_You can enable them by editing `smapi-internal/config.json` if needed. They'll be re-enabled in a later version after they're reworked to reduce performance impact._
_You can enable them by editing `smapi-internal/config.json` if needed. They'll be re-enabled in an upcoming version after they're reworked a bit._
* Removed experimental 'aggressive memory optimizations' option.
_This was disabled by default and is no longer needed in most cases. Memory usage will be better reduced by reworked asset propagation in the upcoming SMAPI 4.0.0._
* Fixed 'content file was not found' error when the game tries to load unlocalized text from a localizable mod data asset.

View File

@ -81,6 +81,14 @@ namespace StardewModdingAPI.Framework
/// <summary>The cached asset load/edit operations to apply, indexed by asset name.</summary>
private readonly TickCacheDictionary<IAssetName, AssetOperationGroup[]> AssetOperationsByKey = new();
/// <summary>A cache of asset operation groups created for legacy <see cref="IAssetLoader"/> implementations.</summary>
[Obsolete]
private readonly Dictionary<IAssetLoader, AssetOperationGroup> LegacyLoaderCache = new(ReferenceEqualityComparer.Instance);
/// <summary>A cache of asset operation groups created for legacy <see cref="IAssetEditor"/> implementations.</summary>
[Obsolete]
private readonly Dictionary<IAssetEditor, AssetOperationGroup> LegacyEditorCache = new(ReferenceEqualityComparer.Instance);
/*********
** Accessors
@ -598,7 +606,9 @@ namespace StardewModdingAPI.Framework
}
// add operation
yield return new AssetOperationGroup(
if (!this.LegacyLoaderCache.TryGetValue(loader.Data, out AssetOperationGroup? group))
{
this.LegacyLoaderCache[loader.Data] = group = new AssetOperationGroup(
mod: loader.Mod,
loadOperations: new[]
{
@ -615,6 +625,9 @@ namespace StardewModdingAPI.Framework
);
}
yield return group;
}
// legacy edit operations
foreach (var editor in this.Editors)
{
@ -652,7 +665,9 @@ namespace StardewModdingAPI.Framework
};
// add operation
yield return new AssetOperationGroup(
if (!this.LegacyEditorCache.TryGetValue(editor.Data, out AssetOperationGroup? group))
{
this.LegacyEditorCache[editor.Data] = group = new AssetOperationGroup(
mod: editor.Mod,
loadOperations: Array.Empty<AssetLoadOperation>(),
editOperations: new[]
@ -668,6 +683,9 @@ namespace StardewModdingAPI.Framework
}
);
}
yield return group;
}
#pragma warning restore CS0612, CS0618
}