Skip to content

Commit

Permalink
a few performance tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ngld committed Apr 16, 2021
1 parent d814224 commit 6013f68
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions OverlayPlugin.Core/EventSources/MiniParseEventSource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#define TRACE

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
Expand Down Expand Up @@ -622,15 +624,8 @@ internal JObject CreateCombatData()
Dictionary<string, string> encounter = null;
List<KeyValuePair<CombatantData, Dictionary<string, string>>> combatant = null;

var encounterTask = Task.Run(() =>
{
encounter = GetEncounterDictionary(allies);
});
var combatantTask = Task.Run(() =>
{
combatant = GetCombatantList(allies);
});
Task.WaitAll(encounterTask, combatantTask);
combatant = GetCombatantList(allies);
encounter = GetEncounterDictionary(allies);

if (encounter == null || combatant == null) return new JObject();

Expand Down Expand Up @@ -685,7 +680,7 @@ internal JObject CreateCombatData()

obj["isActive"] = ActGlobals.oFormActMain.ActiveZone.ActiveEncounter.Active ? "true" : "false";

#if TRACE
#if DEBUG
stopwatch.Stop();
Log(LogLevel.Trace, "CreateUpdateScript: {0} msec", stopwatch.Elapsed.TotalMilliseconds);
#endif
Expand All @@ -694,14 +689,14 @@ internal JObject CreateCombatData()

private List<KeyValuePair<CombatantData, Dictionary<string, string>>> GetCombatantList(List<CombatantData> allies)
{
#if TRACE
#if DEBUG
var stopwatch = new Stopwatch();
stopwatch.Start();
#endif

var combatantList = new List<KeyValuePair<CombatantData, Dictionary<string, string>>>();
Parallel.ForEach(allies, (ally) =>
//foreach (var ally in allies)
// foreach (var ally in allies)
{
var valueDict = new Dictionary<string, string>();
foreach (var exportValuePair in CombatantData.ExportVariables)
Expand Down Expand Up @@ -747,7 +742,7 @@ private List<KeyValuePair<CombatantData, Dictionary<string, string>>> GetCombata
}
);

#if TRACE
#if DEBUG
stopwatch.Stop();
Log(LogLevel.Trace, "GetCombatantList: {0} msec", stopwatch.Elapsed.TotalMilliseconds);
#endif
Expand All @@ -757,7 +752,7 @@ private List<KeyValuePair<CombatantData, Dictionary<string, string>>> GetCombata

private Dictionary<string, string> GetEncounterDictionary(List<CombatantData> allies)
{
#if TRACE
#if DEBUG
var stopwatch = new Stopwatch();
stopwatch.Start();
#endif
Expand Down Expand Up @@ -797,7 +792,7 @@ private Dictionary<string, string> GetEncounterDictionary(List<CombatantData> al
}
}

#if TRACE
#if DEBUG
stopwatch.Stop();
Log(LogLevel.Trace, "GetEncounterDictionary: {0} msec", stopwatch.Elapsed.TotalMilliseconds);
#endif
Expand Down

0 comments on commit 6013f68

Please sign in to comment.