-
Notifications
You must be signed in to change notification settings - Fork 4
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
Modifying the slowdown caused by logging #188
Conversation
WalkthroughThe recent changes to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Logger
User->>Logger: Call log(level, message)
Logger->>Logger: Check current log level
alt Log level is sufficient
Logger->>Logger: Evaluate message
Logger->>Logger: Output log
else Log level is insufficient
Logger->>Logger: Skip message evaluation
end
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #188 +/- ##
==========================================
- Coverage 45.11% 45.09% -0.03%
==========================================
Files 105 105
Lines 19320 19321 +1
==========================================
- Hits 8716 8712 -4
- Misses 10604 10609 +5 ☔ View full report in Codecov by Sentry. |
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: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- Sources/Core/Logger.swift (1 hunks)
Additional comments not posted (6)
Sources/Core/Logger.swift (6)
33-34
: LGTM! The use of@autoclosure
improves performance.The
trace
function now defers the evaluation of the message until it is needed, which is beneficial for performance.
37-38
: LGTM! The use of@autoclosure
improves performance.The
debug
function now defers the evaluation of the message until it is needed, which is beneficial for performance.
41-42
: LGTM! The use of@autoclosure
improves performance.The
info
function now defers the evaluation of the message until it is needed, which is beneficial for performance.
45-46
: LGTM! The use of@autoclosure
improves performance.The
warning
function now defers the evaluation of the message until it is needed, which is beneficial for performance.
49-50
: LGTM! The use of@autoclosure
improves performance.The
error
function now defers the evaluation of the message until it is needed, which is beneficial for performance.
53-54
: LGTM! The use of@autoclosure
improves performance.The
critical
function now defers the evaluation of the message until it is needed, which is beneficial for performance.
static func log(level: Logging.Logger.Level, _ message: @autoclosure () -> String, error: Error? = nil, filename: String = #file, function: String = #function, line: UInt = #line) { | ||
guard Logger.logLevel <= level else { return } | ||
|
||
var log = message() |
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.
LGTM! The use of @autoclosure
improves performance.
The log
function now defers the evaluation of the message until it is needed, which is beneficial for performance.
However, the guard
statement should be updated to use >=
instead of <=
to ensure that the log level is properly checked.
- guard Logger.logLevel <= level else { return }
+ guard Logger.logLevel >= level else { return }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
static func log(level: Logging.Logger.Level, _ message: @autoclosure () -> String, error: Error? = nil, filename: String = #file, function: String = #function, line: UInt = #line) { | |
guard Logger.logLevel <= level else { return } | |
var log = message() | |
static func log(level: Logging.Logger.Level, _ message: @autoclosure () -> String, error: Error? = nil, filename: String = #file, function: String = #function, line: UInt = #line) { | |
guard Logger.logLevel >= level else { return } | |
var log = message() |
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation:
Checklist:
Summary by CodeRabbit
New Features
Bug Fixes