Optimizations:

Use PLINQ for prototype loading. Most of the time is spent reading YAML so this should help a lot.
Don't regenerate collision for every tile placed by the map loader.
This commit is contained in:
Pieter-Jan Briers
2020-01-15 16:13:22 +01:00
parent 0739367013
commit 22cf53fd1c
8 changed files with 77 additions and 39 deletions

View File

@@ -203,23 +203,39 @@ namespace Robust.Shared.Prototypes
/// <inheritdoc />
public void LoadDirectory(ResourcePath path)
{
foreach (var filePath in _resources.ContentFindFiles(path))
{
if (filePath.Extension != "yml" || filePath.Filename.StartsWith("."))
{
continue;
}
using (var reader = new StreamReader(_resources.ContentFileRead(filePath), EncodingHelpers.UTF8))
_hasEverBeenReloaded = true;
var yamlStreams = _resources.ContentFindFiles(path).ToList().AsParallel()
.Where(filePath => filePath.Extension == "yml" && !filePath.Filename.StartsWith("."))
.Select(filePath =>
{
try
{
LoadFromStream(reader);
using var reader = new StreamReader(_resources.ContentFileRead(filePath), EncodingHelpers.UTF8);
var yamlStream = new YamlStream();
yamlStream.Load(reader);
return (yamlStream, filePath);
}
catch (Exception e)
when (e is YamlException || e is PrototypeLoadException)
catch (YamlException e)
{
Logger.ErrorS("eng", $"Exception whilst loading prototypes from {filePath}: {e}");
return (null, null);
}
})
.Where(p => p.yamlStream != null) // Filter out loading errors.
.ToList();
foreach (var (stream, filePath) in yamlStreams)
{
for (var i = 0; i < stream.Documents.Count; i++)
{
try
{
LoadFromDocument(stream.Documents[i]);
}
catch (Exception e)
{
Logger.ErrorS("eng", $"Exception whilst loading prototypes from {filePath}#{i}:\n{e}");
}
}
}