Skip to content

Commit b5a25ae

Browse files
committed
[Session] Optimize mdb loading a bit more
This does a 50x speedup on loading and 500x less allocations done compared to the previous version.
1 parent 0af644c commit b5a25ae

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

Mono.Debugging.Soft/SoftDebuggerSession.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public MdbSourceFileInfo()
6161
{
6262
Methods = new List<MethodMdbInfo>();
6363
}
64+
65+
public MdbSourceFileInfo(List<MethodMdbInfo> methods)
66+
{
67+
Methods = methods;
68+
}
6469
}
6570

6671
class MethodMdbInfo
@@ -2606,20 +2611,30 @@ bool LoadMdbFile(string mdbFileName)
26062611

26072612
using(MonoSymbolFile mdb = MonoSymbolFile.ReadSymbolFile(mdbFileName))
26082613
{
2614+
// Create a mapping by CompileUnitIndex.
2615+
var methodMapping = new Dictionary<int, List<MethodMdbInfo>> (mdb.CompileUnitCount);
2616+
foreach (var method in mdb.Methods) {
2617+
List<MethodMdbInfo> list;
2618+
if (!methodMapping.TryGetValue(method.CompileUnitIndex, out list))
2619+
methodMapping[method.CompileUnitIndex] = list = new List<MethodMdbInfo> ();
2620+
2621+
list.Add (new MethodMdbInfo { SequencePoints = method.GetLineNumberTable ().LineNumbers });
2622+
}
2623+
26092624
foreach (var cu in mdb.CompileUnits)
26102625
{
2611-
MdbSourceFileInfo info = new MdbSourceFileInfo ();
2626+
// A CompileUnit may not have methods, so guard against this.
2627+
List<MethodMdbInfo> list;
2628+
if (!methodMapping.TryGetValue (cu.Index, out list))
2629+
list = new List<MethodMdbInfo> ();
2630+
2631+
MdbSourceFileInfo info = new MdbSourceFileInfo (list);
26122632

26132633
var src = cu.SourceFile;
26142634
info.Hash = src.Checksum;
26152635
info.FileID = src.Index;
26162636
info.FullFilePath = src.FileName;
26172637

2618-
foreach (var method in mdb.Methods) {
2619-
if (method.CompileUnitIndex == cu.Index)
2620-
info.Methods.Add (new MethodMdbInfo { SequencePoints = method.GetLineNumberTable ().LineNumbers });
2621-
}
2622-
26232638
fileToSourceFileInfos [src.FileName] = new List<MdbSourceFileInfo> ();
26242639

26252640
if (!fileToSourceFileInfos.ContainsKey (Path.GetFileName (src.FileName)))

0 commit comments

Comments
 (0)