Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="FSharp.Core" Version="9.0.100" />
<PackageVersion Include="FSharp.SystemTextJson" Version="1.3.13" />
<PackageVersion Include="JasperFx" Version="1.26.0" />
<PackageVersion Include="JasperFx" Version="1.27.0" />
<PackageVersion Include="JasperFx.Events" Version="1.29.1" />
<PackageVersion Include="JasperFx.Events.SourceGenerator" Version="1.5.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
9 changes: 6 additions & 3 deletions src/Marten/Events/QuickEventAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ private static void registerOperationsForStreams(EventGraph eventGraph, Document
}
}

// The quick-append path never reads from this queue (PrepareEvents calls
// applyQuickMetadata, not applyRichMetadata, and only the rich variant
// dequeues from it). Hoist a single throwaway instance out of the
// per-stream loop so we don't allocate one per stream on every save.
var sequences = new Queue<long>();

foreach (var stream in session.WorkTracker.Streams.Where(x => x.Events.Any()))
{
stream.TenantId ??= session.TenantId;

// Not really using it, just need a stand in
var sequences = new Queue<long>();
if (stream.ActionType == StreamActionType.Start)
{
stream.PrepareEvents(0, eventGraph, sequences, session);
Expand Down
15 changes: 14 additions & 1 deletion src/Marten/Internal/Sessions/DocumentSessionBase.SaveChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,20 @@ async ValueTask<IMessageSink> IStorageOperations.GetOrStartMessageSink()

private IEnumerable<Type> operationDocumentTypes()
{
return _workTracker.Operations().Select(x => x.DocumentType).Where(x => x != null).Distinct();
// Single-pass HashSet so we don't enumerate Operations() twice (once for
// Select, once for the Distinct hash) and don't allocate intermediate
// LINQ enumerator chains on every SaveChanges.
var types = new HashSet<Type>();
foreach (var op in _workTracker.Operations())
{
var documentType = op.DocumentType;
if (documentType != null)
{
types.Add(documentType);
}
}

return types;
}

internal record PagesExecution(IReadOnlyList<OperationPage> Pages, IConnectionLifetime Connection,
Expand Down
Loading