Suggested by @LeaFrock.
Proposal
Now that the call-site guards the log call explicitly, set SkipEnabledCheck = true on the source-generated log method to remove the redundant generated check:
[LoggerMessage(EventId = 1002, Level = LogLevel.Debug, SkipEnabledCheck = true,
Message = "Using connection {ConnectionHash} with {Outstanding} outstanding commands")]
public static partial void ConnectionSelected(ILogger logger, int connectionHash, long outstanding);
Rationale
In #659 the call-site was wrapped in an explicit guard, because the argument connection.TotalOutstanding() is expensive — it goes through IConnectionMultiplexer.GetCounters(), which allocates a ServerCounters snapshot on every call, and log arguments are evaluated at the call-site regardless of whether the level is enabled:
if (logger.IsEnabled(LogLevel.Debug))
LogMessages.ConnectionSelected(logger, connection.Connection.GetHashCode(), connection.TotalOutstanding());
By default the [LoggerMessage] source generator emits its own IsEnabled check inside the generated method, so we now pay that check twice. This sits in RedisConnectionPoolManager.GetConnection(), which runs on every single Redis operation, so it is the hottest path in the library. SkipEnabledCheck = true is the documented way to opt out when the caller already guards, and it also makes the intent explicit to the next reader.
Verified: ConnectionSelected has exactly one call-site (RedisConnectionPoolManager.cs:147), and it is already guarded.
Note for the implementer
SkipEnabledCheck = true turns "the caller must guard" into a contract for this method. Any future call-site added without a guard would pay the full formatting cost unconditionally. Worth a short comment on the declaration so that constraint is not lost.
Acceptance criteria
Suggested by @LeaFrock.
Proposal
Now that the call-site guards the log call explicitly, set
SkipEnabledCheck = trueon the source-generated log method to remove the redundant generated check:Rationale
In #659 the call-site was wrapped in an explicit guard, because the argument
connection.TotalOutstanding()is expensive — it goes throughIConnectionMultiplexer.GetCounters(), which allocates aServerCounterssnapshot on every call, and log arguments are evaluated at the call-site regardless of whether the level is enabled:By default the
[LoggerMessage]source generator emits its ownIsEnabledcheck inside the generated method, so we now pay that check twice. This sits inRedisConnectionPoolManager.GetConnection(), which runs on every single Redis operation, so it is the hottest path in the library.SkipEnabledCheck = trueis the documented way to opt out when the caller already guards, and it also makes the intent explicit to the next reader.Verified:
ConnectionSelectedhas exactly one call-site (RedisConnectionPoolManager.cs:147), and it is already guarded.Note for the implementer
SkipEnabledCheck = trueturns "the caller must guard" into a contract for this method. Any future call-site added without a guard would pay the full formatting cost unconditionally. Worth a short comment on the declaration so that constraint is not lost.Acceptance criteria
SkipEnabledCheck = trueadded to theConnectionSelecteddeclaration inLogMessages.cs