-
Notifications
You must be signed in to change notification settings - Fork 1.4k
LogEventInfo - Minor optimization of HasImmutableProperties #6047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded@snakefoot has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 2 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (3)
WalkthroughThe changes refactor message template parameter handling by removing an internal MessageTemplateParameters constructor overload that accepted message and parameters, simplifying it to accept only template parameters. LogEventInfo is updated to align with this change by passing only properties when constructing MessageTemplateParameters, alongside variable renames and code clarity improvements. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/NLog/LogEventInfo.cs (1)
819-826: ResetFormattedMessage / ResetMessageTemplateParameters behavior and minor nit
- Gating the
HasMessageTemplateParameterscall behind theparseMessageTemplateParametersflag inResetFormattedMessagekeeps the expensive “do we have template parameters?” check conditional and ensures_formattedMessageis cleared first when using anILogMessageFormatter.ResetMessageTemplateParameters’s final return (_properties.MessageProperties.Count == 0) nicely distinguishes between events that already carry message-template properties (where you don’t want to re-parse from the message) and those that only have non-template properties but should still be eligible for template parsing later.If you expect
LogEventInfoinstances to haveMessageorParametersmutated after both formatted message and message-properties have been generated, it might be worth re-validating that this flagging still gives the desired re-parse behavior in those edge cases; otherwise this looks fine for the common, one-shot logging flow. Also, the comment at Line 843 has a minor typo (“contructor-input” → “constructor-input”).Also applies to: 832-845
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/NLog/LogEventInfo.cs(6 hunks)src/NLog/MessageTemplates/MessageTemplateParameters.cs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/NLog/LogEventInfo.cs (1)
src/NLog/MessageTemplates/MessageTemplateParameters.cs (3)
MessageTemplateParameters(45-198)MessageTemplateParameters(81-94)MessageTemplateParameters(99-103)
src/NLog/MessageTemplates/MessageTemplateParameters.cs (2)
src/NLog/MessageTemplates/MessageTemplateParameter.cs (2)
MessageTemplateParameter(105-111)MessageTemplateParameter(120-126)src/NLog/Internal/ArrayHelper.cs (1)
ArrayHelper(36-53)
🔇 Additional comments (4)
src/NLog/MessageTemplates/MessageTemplateParameters.cs (1)
99-103: Pre-parsed-parameters constructor behavior looks consistentUsing the provided
IList<MessageTemplateParameter>directly and unconditionally markingIsValidTemplate = truematches the “already parsed” contract and avoids redundant validation; no issues from this change.src/NLog/LogEventInfo.cs (3)
318-320: Message/Parameters setters: reset & parse flag usage is coherentBoth setters now compute a
parseMessageTemplateParametersflag, then update the backing field and callResetFormattedMessage(parseMessageTemplateParameters). This keeps message-template parsing and property reset in sync for bothMessageandParameterswithout changing behavior.Also applies to: 332-335
470-475: Using pre-existing MessageProperties to build MessageTemplateParameters is appropriateConstructing
MessageTemplateParametersdirectly from_properties.MessagePropertiesavoids re-parsing based on_message/_parameterswhen you already have pre-parsed parameters, which is both cheaper and semantically correct. The corresponding constructor settingIsValidTemplate = truefor pre-parsed data aligns with this usage.
720-747: HasImmutableProperties micro-optimization preserves semanticsCaching
properties.MessagePropertiesin a local and iterating it by index whenproperties.Count == messageProperties.Counteliminates an extra property lookup and the dictionary enumerator allocation while still checking every value withIsSafeToDeferFormatting. The fallback branch for mixed properties remains unchanged, so behavior is preserved with a minor perf win.
8fd8029 to
b079a12
Compare
|



No description provided.