Skip to content

Commit 2dbdc03

Browse files
committed
Set a threshold on when filtering moves to parallel
1 parent f23bf69 commit 2dbdc03

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/EventLogExpert.UI/Services/FilterService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ public IReadOnlyList<DisplayEventModel> GetFilteredEvents(
4040
return events as IReadOnlyList<DisplayEventModel> ?? [.. events];
4141
}
4242

43+
// For small collections, PLINQ's thread scheduling overhead exceeds the
44+
// parallelism benefit. Use sequential filtering below the threshold.
45+
if (events is IReadOnlyCollection<DisplayEventModel> { Count: < 10_000 } collection)
46+
{
47+
return collection
48+
.Where(e => e.FilterByDate(eventFilter.DateFilter)
49+
.Filter(eventFilter.Filters, IsXmlEnabled))
50+
.ToList();
51+
}
52+
4353
return events.AsParallel()
4454
.Where(e => e.FilterByDate(eventFilter.DateFilter)
4555
.Filter(eventFilter.Filters, IsXmlEnabled))

0 commit comments

Comments
 (0)