perf: batch flush signaling and fetch path optimizations (Round 6)
Implement Go's pcd (per-client deferred flush) pattern to reduce write-loop wakeups during fan-out delivery, optimize ack reply string construction with stack-based formatting, cache CompiledFilter on ConsumerHandle, and pool fetch message lists. Durable consumer fetch improves from 0.60x to 0.74x Go.
This commit is contained in:
@@ -375,6 +375,32 @@ public sealed class ConsumerManager : IDisposable
|
||||
|
||||
public sealed record ConsumerHandle(string Stream, ConsumerConfig Config)
|
||||
{
|
||||
/// <summary>
|
||||
/// Compiled filter derived from Config. Cached per-instance; invalidated when Config
|
||||
/// changes (either via <c>with { Config = newConfig }</c> or in-place mutation of
|
||||
/// FilterSubject/FilterSubjects).
|
||||
/// Go reference: consumer.go — filter subjects resolved once at consumer creation.
|
||||
/// </summary>
|
||||
private Consumers.CompiledFilter? _compiledFilter;
|
||||
private string? _compiledFilterSubject;
|
||||
private int _compiledFilterSubjectsCount;
|
||||
public Consumers.CompiledFilter CompiledFilter
|
||||
{
|
||||
get
|
||||
{
|
||||
// Detect both reference change (with expression) and in-place mutation
|
||||
if (_compiledFilter == null
|
||||
|| _compiledFilterSubject != Config.FilterSubject
|
||||
|| _compiledFilterSubjectsCount != Config.FilterSubjects.Count)
|
||||
{
|
||||
_compiledFilter = Consumers.CompiledFilter.FromConfig(Config);
|
||||
_compiledFilterSubject = Config.FilterSubject;
|
||||
_compiledFilterSubjectsCount = Config.FilterSubjects.Count;
|
||||
}
|
||||
return _compiledFilter;
|
||||
}
|
||||
}
|
||||
|
||||
public ulong NextSequence { get; set; } = 1;
|
||||
public bool Paused { get; set; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user