Repository navigation
perf: guard loggerExternal.entering/exiting with isLoggable(FINER) across the driver - #2955
Merged
Merged
Conversation
Wrap 396 unguarded loggerExternal.entering() and exiting() calls in SQLServerResultSet with isLoggable(Level.FINER) checks. When logging is disabled (the common production case), this eliminates: - Autoboxing of primitive parameters (int -> Integer) for varargs - Object[] array creation for multi-arg entering/exiting calls - getClassNameLogging() call overhead Benchmarked with 10M iterations on JDK 21: Unguarded: 47.4ms Guarded: 24.2ms (~2x faster per getter call) For a typical query reading 1M rows x 10 columns, this eliminates ~20M unnecessary autoboxing allocations and array creations.
Single-file, zero-dependency benchmark that demonstrates the impact of guarding entering/exiting calls with isLoggable(FINER) in ResultSet getters. Compile and run: javac LoggerGuardBenchmark.java && java LoggerGuardBenchmark
Resolved conflicts in SQLServerResultSet, SQLServerCallableStatement, and SQLServerPreparedStatement by taking origin/main's content and re-applying the loggerExternal.entering/exiting isLoggable(Level.FINER) guards. Line endings preserved per-file to match origin/main convention (LF for most files, CRLF for ScrollWindow/SimpleInputStream/SQLServerConnectionPoolProxy).
Ananya Garg (Ananya2)
force-pushed
the
pr2945-logging-guard-resultset
branch
from
May 14, 2026 14:48
1ddc8ba to
787a02e
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR applies the logging optimization from #2945 across additional Microsoft JDBC Driver classes by guarding loggerExternal.entering(...) / loggerExternal.exiting(...) call sites with loggerExternal.isLoggable(Level.FINER) to avoid unnecessary varargs allocations and boxing when FINER logging is disabled.
Changes:
- Wrapped many previously-unguarded
loggerExternal.entering/exitingcalls withisLoggable(Level.FINER)checks. - Standardized some logging-level references from fully-qualified
java.util.logging.Level.FINERtoLevel.FINER(with corresponding imports where needed).
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java | Guards loggerExternal.entering/exiting calls in statement execution and property accessors. |
| src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java | Guards loggerExternal.entering/exiting across parameter-binding and execution paths. |
| src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java | Guards loggerExternal.entering/exiting for driver entry points and version/compliance methods. |
| src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java | Guards loggerExternal.entering/exiting across DataSource getters/setters and property helpers. |
| src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java | Guards loggerExternal.entering/exiting across connection lifecycle and statement factory methods. |
| src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkRecord.java | Adds FINER guards around bulk-record entering/exiting and imports Level. |
| src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCSVFileRecord.java | Adds FINER guards around entering/exiting in constructors/close/metadata and imports Level. |
| src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java | Adds FINER guards around bulk-copy lifecycle and configuration methods. |
| src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkBatchInsertRecord.java | Adds FINER guards around entering/exiting and imports Level. |
Comments suppressed due to low confidence (4)
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java:8138
prepareCall(String, int, int, int, SQLServerStatementColumnEncryptionSetting)logsloggerExternal.entering(..., "prepareStatement", ...), which misidentifies the method in FINER traces. Update the logged method name to "prepareCall".
public CallableStatement prepareCall(String sql, int nType, int nConcur, int resultSetHoldability,
SQLServerStatementColumnEncryptionSetting stmtColEncSetiing) throws SQLServerException {
if (loggerExternal.isLoggable(Level.FINER)) {
loggerExternal.entering(loggingClassName, "prepareStatement",
new Object[] {nType, nConcur, resultSetHoldability, stmtColEncSetiing});
}
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java:1629
getStringPropertyperformsif (loggerExternal.isLoggable(Level.FINER) && ...)and then immediately re-checksloggerExternal.isLoggable(Level.FINER)before callingexiting(...). The inner check is redundant; remove it to reduce clutter and minor overhead.
if (loggerExternal.isLoggable(Level.FINER) && !propKey.contains("password")
&& !propKey.contains("Password"))
if (loggerExternal.isLoggable(Level.FINER)) {
loggerExternal.exiting(getClassNameLogging(), "get" + propKey, propValue);
}
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java:1568
getMinorVersion()has two consecutiveloggerExternal.isLoggable(Level.FINER)checks surroundingentering/exitingwith no intervening work. Consolidate to a single guard/cached boolean to reduce redundancy and improve readability.
public int getMinorVersion() {
if (loggerExternal.isLoggable(Level.FINER)) {
loggerExternal.entering(getClassNameLogging(), "getMinorVersion");
}
if (loggerExternal.isLoggable(Level.FINER)) {
loggerExternal.exiting(getClassNameLogging(), "getMinorVersion", SQLJdbcVersion.MINOR);
}
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java:1584
jdbcCompliant()has two consecutiveloggerExternal.isLoggable(Level.FINER)checks aroundentering/exitingwith no intervening work. Use a single guard (or cached boolean) for both calls to avoid redundantisLoggablechecks.
@Override
public boolean jdbcCompliant() {
if (loggerExternal.isLoggable(Level.FINER)) {
loggerExternal.entering(getClassNameLogging(), "jdbcCompliant");
}
if (loggerExternal.isLoggable(Level.FINER)) {
loggerExternal.exiting(getClassNameLogging(), "jdbcCompliant", Boolean.TRUE);
}
Divang Sharma (divang)
previously approved these changes
May 18, 2026
Muskan Gupta (muskan124947)
previously approved these changes
May 18, 2026
Ananya Garg (Ananya2)
dismissed stale reviews from Muskan Gupta (muskan124947) and Divang Sharma (divang)
via
May 18, 2026 14:12
cec5e6d
Muskan Gupta (muskan124947)
approved these changes
May 19, 2026
Mahendra Chavan (machavan)
approved these changes
May 20, 2026
Divang Sharma (divang)
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends PR #2945 (which guarded
SQLServerResultSet) to the rest of the driver by addingisLoggable(Level.FINER)guards around 640 previously-unguardedloggerExternal.entering(...)/loggerExternal.exiting(...)call sites across 13 driver classes.When logging is disabled (the common production configuration), the unguarded variants still incur:
int → Integer,boolean → Boolean, etc.) for the varargsObject...parameterObject[]allocations on multi-argument call sitesLogger.entering(...)/Logger.exiting(...)isLoggable(FINER)check before immediately returningAfter this change, the explicit guard short-circuits all of that work whenever the logger level is above
FINER(the default).Change
Applied mechanically across the remaining driver classes:
SQLServerCallableStatement.javaSQLServerPreparedStatement.javaSQLServerConnection.javaSQLServerStatement.javaSQLServerDataSource.javaSQLServerBulkCopy.javaSQLServerDriver.javaSQLServerBulkRecord.javaSQLServerBulkCSVFileRecord.javaSQLServerBulkBatchInsertRecord.javaEvery existing:
is now wrapped in:
There is no behavioral change — logging output remains identical whenever
FINERlogging is enabled.Already-guarded sites (833 total across these files) were intentionally left untouched; existing
isLoggable(...)checks are detected and skipped automatically.Additionally, fully-qualified
java.util.logging.Level.FINERreferences were replaced with the importedLevel.FINERform for consistency with surrounding code, with no behavioral or bytecode impact.Performance Impact
The performance benefit is concentrated in per-row / per-column / per-parameter hot paths where the JIT cannot eliminate boxing and varargs allocations across the
java.util.logging.Loggerboundary.1. Pattern microbenchmark —
benchmark/LoggerGuardBenchmark.javaStandalone benchmark exercising
java.util.logging.Logger.entering(...)/exiting(...)with and without theisLoggable(FINER)guard. JDK 25, logger levelOFF(typical production setting), 8 warmup + 15 measurement iterations × 10,000,000 ops/iter.entering(class, method, int)entering+exiting)entering+exiting)Interpretation
SQLServerPreparedStatement/SQLServerCallableStatementshow the most realistic gains due to heavy parameter-binding paths.SQLServerBulkCopy/SQLServerBulk*Recordsee smaller wins because TDS encoding still dominates total runtime.SQLServerConnection,SQLServerStatement,SQLServerDriver, andSQLServerDataSourceare included primarily for consistency; these are connection/query-frequency paths rather than row-frequency paths.For reference, PR #2945 previously measured ~1.82× improvement on a narrow mixed-type
SQLServerResultSetbenchmark after applying the same optimization pattern — the microbenchmark above reproduces that on the same call shape.Risk
FINERis enabled — the guard predicate is exactly the same thresholdLogger.entering()internally checks.loggerExternal.fine(...),finer(...),log(...), etc. calls were modified — onlyentering(...)/exiting(...).