mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
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:
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user