Hello,
I was wondering, after the LoadContent phase, if retrieving textures from the ContentManager can be an expensive operation when there are a lot of textures loaded in the same ContentManager:
Content.Load<Texture2D>(assetName)
Since this can happen potentially a lot of times in the Update cycle, I was wondering if storing locally (ie: in the screen class that contains its ContentManager) all the loaded Texture2D objects that are potentially needed in the Update cycle, can be considered as a best practise, since its retrieval is immediate (direct access to the local reference) insted of getting it each time from the Content’s dictionary:
Dictionary<string, object> loadedAssets
I know the dictionary is fast since is using a key, but also the key is a string, and potentially a long one (think about the path in addition to the filename), and could be among lot of similar strings (like those that are sharing the path) so the retrieval could not be immediate.
I also discovered that there is only a dictionary for all types of content, and probably it would be faster to have a bunch of them, one for content type, to really speed up the search, instead of only check later that the content type is the desired one?
if (loadedAssets.TryGetValue(key, out value) && value is T)
{
return (T)value;
}
I’m asking because I do not have all these different textures to try a performance test, and I guess using always the same ones but in multiple instances could involve caching and so not being reliable as a test.
Thanks for any answer!