perf: guard logging statements #1112
Merged
Conversation
Seems like there is something wrong with the Zulu build |
-1 The guards are required for multi-argument calls. I think adding explicit |
@@ -148,7 +148,9 @@ public static Encoding getDatabaseEncoding(String databaseEncoding) { | |||
String[] candidates = encodings.get(databaseEncoding); | |||
if (candidates != null) { | |||
for (String candidate : candidates) { | |||
LOGGER.log(Level.FINEST, "Search encoding candidate {0}", candidate); | |||
if (LOGGER.isLoggable(Level.FINEST)) { | |||
LOGGER.log(Level.FINEST, "Search encoding candidate {0}", candidate); |
vlsi
Feb 13, 2018
Member
This is log(Level level, String msg, Object param1)
, and it does not require guards
This is log(Level level, String msg, Object param1)
, and it does not require guards
Ya, that is what I thought as well
…-1 from me as well
Dave Cramer
On 13 February 2018 at 10:28, Vladimir Sitnikov ***@***.***> wrote:
***@***.**** requested changes on this pull request.
-1
The guards are required for multi-argument calls.
The only purpose of the guards is to avoid creating Object[] for varargs
(==performance reasons).
I think adding explicit if (loggable) makes code harder to read, and I do
think it is good when we can avoid extra if checks
------------------------------
In pgjdbc/src/main/java/org/postgresql/core/Encoding.java
<#1112 (comment)>:
> @@ -148,7 +148,9 @@ public static Encoding getDatabaseEncoding(String databaseEncoding) {
String[] candidates = encodings.get(databaseEncoding);
if (candidates != null) {
for (String candidate : candidates) {
- LOGGER.log(Level.FINEST, "Search encoding candidate {0}", candidate);
+ if (LOGGER.isLoggable(Level.FINEST)) {
+ LOGGER.log(Level.FINEST, "Search encoding candidate {0}", candidate);
This is log(Level level, String msg, Object param1), and it does not
require guards
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1112 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAYz9lzYykafmYxfJx5XCZP4dF5X5OvJks5tUao6gaJpZM4SD2T2>
.
|
I agree that the big win is for log statements with arguments, however Feel free to close. |
sounds to me like it costs 1 function call to save 1 function call ?
Dave Cramer
…On 13 February 2018 at 10:39, Jesper Pedersen ***@***.***> wrote:
I agree that the big win is for log statements with arguments, however
Logger.log() does an internal if (enabled), so this saves 1 function call
per log statement.
Feel free to close.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1112 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAYz9hjFI49pZ8R7BVo3NKbR4DvAJykuks5tUayzgaJpZM4SD2T2>
.
|
|
rhavermans
added a commit
to bolcom/pgjdbc
that referenced
this pull request
Jul 13, 2018
Guard certain logging statements with `isLoggable` to prevent `Object[]` allocation for the argument vararg.
rhavermans
added a commit
to bolcom/pgjdbc
that referenced
this pull request
Jul 13, 2018
Guard certain logging statements with `isLoggable` to prevent `Object[]` allocation for the argument vararg.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Add some more guards to logging statements to make it consistent with other parts of the code