Skip to content

Commit eed6789

Browse files
committed
Switch parse results collection to local locks
They are faster than the ConcurrentBag.
1 parent ba6ddac commit eed6789

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Rubberduck.Parsing/VBA/Parsing/ParseRunner.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Concurrent;
32
using System.Collections.Generic;
43
using System.Linq;
54
using System.Threading;
@@ -30,7 +29,8 @@ public ParseRunner(
3029

3130
token.ThrowIfCancellationRequested();
3231

33-
var results = new ConcurrentBag<(QualifiedModuleName module, ModuleParseResults results)>();
32+
var results = new List<(QualifiedModuleName module, ModuleParseResults results)>();
33+
var lockObject = new object();
3434

3535
var options = new ParallelOptions
3636
{
@@ -42,7 +42,19 @@ public ParseRunner(
4242
{
4343
Parallel.ForEach(modules,
4444
options,
45-
module => results.Add((module, ModuleParseResults(module, token)))
45+
() => new List<(QualifiedModuleName module, ModuleParseResults results)>(),
46+
(module, state, localList) =>
47+
{
48+
localList.Add((module, ModuleParseResults(module, token)));
49+
return localList;
50+
},
51+
(finalResult) =>
52+
{
53+
lock (lockObject)
54+
{
55+
results.AddRange(finalResult);
56+
}
57+
}
4658
);
4759
}
4860
catch (AggregateException exception)

0 commit comments

Comments
 (0)